From 4a198e2f64cc0978b84dd11249065c11567ff418 Mon Sep 17 00:00:00 2001 From: reality Date: Wed, 4 Feb 2015 17:00:47 +0000 Subject: [PATCH] more karma --- modules/karma/karma.js | 55 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/modules/karma/karma.js b/modules/karma/karma.js index 9581250..b1df713 100644 --- a/modules/karma/karma.js +++ b/modules/karma/karma.js @@ -13,7 +13,10 @@ var karma = function(dbot) { }.bind(this), 'setKarma': function(item, value, callback) { - this.db.save('karma', item.toLowerCase(), value, callback); + this.db.save('karma', item.toLowerCase(), { + 'item': item, + 'karma': value + }, callback); }.bind(this) }; @@ -21,6 +24,7 @@ var karma = function(dbot) { 'karma': function(event) { var item = event.params[1] || event.user; this.internalAPI.getKarma(event.server, target, function(err, karma) { + karma = karma.karma; event.reply(dbot.t('karma', { 'item': item, 'karma': karma @@ -38,6 +42,51 @@ var karma = function(dbot) { 'value': value })); }); + }, + + 'unkarmaiest': function(event) { + var karmas = {}; + this.db.scan('karma', function(karma) { + if(karma && !_.isUndefined(karma.item)) { + karmas[karma.item] = karma.karma; + } + }.bind(this), function(err) { + var qSizes = _.chain(karmas) + .pairs() + .sortBy(function(category) { return category[1]; }) + .first(10) + .value(); + + var qString = 'Unkarmaiest: '; + for(var i=0;i