3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-27 22:39:26 +01:00

underscorisation of kick [#81]

This commit is contained in:
reality 2013-01-12 22:53:13 +00:00
parent ca8a8ca9c2
commit f36e6c781b

View File

@ -1,3 +1,5 @@
var _ = require('underscore')._;
var kick = function(dbot) { var kick = function(dbot) {
var commands = { var commands = {
// Give the number of times a given user has been kicked and has kicked // Give the number of times a given user has been kicked and has kicked
@ -5,27 +7,35 @@ var kick = function(dbot) {
'~kickcount': function(event) { '~kickcount': function(event) {
var username = event.params[1]; var username = event.params[1];
if(!dbot.db.kicks.hasOwnProperty(username)) { if(!_.has(dbot.db.kicks, username)) {
var kicks = '0'; var kicks = '0';
} else { } else {
var kicks = dbot.db.kicks[username]; var kicks = dbot.db.kicks[username];
} }
if(!dbot.db.kickers.hasOwnProperty(username)) { if(!_.has(dbot.db.kickers, username)) {
var kicked = '0'; var kicked = '0';
} else { } else {
var kicked = dbot.db.kickers[username]; var kicked = dbot.db.kickers[username];
} }
event.reply(dbot.t('user_kicks', {'user': username, '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 // Output a list of the people who have been kicked the most and those
// who have kicked other people the most. // who have kicked other people the most.
'~kickstats': function(event) { '~kickstats': function(event) {
var orderedKickLeague = function(list, topWhat) { var orderedKickLeague = function(list, topWhat) {
var kickArr = Object.prototype.sort(list, function(key, obj) { return obj[key]; }); var kickArr = _.chain(list)
kickArr = kickArr.slice(kickArr.length - 10).reverse(); .pairs()
.sortBy(function(kick) { return kick[1] })
.reverse()
.first(10)
.value();
var kickString = "Top " + topWhat + ": "; var kickString = "Top " + topWhat + ": ";
for(var i=0;i<kickArr.length;i++) { for(var i=0;i<kickArr.length;i++) {
@ -48,23 +58,26 @@ var kick = function(dbot) {
'listener': function(event) { 'listener': function(event) {
if(event.kickee == dbot.config.name) { if(event.kickee == dbot.config.name) {
dbot.instance.join(event, event.channel); dbot.instance.join(event, event.channel);
event.reply(dbot.t('kicked_dbot', {'botname': dbot.config.name})); event.reply(dbot.t('kicked_dbot', { 'botname': dbot.config.name }));
dbot.db.kicks[dbot.config.name] += 1; dbot.db.kicks[dbot.config.name] += 1;
} else { } else {
if(!dbot.db.kicks.hasOwnProperty(event.kickee)) { if(!_.has(dbot.db.kicks, event.kickee)) {
dbot.db.kicks[event.kickee] = 1; dbot.db.kicks[event.kickee] = 1;
} else { } else {
dbot.db.kicks[event.kickee] += 1; dbot.db.kicks[event.kickee] += 1;
} }
if(!dbot.db.kickers.hasOwnProperty(event.user)) { if(!_.has(dbot.db.kickers, event.user)) {
dbot.db.kickers[event.user] = 1; dbot.db.kickers[event.user] = 1;
} else { } else {
dbot.db.kickers[event.user] += 1; dbot.db.kickers[event.user] += 1;
} }
event.reply(event.kickee + '-- (' + dbot.t('user_kicks', event.reply(event.kickee + '-- (' + dbot.t('user_kicks', {
{'user': event.kickee, 'kicks': dbot.db.kicks[event.kickee], 'kicked': dbot.db.kickers[event.kickee]}) + ')'); 'user': event.kickee,
'kicks': dbot.db.kicks[event.kickee],
'kicked': dbot.db.kickers[event.kickee]
}) + ')');
} }
}, },
on: 'KICK' on: 'KICK'