Converted drama kicks and puns to new format. Quite tired now.

This commit is contained in:
Luke Slater 2012-05-23 20:05:23 +01:00
parent 74369c5de6
commit 979399de46
3 changed files with 56 additions and 63 deletions

View File

@ -1,3 +1,7 @@
/**
* Module Name: Drama
* Description: Experimental, you probably don't want it.
*/
var brain = require('brain');
var drama = function(dbot) {
@ -25,29 +29,29 @@ var drama = function(dbot) {
var bayes = new brain.BayesianClassifier(options);
var commands = {
'~train': function(data, params) {
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 ' +
params[1] + ' (' + last[params[1]][params[2]] + ') classified as \'' + params[3] + '\'');
'~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] + '\'');
}
},
'~rtrain': function(data, params) {
if(dbot.admin.include(data.user)) {
var category = params[1];
params.splice(0, 2);
var msg = params.join(' ');
'~rtrain': function(event) {
if(dbot.admin.include(event.user)) {
var category = event.params[1];
event.params.splice(0, 2);
var msg = event.params.join(' ');
bayes.train(msg, category);
dbot.say(data.channel, '\'' + msg + '\' classified as \'' + category + '\'');
event.reply('\'' + msg + '\' classified as \'' + category + '\'');
}
},
'~classify': function(data, params) {
params.splice(0, 1);
var msg = params.join(' ');
'~classify': function(event) {
event.params.splice(0, 1);
var msg = event.params.join(' ');
bayes.classify(msg, function(category) {
dbot.say(data.channel, 'Classified as: ' + category + '!');
event.reply('Classified as: ' + category + '!');
}.bind(this));
}
}
@ -61,26 +65,26 @@ var drama = function(dbot) {
var category = bayes.classify(data.message, function(category) {
if(category !== 'normal') {
if(category === 'beinganasshole') {
if(dbot.db.drama.beinganasshole.hasOwnProperty(data.user)) {
dbot.db.drama.beinganasshole[data.user]++;
if(dbot.db.drama.beinganasshole.hasOwnProperty(event.user)) {
dbot.db.drama.beinganasshole[event.user]++;
} else {
dbot.db.drama.beinganasshole[data.user] = 1;
dbot.db.drama.beinganasshole[event.user] = 1;
}
} else if(category === 'sd') {
if(dbot.db.drama.sd.hasOwnProperty(data.user)) {
dbot.db.drama.sd[data.user]++;
if(dbot.db.drama.sd.hasOwnProperty(event.user)) {
dbot.db.drama.sd[event.user]++;
} else {
dbot.db.drama.sd[data.user] = 1;
dbot.db.drama.sd[event.user] = 1;
}
}
}
}.bind(this));
if(last.hasOwnProperty(data.channel)) {
last[data.channel][data.user] = data.message;
if(last.hasOwnProperty(event.channel)) {
last[event.channel][event.user] = data.message;
} else {
last[data.channel] = { };
last[data.channel][data.user] = data.message;
last[event.channel] = { };
last[event.channel][event.user] = data.message;
}
},

View File

@ -4,25 +4,27 @@ var kick = function(dbot) {
var commands = {
// Give the number of times a given user has been kicked and has kicked
// other people.
'~kickcount': function(data, params) {
if(!dbot.db.kicks.hasOwnProperty(params[1])) {
'~kickcount': function(event) {
var username = event.params[1];
if(!dbot.db.kicks.hasOwnProperty(username)) {
var kicks = '0';
} else {
var kicks = dbot.db.kicks[params[1]];
var kicks = dbot.db.kicks[username];
}
if(!dbot.db.kickers.hasOwnProperty(params[1])) {
if(!dbot.db.kickers.hasOwnProperty(username)) {
var kicked = '0';
} else {
var kicked = dbot.db.kickers[params[1]];
var kicked = dbot.db.kickers[username];
}
dbot.say(data.channel, dbot.t('user_kicks', {'user': params[1], 'kicks': kicks, 'kicked': kicked}));
event.reply(dbot.t('user_kicks', {'user': username, 'kicks': kicks, 'kicked': kicked}));
},
// Output a list of the people who have been kicked the most and those
// who have kicked other people the most.
'~kickstats': function(data, params) {
'~kickstats': function(event) {
var orderedKickLeague = function(list, topWhat) {
var kickArr = [];
for(var kickUser in list) {
@ -42,45 +44,32 @@ var kick = function(dbot) {
return kickString.slice(0, -2);
};
dbot.say(data.channel, orderedKickLeague(dbot.db.kicks, 'Kicked'));
dbot.say(data.channel, orderedKickLeague(dbot.db.kickers, 'Kickers'));
event.reply(orderedKickLeague(dbot.db.kicks, 'Kicked'));
event.reply(orderedKickLeague(dbot.db.kickers, 'Kickers'));
}
};
return {
// Counts kicks
'listener': function(data) {
if(data.kickee == dbot.name) {
dbot.instance.join(data.channel);
dbot.say(data.channel, dbot.t('kicked_dbot', {'botname': dbot.name}));
'listener': function(event) {
if(event.kickee == dbot.name) {
dbot.instance.join(event, event.channel);
event.reply(dbot.t('kicked_dbot', {'botname': dbot.name}));
dbot.db.kicks[dbot.name] += 1;
} else {
if(dbot.db.modehate.include(data.user)) {
dbot.instance.send('KICK ' + data.channel + ' ' + data.user + ' :gtfo (MODEHATE)');
if(!dbot.db.kicks.hasOwnProperty(data.user)) {
dbot.db.kicks[data.user] = 1;
} else {
dbot.db.kicks[data.user] += 1;
}
}
if(!dbot.db.kicks.hasOwnProperty(data.kickee)) {
dbot.db.kicks[data.kickee] = 1;
if(!dbot.db.kicks.hasOwnProperty(event.kickee)) {
dbot.db.kicks[event.kickee] = 1;
} else {
dbot.db.kicks[data.kickee] += 1;
dbot.db.kicks[event.kickee] += 1;
}
if(!dbot.db.kickers.hasOwnProperty(data.user)) {
dbot.db.kickers[data.user] = 1;
if(!dbot.db.kickers.hasOwnProperty(event.user)) {
dbot.db.kickers[event.user] = 1;
} else {
dbot.db.kickers[data.user] += 1;
dbot.db.kickers[event.user] += 1;
}
dbot.say(data.channel, data.kickee + '-- (' +
dbot.t('user_kicks', {'user': data.kickee, 'kicks': dbot.db.kicks[data.kickee],
'kicked': dbot.db.kickers[data.kickee]}) + ')');
event.reply(event.kickee + '-- (' + dbot.t('user_kicks',
{'user': event.kickee, 'kicks': dbot.db.kicks[event.kickee], 'kicked': dbot.db.kickers[event.kickee]}) + ')');
}
},

View File

@ -3,11 +3,11 @@ var puns = function(dbot) {
var dbot = dbot;
return {
'listener': function(data) {
data.user = dbot.cleanNick(data.user);
'listener': function(event) {
event.user = dbot.cleanNick(data.user);
if((dbot.db.ignores.hasOwnProperty(data.user) &&
dbot.db.ignores[data.user].include(name)) == false) {
if((dbot.db.ignores.hasOwnProperty(event.user) &&
dbot.db.ignores[event.user].include(name)) == false) {
if(dbot.moduleNames.include('quotes') &&
dbot.db.quoteArrs.hasOwnProperty(data.user)) {
data.message = '~q ' + data.user.toLowerCase();