From a4313ee665e3e7ec5ba19666455b74742f27e1cb Mon Sep 17 00:00:00 2001 From: Psychedelic Squid Date: Wed, 14 Mar 2012 13:59:26 +0000 Subject: [PATCH 1/3] '~CATEGORY' now dispatches a '~q CATEGORY' command. --- modules/command.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/command.js b/modules/command.js index 7c23cec..df617bf 100644 --- a/modules/command.js +++ b/modules/command.js @@ -66,8 +66,14 @@ var command = function(dbot) { } else { q[1] = q[1].trim(); key = dbot.cleanNick(q[1]) - if(dbot.db.quoteArrs.hasOwnProperty(key)) { - dbot.say(data.channel, q[1] + ': ' + dbot.interpolatedQuote(key)); + if(dbot.db.quoteArrs.hasOwnProperty(key) && dbot.moduleNames.include('quotes')) { + var params = ['~q']; + key.split(' ').each((function(word) { + this.push(word); + }).bind(params)); + data.message = params.join(' '); + dbot.commands[params[0]](data, params); + dbot.save(); } else { // See if it's similar to anything var winnerDistance = Infinity; From a08e904ea674f40148a42ed5d6289479a9039609 Mon Sep 17 00:00:00 2001 From: Psychedelic Squid Date: Wed, 14 Mar 2012 14:20:59 +0000 Subject: [PATCH 2/3] Puns also changed to dispatch a '~q' --- modules/puns.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/puns.js b/modules/puns.js index 8578129..2b591ed 100644 --- a/modules/puns.js +++ b/modules/puns.js @@ -3,10 +3,14 @@ var puns = function(dbot) { return { 'listener': function(data) { - if(data.user == 'reality') { - dbot.instance.say(data.channel, dbot.interpolatedQuote('realityonce')); - } else if(dbot.db.quoteArrs.hasOwnProperty(data.user.toLowerCase())) { - dbot.say(data.channel, data.user + ': ' + dbot.interpolatedQuote(data.user.toLowerCase())); + if(dbot.moduleNames.include('quotes')) { + if(data.user == 'reality') { + data.message = '~q realityonce'; + } else if(dbot.db.quoteArrs.hasOwnProperty(data.user.toLowerCase())) { + data.message = '~q ' + data.user.toLowerCase(); + } + var params = data.message.split(' '); + dbot.commands[params[0]](data, params); } }, From 155a2f2f84865149701cd1fa9db201614282cbc5 Mon Sep 17 00:00:00 2001 From: Psychedelic Squid Date: Wed, 14 Mar 2012 14:35:37 +0000 Subject: [PATCH 3/3] interpolatedQuote fully transplanted into quotes.js, should reduce pesky run.js reloading to near-zero --- modules/quotes.js | 24 +++++++++++++++++++++--- run.js | 18 ------------------ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/modules/quotes.js b/modules/quotes.js index f08b3e1..d001260 100644 --- a/modules/quotes.js +++ b/modules/quotes.js @@ -2,6 +2,24 @@ var quotes = function(dbot) { var quotes = dbot.db.quoteArrs; var addStack = []; var rmAllowed = true; + + // Retrieve a random quote from a given category, interpolating any quote references (~~QUOTE CATEGORY~~) within it + var interpolatedQuote = function(key, quoteTree) { + if( quoteTree !== undefined && quoteTree.indexOf( key ) != -1 ) { console.log('nrll'); return ''; } + else if( quoteTree === undefined ) quoteTree = []; + var quoteString = quotes[key].random(); + var quoteRefs = quoteString.match(/~~([\d\w\s-]*)~~/g); + var thisRef; + while( quoteRefs && (thisRef = quoteRefs.shift()) !== undefined ) { + var cleanRef = dbot.cleanNick(thisRef.replace(/^~~/,'').replace(/~~$/,'').trim()); + if (quotes.hasOwnProperty(cleanRef)) { + quoteTree.push( key ); + quoteString = quoteString.replace("~~"+cleanRef+"~~", interpolatedQuote(cleanRef, quoteTree.slice())); + quoteTree.pop(); + } + } + return quoteString; + }; var commands = { '~q': function(data, params) { @@ -10,7 +28,7 @@ var quotes = function(dbot) { q[1] = q[1].trim(); key = q[1].toLowerCase(); if(quotes.hasOwnProperty(key)) { - dbot.say(data.channel, q[1] + ': ' + dbot.interpolatedQuote(key)); + dbot.say(data.channel, q[1] + ': ' + interpolatedQuote(key)); } else { dbot.say(data.channel, 'Nobody loves ' + q[1]); } @@ -192,11 +210,11 @@ var quotes = function(dbot) { '~rq': function(data, params) { var rQuote = Object.keys(quotes).random(); - dbot.say(data.channel, rQuote + ': ' + dbot.interpolatedQuote(rQuote)); + dbot.say(data.channel, rQuote + ': ' + interpolatedQuote(rQuote)); }, '~d': function(data, params) { - dbot.say(data.channel, data.user + ': ' + dbot.interpolatedQuote(dbot.name)); + dbot.say(data.channel, data.user + ': ' + interpolatedQuote(dbot.name)); }, '~link': function(data, params) { diff --git a/run.js b/run.js index be13c93..bdb5e1b 100644 --- a/run.js +++ b/run.js @@ -66,24 +66,6 @@ var DBot = function(timers) { this.instance.connect(); }; -// Retrieve a random quote from a given category, interpolating any quote references (~~QUOTE CATEGORY~~) within it -DBot.prototype.interpolatedQuote = function(key, quoteTree) { - if( quoteTree !== undefined && quoteTree.indexOf( key ) != -1 ) { console.log('nrll'); return ''; } - else if( quoteTree === undefined ) quoteTree = []; - var quoteString = this.db.quoteArrs[key].random(); - var quoteRefs = quoteString.match(/~~([\d\w\s-]*)~~/g); - var thisRef; - while( quoteRefs && (thisRef = quoteRefs.shift()) !== undefined ) { - var cleanRef = this.cleanNick(thisRef.replace(/^~~/,'').replace(/~~$/,'').trim()); - if (this.db.quoteArrs.hasOwnProperty(cleanRef)) { - quoteTree.push( key ); - quoteString = quoteString.replace("~~"+cleanRef+"~~", this.interpolatedQuote(cleanRef, quoteTree.slice())); - quoteTree.pop(); - } - } - return quoteString; -}; - // Say something in a channel DBot.prototype.say = function(channel, data) { this.instance.say(channel, data);