From 4555e12eaa6a50a236e8c5017f4d3ca5e9002533 Mon Sep 17 00:00:00 2001 From: reality Date: Sat, 26 Jan 2013 20:08:09 +0000 Subject: [PATCH] Fix quote interpol + no need to pass event [#230][#156] --- modules/quotes/commands.js | 2 +- modules/quotes/config.json | 2 +- modules/quotes/quotes.js | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/quotes/commands.js b/modules/quotes/commands.js index c3d0522..c99fd01 100644 --- a/modules/quotes/commands.js +++ b/modules/quotes/commands.js @@ -188,7 +188,7 @@ var commands = function(dbot) { '~rq': function(event) { var category = _.keys(quotes)[_.random(0, _.size(quotes) -1)]; - event.reply(category + ': ' + this.internalAPI.interpolatedQuote(event, category)); + event.reply(category + ': ' + this.internalAPI.interpolatedQuote(event.server, event.channel.name, category)); }, '~link': function(event) { diff --git a/modules/quotes/config.json b/modules/quotes/config.json index 7530554..e8d0465 100644 --- a/modules/quotes/config.json +++ b/modules/quotes/config.json @@ -1,6 +1,6 @@ { "dbKeys": [ "quoteArrs" ], - "dependencies": [ "command" ], + "dependencies": [ "command", "users" ], "rmLimit": 10, "ignorable": true, "help": "http://github.com/reality/depressionbot/blob/master/modules/quotes/README.md" diff --git a/modules/quotes/quotes.js b/modules/quotes/quotes.js index 85d9fb0..b1b2639 100644 --- a/modules/quotes/quotes.js +++ b/modules/quotes/quotes.js @@ -11,7 +11,7 @@ var quotes = function(dbot) { this.internalAPI = { // Retrieve a random quote from a given category, interpolating any quote // references (~~QUOTE CATEGORY~~) within it - 'interpolatedQuote': function(event, key, quoteTree) { + 'interpolatedQuote': function(server, channel, key, quoteTree) { if(!_.isUndefined(quoteTree) && quoteTree.indexOf(key) != -1) { return ''; } else if(_.isUndefined(quoteTree)) { @@ -28,13 +28,13 @@ var quotes = function(dbot) { while(quoteRefs && (thisRef = quoteRefs.shift()) !== undefined) { var cleanRef = dbot.cleanNick(thisRef.replace(/^~~/,'').replace(/~~$/,'').trim()); if(cleanRef === '-nicks-') { - var randomNick = _.keys(event.channel.nicks)[_.random(0, _.size(event.channel.nicks) -1)]; + var randomNick = dbot.api.users.getRandomChannelUser(server, channel); quoteString = quoteString.replace("~~" + cleanRef + "~~", randomNick); quoteTree.pop(); } else if(_.has(this.quotes, cleanRef)) { quoteTree.push(key); quoteString = quoteString.replace("~~" + cleanRef + "~~", - interpolatedQuote(event, cleanRef, quoteTree.slice())); + this.internalAPI.interpolatedQuote(server, channel, cleanRef, quoteTree.slice())); quoteTree.pop(); } } @@ -76,9 +76,9 @@ var quotes = function(dbot) { if(key.charAt(0) !== '_') { // lol if(_.has(this.quotes, key)) { - return this.internalAPI.interpolatedQuote(event, key); + return this.internalAPI.interpolatedQuote(event.server, event.channel.name, key); } else if(_.has(this.quotes, altKey)) { - return this.internalAPI.interpolatedQuote(event, altKey); + return this.internalAPI.interpolatedQuote(event.server, event.channel.name, altKey); } else { return false; }