2013-10-17 11:10:01 +02:00
|
|
|
var _ = require('underscore')._,
|
2013-10-17 16:31:05 +02:00
|
|
|
async = require('async'),
|
|
|
|
moment = require('moment');
|
2013-10-16 17:12:05 +02:00
|
|
|
|
|
|
|
var commands = function(dbot) {
|
|
|
|
var commands = {
|
2013-10-17 05:59:29 +02:00
|
|
|
'~words': function(event) {
|
|
|
|
var getWords = function(user) {
|
|
|
|
this.api.getUserStats(user.id, function(uStats) {
|
|
|
|
if(uStats) {
|
|
|
|
var output = dbot.t('sstats_uwords', {
|
|
|
|
'user': user.primaryNick,
|
|
|
|
'words': uStats.words,
|
|
|
|
'curses': uStats.curses,
|
|
|
|
'capitals': uStats.capitals
|
|
|
|
});
|
|
|
|
if(event.rChannel && _.has(uStats.channels, event.rChannel.id)) {
|
|
|
|
ucStats = uStats.channels[event.rChannel.id];
|
|
|
|
output += dbot.t('sstats_ucwords', {
|
|
|
|
'channel': event.channel,
|
|
|
|
'words': ucStats.words,
|
|
|
|
'curses': ucStats.curses,
|
|
|
|
'capitals': ucStats.capitals
|
|
|
|
});
|
|
|
|
}
|
|
|
|
event.reply(output);
|
|
|
|
} else {
|
|
|
|
event.reply(dbot.t('sstats_noustats'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}.bind(this);
|
|
|
|
|
|
|
|
if(event.params[1]) {
|
|
|
|
dbot.api.users.resolveUser(event.server, event.params[1], function(user) {
|
|
|
|
if(user) {
|
|
|
|
getWords(user);
|
|
|
|
} else {
|
|
|
|
event.reply(dbot.t('sstats_unknown_user'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
getWords(event.rUser);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-10-16 17:12:05 +02:00
|
|
|
'~lines': function(event) {
|
2013-10-16 17:22:45 +02:00
|
|
|
var getLines = function(user) {
|
|
|
|
this.api.getUserStats(user.id, function(uStats) {
|
2013-10-16 17:12:05 +02:00
|
|
|
if(uStats) {
|
|
|
|
var output = dbot.t('sstats_tlines', {
|
2013-10-16 17:22:45 +02:00
|
|
|
'user': user.primaryNick,
|
2013-10-16 17:12:05 +02:00
|
|
|
'lines': uStats.lines
|
|
|
|
});
|
|
|
|
if(event.rChannel && _.has(uStats.channels, event.rChannel.id)) {
|
|
|
|
output += dbot.t('sstats_uclines', {
|
|
|
|
'channel': event.channel,
|
|
|
|
'lines': uStats.channels[event.rChannel.id].lines
|
|
|
|
});
|
|
|
|
}
|
|
|
|
event.reply(output);
|
|
|
|
} else {
|
|
|
|
event.reply(dbot.t('sstats_noustats'));
|
|
|
|
}
|
|
|
|
});
|
2013-10-16 17:22:45 +02:00
|
|
|
}.bind(this);
|
|
|
|
|
|
|
|
if(event.params[1]) {
|
|
|
|
dbot.api.users.resolveUser(event.server, event.params[1], function(user) {
|
|
|
|
if(user) {
|
|
|
|
getLines(user);
|
|
|
|
} else {
|
|
|
|
event.reply(dbot.t('sstats_unknown_user'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
getLines(event.rUser);
|
2013-10-16 17:12:05 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-10-17 11:10:01 +02:00
|
|
|
'~loudest': function(event) {
|
2013-10-17 14:46:55 +02:00
|
|
|
var channel = event.params[1];
|
|
|
|
|
|
|
|
if(_.isUndefined(channel)) {
|
|
|
|
this.internalAPI.highscore('user_stats', 'lines', function(lCounts) {
|
2013-10-17 13:42:05 +02:00
|
|
|
event.reply(this.internalAPI.formatHighscore('Loudest users: ', lCounts));
|
|
|
|
}.bind(this));
|
2013-10-17 14:46:55 +02:00
|
|
|
} 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));
|
|
|
|
}
|
2013-10-17 13:46:50 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
'~uncouth': function(event) {
|
2013-10-17 14:46:55 +02:00
|
|
|
var channel = event.params[1];
|
|
|
|
|
|
|
|
if(_.isUndefined(channel)) {
|
|
|
|
this.internalAPI.highscore('user_stats', 'curses', function(lCounts) {
|
2013-10-17 13:46:50 +02:00
|
|
|
event.reply(this.internalAPI.formatHighscore('Most uncouth users: ', lCounts));
|
|
|
|
}.bind(this));
|
2013-10-17 14:46:55 +02:00
|
|
|
} 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));
|
|
|
|
}
|
2013-10-17 13:50:34 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
'~shoutiest': function(event) {
|
2013-10-17 14:46:55 +02:00
|
|
|
var channel = event.params[1];
|
|
|
|
|
|
|
|
if(_.isUndefined(channel)) {
|
|
|
|
this.internalAPI.highscore('user_stats', 'capitals', function(lCounts) {
|
2013-10-17 13:50:34 +02:00
|
|
|
event.reply(this.internalAPI.formatHighscore('Shoutiest users: ', lCounts));
|
|
|
|
}.bind(this));
|
2013-10-17 14:46:55 +02:00
|
|
|
} 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));
|
|
|
|
}
|
2013-10-17 13:50:34 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
'~wordiest': function(event) {
|
2013-10-17 14:46:55 +02:00
|
|
|
var channel = event.params[1];
|
|
|
|
|
|
|
|
if(_.isUndefined(channel)) {
|
|
|
|
this.internalAPI.highscore('user_stats', 'words', function(lCounts) {
|
2013-10-17 13:50:34 +02:00
|
|
|
event.reply(this.internalAPI.formatHighscore('Wordiest users: ', lCounts));
|
|
|
|
}.bind(this));
|
2013-10-17 14:46:55 +02:00
|
|
|
} 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));
|
|
|
|
}
|
2013-10-17 11:16:50 +02:00
|
|
|
},
|
|
|
|
|
2013-10-16 17:12:05 +02:00
|
|
|
'~clines': function(event) {
|
|
|
|
if(!event.cStats) return;
|
|
|
|
event.reply(dbot.t('sstats_clines', {
|
|
|
|
'channel': event.channel,
|
|
|
|
'lines': event.cStats.lines
|
|
|
|
}));
|
2013-10-17 16:31:05 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
'~last': function(event) {
|
|
|
|
dbot.api.users.resolveUser(event.server, event.params[1], function(user) {
|
|
|
|
if(user) {
|
|
|
|
this.api.getUserStats(user.id, function(uStats) {
|
|
|
|
if(uStats && uStats.last) {
|
|
|
|
event.reply(user.primaryNick + ' was last seen ' + moment(uStats.last).fromNow() + '.');
|
|
|
|
} else {
|
|
|
|
event.reply('I haven\'t seen that user active yet.');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
event.reply('Unknown user.');
|
|
|
|
}
|
|
|
|
}.bind(this));
|
2013-10-20 20:29:54 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
'~trackword': function(event) {
|
|
|
|
var word = event.params[1].trim();
|
|
|
|
this.api.getTrackedWord(word, function(tWord) {
|
|
|
|
if(!tWord) {
|
|
|
|
this.api.createTrackedWord(word, function(tWord) {
|
|
|
|
event.reply('Now tracking ' + word);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
event.reply('Word already being tracked.');
|
|
|
|
}
|
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
|
|
|
|
'~word': function(event) {
|
|
|
|
var word = event.params[1].trim();
|
|
|
|
this.api.getTrackedWord(word, function(tWord) {
|
|
|
|
if(tWord) {
|
|
|
|
event.reply(dbot.t('sstats_word', {
|
|
|
|
'word': word,
|
|
|
|
'total': tWord.total,
|
|
|
|
'channels': _.keys(tWord.channels).length,
|
|
|
|
'users': _.keys(tWord.users).length,
|
|
|
|
'since': new Date(tWord.creation)
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
event.reply(word + ' isn\'t being tracked.');
|
|
|
|
}
|
|
|
|
});
|
2013-10-20 20:42:00 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// merge to some raw highscore thing
|
|
|
|
'~wordusers': function(event) {
|
|
|
|
var word = event.params[1].trim();
|
|
|
|
this.api.getTrackedWord(word, function(tWord) {
|
|
|
|
if(tWord) {
|
|
|
|
var pCounts = _.chain(tWord.users)
|
|
|
|
.pairs()
|
|
|
|
.sortBy(function(p) { return p[1]; })
|
|
|
|
.reverse()
|
|
|
|
.first(10)
|
|
|
|
.value();
|
|
|
|
|
|
|
|
async.eachSeries(pCounts, function(pCount, next) {
|
|
|
|
dbot.api.users.getUser(pCount[0], function(user) {
|
|
|
|
pCount[0] = user.primaryNick; next();
|
|
|
|
});
|
|
|
|
}, function() {
|
|
|
|
event.reply(this.internalAPI.formatHighscore('Top ' + word + ' users: ', pCounts));
|
|
|
|
}.bind(this));
|
|
|
|
} else {
|
|
|
|
event.reply(word + ' isn\'t being tracked.');
|
|
|
|
}
|
|
|
|
}.bind(this));
|
2013-10-16 17:12:05 +02:00
|
|
|
}
|
|
|
|
};
|
2013-10-20 20:42:00 +02:00
|
|
|
|
|
|
|
commands['~wordusers'].regex = [/^~wordusers ([\d\w[\]{}^|\\`_-]+?)/, 2];
|
2013-10-20 20:29:54 +02:00
|
|
|
commands['~trackword'].access = 'power_user';
|
2013-10-16 17:12:05 +02:00
|
|
|
return commands;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.fetch = function(dbot) {
|
|
|
|
return commands(dbot);
|
|
|
|
};
|