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) {
|
'~loudest': function(event) {
|
||||||
this.internalAPI.highscore('user_stats', 'lines', function(lCounts) {
|
var channel = event.params[1];
|
||||||
async.eachSeries(lCounts, function(lCount, next) {
|
|
||||||
dbot.api.users.getUser(lCount[0], function(user) {
|
if(_.isUndefined(channel)) {
|
||||||
lCount[0] = user.primaryNick; next();
|
this.internalAPI.highscore('user_stats', 'lines', function(lCounts) {
|
||||||
});
|
|
||||||
}, function() {
|
|
||||||
event.reply(this.internalAPI.formatHighscore('Loudest users: ', lCounts));
|
event.reply(this.internalAPI.formatHighscore('Loudest users: ', lCounts));
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}.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) {
|
'~uncouth': function(event) {
|
||||||
this.internalAPI.highscore('user_stats', 'curses', function(lCounts) {
|
var channel = event.params[1];
|
||||||
async.eachSeries(lCounts, function(lCount, next) {
|
|
||||||
dbot.api.users.getUser(lCount[0], function(user) {
|
if(_.isUndefined(channel)) {
|
||||||
lCount[0] = user.primaryNick; next();
|
this.internalAPI.highscore('user_stats', 'curses', function(lCounts) {
|
||||||
});
|
|
||||||
}, function() {
|
|
||||||
event.reply(this.internalAPI.formatHighscore('Most uncouth users: ', lCounts));
|
event.reply(this.internalAPI.formatHighscore('Most uncouth users: ', lCounts));
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}.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) {
|
'~shoutiest': function(event) {
|
||||||
this.internalAPI.highscore('user_stats', 'capitals', function(lCounts) {
|
var channel = event.params[1];
|
||||||
async.eachSeries(lCounts, function(lCount, next) {
|
|
||||||
dbot.api.users.getUser(lCount[0], function(user) {
|
if(_.isUndefined(channel)) {
|
||||||
lCount[0] = user.primaryNick; next();
|
this.internalAPI.highscore('user_stats', 'capitals', function(lCounts) {
|
||||||
});
|
|
||||||
}, function() {
|
|
||||||
event.reply(this.internalAPI.formatHighscore('Shoutiest users: ', lCounts));
|
event.reply(this.internalAPI.formatHighscore('Shoutiest users: ', lCounts));
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}.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) {
|
'~wordiest': function(event) {
|
||||||
this.internalAPI.highscore('user_stats', 'words', function(lCounts) {
|
var channel = event.params[1];
|
||||||
async.eachSeries(lCounts, function(lCount, next) {
|
|
||||||
dbot.api.users.getUser(lCount[0], function(user) {
|
if(_.isUndefined(channel)) {
|
||||||
lCount[0] = user.primaryNick; next();
|
this.internalAPI.highscore('user_stats', 'words', function(lCounts) {
|
||||||
});
|
|
||||||
}, function() {
|
|
||||||
event.reply(this.internalAPI.formatHighscore('Wordiest users: ', lCounts));
|
event.reply(this.internalAPI.formatHighscore('Wordiest users: ', lCounts));
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}.bind(this));
|
} else {
|
||||||
},
|
this.internalAPI.channelHighscore('user_stats', event.server, channel, 'words', function(lCounts) {
|
||||||
|
if(lCounts) {
|
||||||
'~cloudest': function(event) {
|
event.reply(this.internalAPI.formatHighscore('Wordiest users in ' + channel + ': ', lCounts));
|
||||||
var pathString = 'channels.' + event.rChannel.id + '.lines';
|
} else {
|
||||||
this.internalAPI.highscore('user_stats', pathString, function(lCounts) {
|
event.reply('Unknown channel.');
|
||||||
async.eachSeries(lCounts, function(lCount, next) {
|
}
|
||||||
dbot.api.users.getUser(lCount[0], function(user) {
|
}.bind(this));
|
||||||
lCount[0] = user.primaryNick; next();
|
}
|
||||||
});
|
|
||||||
}, function() {
|
|
||||||
event.reply(this.internalAPI.formatHighscore('Loudest users in ' + event.channel + ': ', lCounts));
|
|
||||||
}.bind(this));;
|
|
||||||
}.bind(this));
|
|
||||||
},
|
},
|
||||||
|
|
||||||
'~clines': function(event) {
|
'~clines': function(event) {
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
* Module Name: sstats
|
* Module Name: sstats
|
||||||
* Description: Simple Stats, in the absence of good ones.
|
* Description: Simple Stats, in the absence of good ones.
|
||||||
*/
|
*/
|
||||||
var _ = require('underscore')._;
|
var _ = require('underscore')._,
|
||||||
|
async = require('async');
|
||||||
|
|
||||||
var sstats = function(dbot) {
|
var sstats = function(dbot) {
|
||||||
if(!_.has(dbot.db, 'ssinception')) dbot.db.ssinception = new Date().getTime();
|
if(!_.has(dbot.db, 'ssinception')) dbot.db.ssinception = new Date().getTime();
|
||||||
@ -42,10 +43,27 @@ var sstats = function(dbot) {
|
|||||||
.first(10)
|
.first(10)
|
||||||
.value();
|
.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),
|
}.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) {
|
'formatHighscore': function(string, pCounts) {
|
||||||
var output = string;
|
var output = string;
|
||||||
for(var i=0;i<pCounts.length;i++) {
|
for(var i=0;i<pCounts.length;i++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user