3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-18 08:32:42 +01:00
dbot/modules/user.js

77 lines
2.4 KiB
JavaScript
Raw Normal View History

var userCommands = function(dbot) {
var dbot = dbot;
var commands = {
'~kc': function(data, params) {
dbot.say('aisbot', '.karma ' + data.message.split(' ')[1]);
dbot.waitingForKarma = data.channel;
},
'~kickcount': function(data, params) {
if(!dbot.db.kicks.hasOwnProperty(params[1])) {
2011-10-12 18:43:53 +02:00
var kicks = '0';
2011-10-12 18:45:00 +02:00
} else {
var kicks = dbot.db.kicks[params[1]];
}
2011-10-12 18:43:53 +02:00
if(!dbot.db.kickers.hasOwnProperty(params[1])) {
var kicked = '0';
2011-10-12 18:45:00 +02:00
} else {
var kicked = dbot.db.kickers[params[1]];
2011-10-12 18:43:53 +02:00
}
2011-10-12 18:45:00 +02:00
2011-10-12 18:43:53 +02:00
dbot.say(data.channel, params[1] + ' has been kicked ' + kicks + ' times and has kicked people ' + kicked + ' times.');
2011-09-12 17:38:10 +02:00
},
'~kickstats': function(data, params) {
var kickArr = [];
for(var kickUser in dbot.db.kicks) {
if(dbot.db.kicks.hasOwnProperty(kickUser)) {
kickArr.push([kickUser, dbot.db.kicks[kickUser]]);
}
}
var orderedKicks = kickArr.sort(function(a, b) { return a[1] - b[1]; });
2011-11-03 02:48:47 +01:00
var topKicks = kickArr.slice(kickArr.length - 10).reverse();
2011-10-12 18:49:00 +02:00
var kickString = "Top Kicked: ";
for(var i=0;i<topKicks.length;i++) {
kickString += topKicks[i][0] + " (" + topKicks[i][1] + "), ";
}
kickString = kickString.slice(0, -2);
dbot.say(data.channel, kickString);
// code repetition bad
var kickArr = [];
for(var kickUser in dbot.db.kickers) {
if(dbot.db.kickers.hasOwnProperty(kickUser)) {
kickArr.push([kickUser, dbot.db.kickers[kickUser]]);
}
}
var orderedKicks = kickArr.sort(function(a, b) { return a[1] - b[1]; });
2011-11-03 02:48:47 +01:00
var topKicks = kickArr.slice(kickArr.length - 10).reverse();
2011-10-12 18:49:00 +02:00
var kickString = "Top Kickers: ";
2011-09-12 17:38:10 +02:00
for(var i=0;i<topKicks.length;i++) {
kickString += topKicks[i][0] + " (" + topKicks[i][1] + "), ";
}
kickString = kickString.slice(0, -2);
dbot.say(data.channel, kickString);
}
};
return {
'onLoad': function() {
return commands;
}
};
};
exports.fetch = function(dbot) {
return userCommands(dbot);
};