var _ = require('underscore')._, moment = require('moment'); var commands = function(dbot) { var commands = { '~ncount': function(event) { var chanCounts = {}, total = 0, offString = event.params[1] || null; offset = moment().subtract(offString, 1).valueOf() || null; console.log(offset); /*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; chanCounts[notify.channel]++; total++; } else { console.log(offset); console.log(notify.time); console.log(); if(notify.time > offset) { if(!_.has(chanCounts, notify.channel)) chanCounts[notify.channel] = 0; chanCounts[notify.channel]++; total++; } } } }, function() { var cCounts = _.chain(chanCounts) .pairs() .sortBy(function(p) { return p[1]; }) .reverse() .first(10) .value(); var cString = ''; for(var i=0;i