From f48e4c3942a970f813fb8806bd3c7c510dafffd0 Mon Sep 17 00:00:00 2001 From: reality Date: Fri, 11 Apr 2014 23:19:31 +0000 Subject: [PATCH] something something channel users --- modules/quotes/quotes.js | 2 +- modules/users/api.js | 23 +++++++---------------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/modules/quotes/quotes.js b/modules/quotes/quotes.js index 53a8ef0..004d4a0 100644 --- a/modules/quotes/quotes.js +++ b/modules/quotes/quotes.js @@ -17,7 +17,7 @@ var quotes = function(dbot) { var ref = this.internalAPI.cleanRef(quoteRefs[0].replace(/^~~/,'').replace(/~~$/,'').trim()); if(ref === '-nicks-') { dbot.api.users.getRandomChannelUser(server, channel, function(user) { - quote = quote.replace('~~' + ref + '~~', user.currentNick); + quote = quote.replace('~~' + ref + '~~', user); this.internalAPI.interpolatedQuote(server, channel, username, key, quote, callback); }.bind(this)); diff --git a/modules/users/api.js b/modules/users/api.js index 5649a95..4458bbb 100644 --- a/modules/users/api.js +++ b/modules/users/api.js @@ -89,22 +89,13 @@ var api = function(dbot) { }, 'getRandomChannelUser': function(server, cName, callback) { - var channel; - this.db.search('channel_users', { - 'server': server, - 'name': cName - }, function(result) { - channel = result; - }, 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)); + if(_.has(dbot.instance.connections[server].channels, cName)) { + var nicks = _.keys(dbot.instance.connections[server].channels[cName].nicks); + var randomUser = nicks[_.random(0, nicks.length -1)] + callback(randomUser); + } else { + callback(false); + } }, 'getAllUsers': function(callback) {