diff --git a/modules/report/commands.js b/modules/report/commands.js index 8841c24..7c3facc 100644 --- a/modules/report/commands.js +++ b/modules/report/commands.js @@ -9,74 +9,81 @@ var commands = function(dbot) { typeCounts = {}, total = 0, offString = event.params[1] || null; - offset = moment().subtract(offString, 1).valueOf() || null; + offset = moment().subtract(offString, 1).valueOf() || null, + nick = event.params[2] || event.user; /*if(!offset || !offset.isValid()) { event.reply('Invalid timescale. Try \'week\''); return; }*/ - this.db.scan('notifies', function(notify) { - if(notify.user == event.rUser.id) { - if(!offString) { - if(!_.has(chanCounts, notify.channel)) chanCounts[notify.channel] = 0; - if(!_.has(typeCounts, notify.type)) typeCounts[notify.type] = 0; - chanCounts[notify.channel]++; - typeCounts[notify.type]++; - total++; - } else { - if(notify.time > offset) { + dbot.api.users.resolveUser(event.server, nick, function(err, user) { + if(user) { + this.db.scan('notifies', function(notify) { + if(notify.user == user.id) { + if(!offString) { if(!_.has(chanCounts, notify.channel)) chanCounts[notify.channel] = 0; if(!_.has(typeCounts, notify.type)) typeCounts[notify.type] = 0; chanCounts[notify.channel]++; typeCounts[notify.type]++; total++; + } else { + if(notify.time > offset) { + if(!_.has(chanCounts, notify.channel)) chanCounts[notify.channel] = 0; + if(!_.has(typeCounts, notify.type)) typeCounts[notify.type] = 0; + chanCounts[notify.channel]++; + typeCounts[notify.type]++; + total++; + } } } - } - }, function() { - var cCounts = _.chain(chanCounts) - .pairs() - .sortBy(function(p) { return p[1]; }) - .reverse() - .first(10) - .value(); + }, function() { + var cCounts = _.chain(chanCounts) + .pairs() + .sortBy(function(p) { return p[1]; }) + .reverse() + .first(10) + .value(); - var cString = ''; - for(var i=0;i