From 10a46a3bdef417012e87c83d67078a83b2fd6b62 Mon Sep 17 00:00:00 2001 From: reality Date: Thu, 17 Oct 2013 09:10:01 +0000 Subject: [PATCH] overall ~loudest --- modules/sstats/commands.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/modules/sstats/commands.js b/modules/sstats/commands.js index a4ced41..de24ec2 100644 --- a/modules/sstats/commands.js +++ b/modules/sstats/commands.js @@ -1,4 +1,5 @@ -var _ = require('underscore')._; +var _ = require('underscore')._, + async = require('async'); var commands = function(dbot) { var commands = { @@ -75,6 +76,33 @@ var commands = function(dbot) { } }, + '~loudest': function(event) { + var lines = {}; + this.db.scan('user_stats', function(uStats) { + lines[uStats.id] = uStats.lines; + }, function() { + var lCounts = _.chain(lines) + .pairs() + .sortBy(function(user) { return user[1]; }) + .reverse() + .first(10) + .value(); + + async.eachSeries(lCounts, function(lCount, next) { + dbot.api.users.getUser(lCount[0], function(user) { + lCount[0] = user.primaryNick; + next(); + }); + }, function() { + var output = "Loudest users: "; + for(var i=0;i