3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-24 11:42:36 +01:00

time thing

This commit is contained in:
reality 2014-05-25 21:16:28 +00:00
parent 131233e7d0
commit 6990a10d9c
2 changed files with 43 additions and 10 deletions

View File

@ -1,16 +1,37 @@
var _ = require('underscore')._;
var _ = require('underscore')._,
moment = require('moment');
var commands = function(dbot) {
var commands = {
'~ncount': function(event) {
var chanCounts = {},
total = 0;
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)
@ -26,11 +47,20 @@ var commands = function(dbot) {
}
cString = cString.slice(0, -2);
if(offString) {
event.reply(dbot.t('timed_notifies', {
'user': event.user,
'count': total,
'offString': offString,
'cString': cString
}));
} else {
event.reply(dbot.t('total_notifies', {
'user': event.user,
'count': total,
'cString': cString
}));
}
});
},

View File

@ -84,5 +84,8 @@
},
"total_notifies": {
"en": "{user} has a total of {count} notifies. Channels: {cString}"
},
"timed_notifies": {
"en": "{user} has made {count} notifies in the last {offString}. Channels: {cString}"
}
}