forked from GitHub/dbot
efficiency and command merging
This commit is contained in:
parent
0db0abeb6a
commit
44316a5de1
@ -77,64 +77,75 @@ var commands = function(dbot) {
|
||||
},
|
||||
|
||||
'~loudest': function(event) {
|
||||
var channel = event.params[1];
|
||||
|
||||
if(_.isUndefined(channel)) {
|
||||
this.internalAPI.highscore('user_stats', 'lines', function(lCounts) {
|
||||
async.eachSeries(lCounts, function(lCount, next) {
|
||||
dbot.api.users.getUser(lCount[0], function(user) {
|
||||
lCount[0] = user.primaryNick; next();
|
||||
});
|
||||
}, function() {
|
||||
event.reply(this.internalAPI.formatHighscore('Loudest users: ', lCounts));
|
||||
}.bind(this));
|
||||
} else {
|
||||
this.internalAPI.channelHighscore('user_stats', event.server, channel, 'lines', function(lCounts) {
|
||||
if(lCounts) {
|
||||
event.reply(this.internalAPI.formatHighscore('Loudest users in ' + channel + ': ', lCounts));
|
||||
} else {
|
||||
event.reply('Unknown channel.');
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
},
|
||||
|
||||
'~uncouth': function(event) {
|
||||
var channel = event.params[1];
|
||||
|
||||
if(_.isUndefined(channel)) {
|
||||
this.internalAPI.highscore('user_stats', 'curses', function(lCounts) {
|
||||
async.eachSeries(lCounts, function(lCount, next) {
|
||||
dbot.api.users.getUser(lCount[0], function(user) {
|
||||
lCount[0] = user.primaryNick; next();
|
||||
});
|
||||
}, function() {
|
||||
event.reply(this.internalAPI.formatHighscore('Most uncouth users: ', lCounts));
|
||||
}.bind(this));
|
||||
} else {
|
||||
this.internalAPI.channelHighscore('user_stats', event.server, channel, 'curses', function(lCounts) {
|
||||
if(lCounts) {
|
||||
event.reply(this.internalAPI.formatHighscore('Most uncouth users in ' + channel + ': ', lCounts));
|
||||
} else {
|
||||
event.reply('Unknown channel.');
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
},
|
||||
|
||||
'~shoutiest': function(event) {
|
||||
var channel = event.params[1];
|
||||
|
||||
if(_.isUndefined(channel)) {
|
||||
this.internalAPI.highscore('user_stats', 'capitals', function(lCounts) {
|
||||
async.eachSeries(lCounts, function(lCount, next) {
|
||||
dbot.api.users.getUser(lCount[0], function(user) {
|
||||
lCount[0] = user.primaryNick; next();
|
||||
});
|
||||
}, function() {
|
||||
event.reply(this.internalAPI.formatHighscore('Shoutiest users: ', lCounts));
|
||||
}.bind(this));
|
||||
} else {
|
||||
this.internalAPI.channelHighscore('user_stats', event.server, channel, 'capitals', function(lCounts) {
|
||||
if(lCounts) {
|
||||
event.reply(this.internalAPI.formatHighscore('Shoutiest users in ' + channel + ': ', lCounts));
|
||||
} else {
|
||||
event.reply('Unknown channel.');
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
},
|
||||
|
||||
'~wordiest': function(event) {
|
||||
var channel = event.params[1];
|
||||
|
||||
if(_.isUndefined(channel)) {
|
||||
this.internalAPI.highscore('user_stats', 'words', function(lCounts) {
|
||||
async.eachSeries(lCounts, function(lCount, next) {
|
||||
dbot.api.users.getUser(lCount[0], function(user) {
|
||||
lCount[0] = user.primaryNick; next();
|
||||
});
|
||||
}, function() {
|
||||
event.reply(this.internalAPI.formatHighscore('Wordiest users: ', lCounts));
|
||||
}.bind(this));
|
||||
} else {
|
||||
this.internalAPI.channelHighscore('user_stats', event.server, channel, 'words', function(lCounts) {
|
||||
if(lCounts) {
|
||||
event.reply(this.internalAPI.formatHighscore('Wordiest users in ' + channel + ': ', lCounts));
|
||||
} else {
|
||||
event.reply('Unknown channel.');
|
||||
}
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
'~cloudest': function(event) {
|
||||
var pathString = 'channels.' + event.rChannel.id + '.lines';
|
||||
this.internalAPI.highscore('user_stats', pathString, function(lCounts) {
|
||||
async.eachSeries(lCounts, function(lCount, next) {
|
||||
dbot.api.users.getUser(lCount[0], function(user) {
|
||||
lCount[0] = user.primaryNick; next();
|
||||
});
|
||||
}, function() {
|
||||
event.reply(this.internalAPI.formatHighscore('Loudest users in ' + event.channel + ': ', lCounts));
|
||||
}.bind(this));;
|
||||
}.bind(this));
|
||||
}
|
||||
},
|
||||
|
||||
'~clines': function(event) {
|
||||
|
@ -2,7 +2,8 @@
|
||||
* Module Name: sstats
|
||||
* Description: Simple Stats, in the absence of good ones.
|
||||
*/
|
||||
var _ = require('underscore')._;
|
||||
var _ = require('underscore')._,
|
||||
async = require('async');
|
||||
|
||||
var sstats = function(dbot) {
|
||||
if(!_.has(dbot.db, 'ssinception')) dbot.db.ssinception = new Date().getTime();
|
||||
@ -42,8 +43,25 @@ var sstats = function(dbot) {
|
||||
.first(10)
|
||||
.value();
|
||||
|
||||
callback(pCounts);
|
||||
async.eachSeries(pCounts, function(pCount, next) {
|
||||
dbot.api.users.getUser(pCount[0], function(user) {
|
||||
pCount[0] = user.primaryNick; next();
|
||||
});
|
||||
}, function() {
|
||||
callback(pCounts);
|
||||
}.bind(this));
|
||||
});
|
||||
}.bind(this),
|
||||
|
||||
'channelHighscore': function(key, server, channel, property, callback) {
|
||||
dbot.api.users.resolveChannel(server, channel, function(channel) {
|
||||
if(channel) {
|
||||
var newProperty = 'channels.' + channel.id + '.' + property;
|
||||
this.internalAPI.highscore(key, newProperty, callback);
|
||||
} else {
|
||||
callback(null);
|
||||
}
|
||||
}.bind(this));
|
||||
}.bind(this),
|
||||
|
||||
'formatHighscore': function(string, pCounts) {
|
||||
|
Loading…
Reference in New Issue
Block a user