From 5cc3b224c29f08bd52c4936d56a6a06ce2f4204c Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Tue, 14 Feb 2012 18:00:03 +0000 Subject: [PATCH] experimental bayesian classifier for detecting being an asshole and drama --- modules/drama.js | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 modules/drama.js diff --git a/modules/drama.js b/modules/drama.js new file mode 100644 index 0000000..8f9a4a4 --- /dev/null +++ b/modules/drama.js @@ -0,0 +1,62 @@ +var brain = require('brain'); + +var drama = function(dbot) { + var dbot = dbot; + var last = {}; + var options = { + 'backend': { + 'type': 'Redis', + 'options': { + 'hostname': 'localhost', + 'port': 6379, + 'name': 'dbotdrama' + } + }, + + 'thresholds': { + 'drama': 3, + 'beinganasshole': 3, + 'normal': 1 + }, + + 'def': 'normal' + }; + var bayes = new brain.BayesianClassifier(options); + + var commands = { + '~train': function(data, params) { + if(data.user == dbot.admin) { + bayes.train(last[params[1]][params[2]], params[3]); + dbot.say(data.channel, 'Last thing ' + params[2] + ' said in ' + + params[1] + ' classified as \'' + params[3] + '\''); + } + } + } + + return { + 'onLoad': function() { + return commands; + }, + + 'listener': function(data) { + if(reporting == true) { + var category = bayes.classify(data.message, function(category) { + console.log(category + '!'); + }.bind(this)); + } + + if(last.hasOwnProperty(data.channel)) { + last[data.channel][data.user] = data.message; + } else { + last[data.channel] = { }; + last[data.channel][data.user] = data.message; + } + }, + + 'on': 'PRIVMSG' + }; +} + +exports.fetch = function(dbot) { + return drama(dbot); +};