mirror of
https://github.com/reality/dbot.git
synced 2024-11-27 14:29:29 +01:00
run ncount on other users
This commit is contained in:
parent
25d26b5586
commit
c6d352038c
@ -9,74 +9,81 @@ var commands = function(dbot) {
|
|||||||
typeCounts = {},
|
typeCounts = {},
|
||||||
total = 0,
|
total = 0,
|
||||||
offString = event.params[1] || null;
|
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()) {
|
/*if(!offset || !offset.isValid()) {
|
||||||
event.reply('Invalid timescale. Try \'week\'');
|
event.reply('Invalid timescale. Try \'week\'');
|
||||||
return;
|
return;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
this.db.scan('notifies', function(notify) {
|
dbot.api.users.resolveUser(event.server, nick, function(err, user) {
|
||||||
if(notify.user == event.rUser.id) {
|
if(user) {
|
||||||
if(!offString) {
|
this.db.scan('notifies', function(notify) {
|
||||||
if(!_.has(chanCounts, notify.channel)) chanCounts[notify.channel] = 0;
|
if(notify.user == user.id) {
|
||||||
if(!_.has(typeCounts, notify.type)) typeCounts[notify.type] = 0;
|
if(!offString) {
|
||||||
chanCounts[notify.channel]++;
|
|
||||||
typeCounts[notify.type]++;
|
|
||||||
total++;
|
|
||||||
} else {
|
|
||||||
if(notify.time > offset) {
|
|
||||||
if(!_.has(chanCounts, notify.channel)) chanCounts[notify.channel] = 0;
|
if(!_.has(chanCounts, notify.channel)) chanCounts[notify.channel] = 0;
|
||||||
if(!_.has(typeCounts, notify.type)) typeCounts[notify.type] = 0;
|
if(!_.has(typeCounts, notify.type)) typeCounts[notify.type] = 0;
|
||||||
chanCounts[notify.channel]++;
|
chanCounts[notify.channel]++;
|
||||||
typeCounts[notify.type]++;
|
typeCounts[notify.type]++;
|
||||||
total++;
|
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() {
|
||||||
}, function() {
|
var cCounts = _.chain(chanCounts)
|
||||||
var cCounts = _.chain(chanCounts)
|
.pairs()
|
||||||
.pairs()
|
.sortBy(function(p) { return p[1]; })
|
||||||
.sortBy(function(p) { return p[1]; })
|
.reverse()
|
||||||
.reverse()
|
.first(10)
|
||||||
.first(10)
|
.value();
|
||||||
.value();
|
|
||||||
|
|
||||||
var cString = '';
|
var cString = '';
|
||||||
for(var i=0;i<cCounts.length;i++) {
|
for(var i=0;i<cCounts.length;i++) {
|
||||||
cString += cCounts[i][0] + " (" + cCounts[i][1] + "), ";
|
cString += cCounts[i][0] + " (" + cCounts[i][1] + "), ";
|
||||||
}
|
}
|
||||||
cString = cString.slice(0, -2);
|
cString = cString.slice(0, -2);
|
||||||
|
|
||||||
var tCounts = _.chain(typeCounts)
|
var tCounts = _.chain(typeCounts)
|
||||||
.pairs()
|
.pairs()
|
||||||
.sortBy(function(p) { return p[1]; })
|
.sortBy(function(p) { return p[1]; })
|
||||||
.reverse()
|
.reverse()
|
||||||
.first(10)
|
.first(10)
|
||||||
.value();
|
.value();
|
||||||
|
|
||||||
var tString = '';
|
var tString = '';
|
||||||
for(var i=0;i<tCounts.length;i++) {
|
for(var i=0;i<tCounts.length;i++) {
|
||||||
tString += tCounts[i][0] + " (" + tCounts[i][1] + "), ";
|
tString += tCounts[i][0] + " (" + tCounts[i][1] + "), ";
|
||||||
}
|
}
|
||||||
tString = tString.slice(0, -2);
|
tString = tString.slice(0, -2);
|
||||||
|
|
||||||
if(offString) {
|
if(offString) {
|
||||||
event.reply(dbot.t('timed_notifies', {
|
event.reply(dbot.t('timed_notifies', {
|
||||||
'user': event.user,
|
'user': user.priamryNick,
|
||||||
'count': total,
|
'count': total,
|
||||||
'offString': offString,
|
'offString': offString,
|
||||||
'cString': cString,
|
'cString': cString,
|
||||||
'tString': tString
|
'tString': tString
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
event.reply(dbot.t('total_notifies', {
|
event.reply(dbot.t('total_notifies', {
|
||||||
'user': event.user,
|
'user': user.primaryNick,
|
||||||
'count': total,
|
'count': total,
|
||||||
'cString': cString,
|
'cString': cString,
|
||||||
'tString': tString
|
'tString': tString
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
event.reply('No idea who that is mate.');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -363,7 +370,7 @@ var commands = function(dbot) {
|
|||||||
commands['~sustatus'].regex = [/^sustatus ([^ ]+)$/, 2];
|
commands['~sustatus'].regex = [/^sustatus ([^ ]+)$/, 2];
|
||||||
commands['~ustatus'].access = 'power_user';
|
commands['~ustatus'].access = 'power_user';
|
||||||
commands['~sustatus'].access = 'power_user';
|
commands['~sustatus'].access = 'power_user';
|
||||||
commands['~sustatus'].access = 'concerning';
|
commands['~ncount'].access = 'power_user';
|
||||||
|
|
||||||
return commands;
|
return commands;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user