2012-05-23 21:05:23 +02:00
|
|
|
/**
|
|
|
|
* Module Name: Drama
|
|
|
|
* Description: Experimental, you probably don't want it.
|
|
|
|
*/
|
2012-02-14 19:00:03 +01:00
|
|
|
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
|
2012-02-14 19:00:03 +01:00
|
|
|
'normal': 1
|
|
|
|
},
|
|
|
|
|
|
|
|
'def': 'normal'
|
|
|
|
};
|
|
|
|
var bayes = new brain.BayesianClassifier(options);
|
|
|
|
|
|
|
|
var commands = {
|
2012-05-23 21:05:23 +02:00
|
|
|
'~train': function(event) {
|
|
|
|
if(dbot.admin.include(event.user)) {
|
|
|
|
bayes.train(last[event.params[1]][event.params[2]], event.params[3]);
|
|
|
|
event.reply('Last thing ' + event.params[2] + ' said in ' +
|
|
|
|
event.params[1] + ' (' + last[event.params[1]][event.params[2]] + ') classified as \'' + event.params[3] + '\'');
|
2012-02-14 19:00:03 +01:00
|
|
|
}
|
2012-02-14 19:15:59 +01:00
|
|
|
},
|
|
|
|
|
2012-05-23 21:05:23 +02:00
|
|
|
'~rtrain': function(event) {
|
|
|
|
if(dbot.admin.include(event.user)) {
|
|
|
|
var category = event.params[1];
|
|
|
|
event.params.splice(0, 2);
|
|
|
|
var msg = event.params.join(' ');
|
2012-02-14 19:17:31 +01:00
|
|
|
bayes.train(msg, category);
|
2012-05-23 21:05:23 +02:00
|
|
|
event.reply('\'' + msg + '\' classified as \'' + category + '\'');
|
2012-02-15 22:05:26 +01:00
|
|
|
}
|
2012-02-15 22:04:01 +01:00
|
|
|
},
|
|
|
|
|
2012-05-23 21:05:23 +02:00
|
|
|
'~classify': function(event) {
|
|
|
|
event.params.splice(0, 1);
|
|
|
|
var msg = event.params.join(' ');
|
2012-02-15 22:04:01 +01:00
|
|
|
bayes.classify(msg, function(category) {
|
2012-05-23 21:05:23 +02:00
|
|
|
event.reply('Classified as: ' + category + '!');
|
2012-02-15 22:04:01 +01:00
|
|
|
}.bind(this));
|
2012-02-14 19:00:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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') {
|
2012-05-23 21:05:23 +02:00
|
|
|
if(dbot.db.drama.beinganasshole.hasOwnProperty(event.user)) {
|
|
|
|
dbot.db.drama.beinganasshole[event.user]++;
|
2012-03-06 20:55:35 +01:00
|
|
|
} else {
|
2012-05-23 21:05:23 +02:00
|
|
|
dbot.db.drama.beinganasshole[event.user] = 1;
|
2012-03-06 20:55:35 +01:00
|
|
|
}
|
|
|
|
} else if(category === 'sd') {
|
2012-05-23 21:05:23 +02:00
|
|
|
if(dbot.db.drama.sd.hasOwnProperty(event.user)) {
|
|
|
|
dbot.db.drama.sd[event.user]++;
|
2012-03-06 20:55:35 +01:00
|
|
|
} else {
|
2012-05-23 21:05:23 +02:00
|
|
|
dbot.db.drama.sd[event.user] = 1;
|
2012-03-06 20:55:35 +01:00
|
|
|
}
|
|
|
|
}
|
2012-03-05 19:17:15 +01:00
|
|
|
}
|
2012-02-14 19:02:48 +01:00
|
|
|
}.bind(this));
|
2012-02-14 19:00:03 +01:00
|
|
|
|
2012-05-23 21:05:23 +02:00
|
|
|
if(last.hasOwnProperty(event.channel)) {
|
|
|
|
last[event.channel][event.user] = data.message;
|
2012-02-14 19:00:03 +01:00
|
|
|
} else {
|
2012-05-23 21:05:23 +02:00
|
|
|
last[event.channel] = { };
|
|
|
|
last[event.channel][event.user] = data.message;
|
2012-02-14 19:00:03 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-04-15 22:43:02 +02:00
|
|
|
'on': 'PRIVMSG',
|
|
|
|
|
|
|
|
'name': 'drama',
|
|
|
|
|
|
|
|
'ignorable': false
|
2012-02-14 19:00:03 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.fetch = function(dbot) {
|
|
|
|
return drama(dbot);
|
|
|
|
};
|