3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-25 20:22:39 +01:00
dbot/modules/drama.js

98 lines
3.0 KiB
JavaScript
Raw Normal View History

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,
2012-02-14 19:18:53 +01:00
'sd': 3, // self depracating
'normal': 1
},
'def': 'normal'
};
var bayes = new brain.BayesianClassifier(options);
var commands = {
'~train': function(data, params) {
2012-03-10 15:38:47 +01:00
if(dbot.admin.include(data.user)) {
bayes.train(last[params[1]][params[2]], params[3]);
dbot.say(data.channel, 'Last thing ' + params[2] + ' said in ' +
2012-02-14 19:57:52 +01:00
params[1] + ' (' + last[params[1]][params[2]] + ') classified as \'' + params[3] + '\'');
}
2012-02-14 19:15:59 +01:00
},
'~rtrain': function(data, params) {
2012-03-10 15:38:47 +01:00
if(dbot.admin.include(data.user)) {
2012-02-14 19:17:31 +01:00
var category = params[1];
2012-02-14 19:15:59 +01:00
params.splice(0, 2);
var msg = params.join(' ');
2012-02-14 19:17:31 +01:00
bayes.train(msg, category);
dbot.say(data.channel, '\'' + msg + '\' classified as \'' + category + '\'');
2012-02-15 22:05:26 +01:00
}
2012-02-15 22:04:01 +01:00
},
'~classify': function(data, params) {
params.splice(0, 1);
var msg = params.join(' ');
bayes.classify(msg, function(category) {
dbot.say(data.channel, 'Classified as: ' + category + '!');
}.bind(this));
}
}
return {
'onLoad': function() {
return commands;
},
'listener': function(data) {
2012-02-14 19:02:48 +01:00
var category = bayes.classify(data.message, function(category) {
2012-03-06 20:55:35 +01:00
if(category !== 'normal') {
if(category === 'beinganasshole') {
if(dbot.db.drama.beinganasshole.hasOwnProperty(data.user)) {
dbot.db.drama.beinganasshole[data.user]++;
} else {
dbot.db.drama.beinganasshole[data.user] = 1;
}
} else if(category === 'sd') {
if(dbot.db.drama.sd.hasOwnProperty(data.user)) {
dbot.db.drama.sd[data.user]++;
} else {
dbot.db.drama.sd[data.user] = 1;
}
}
2012-03-05 19:17:15 +01:00
}
2012-02-14 19:02:48 +01:00
}.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',
'name': 'drama',
'ignorable': false
};
}
exports.fetch = function(dbot) {
return drama(dbot);
};