3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-27 14:29:29 +01:00

something something channel users

This commit is contained in:
reality 2014-04-11 23:19:31 +00:00
parent 5644675b74
commit f48e4c3942
2 changed files with 8 additions and 17 deletions

View File

@ -17,7 +17,7 @@ var quotes = function(dbot) {
var ref = this.internalAPI.cleanRef(quoteRefs[0].replace(/^~~/,'').replace(/~~$/,'').trim()); var ref = this.internalAPI.cleanRef(quoteRefs[0].replace(/^~~/,'').replace(/~~$/,'').trim());
if(ref === '-nicks-') { if(ref === '-nicks-') {
dbot.api.users.getRandomChannelUser(server, channel, function(user) { dbot.api.users.getRandomChannelUser(server, channel, function(user) {
quote = quote.replace('~~' + ref + '~~', user.currentNick); quote = quote.replace('~~' + ref + '~~', user);
this.internalAPI.interpolatedQuote(server, channel, this.internalAPI.interpolatedQuote(server, channel,
username, key, quote, callback); username, key, quote, callback);
}.bind(this)); }.bind(this));

View File

@ -89,22 +89,13 @@ var api = function(dbot) {
}, },
'getRandomChannelUser': function(server, cName, callback) { 'getRandomChannelUser': function(server, cName, callback) {
var channel; if(_.has(dbot.instance.connections[server].channels, cName)) {
this.db.search('channel_users', { var nicks = _.keys(dbot.instance.connections[server].channels[cName].nicks);
'server': server, var randomUser = nicks[_.random(0, nicks.length -1)]
'name': cName callback(randomUser);
}, function(result) { } else {
channel = result; callback(false);
}, function(err) { }
if(!err && channel) {
if(!_.isUndefined(channel.users)) {
var randomUser = channel.users[_.random(0, channel.users.length - 1)];
this.api.getUser(randomUser, callback);
} else {
callback(false);
}
}
}.bind(this));
}, },
'getAllUsers': function(callback) { 'getAllUsers': function(callback) {