From 1d2659f3618506955c0e374e5572f0fe9044fd35 Mon Sep 17 00:00:00 2001 From: Psychedelic Squid Date: Wed, 7 Mar 2012 22:13:31 +0000 Subject: [PATCH] Interpolated quotes, because why not? --- modules/puns.js | 4 ++-- modules/quotes.js | 6 +++--- run.js | 18 +++++++++++++++++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/modules/puns.js b/modules/puns.js index 1cc2661..29b7ae9 100644 --- a/modules/puns.js +++ b/modules/puns.js @@ -4,9 +4,9 @@ var puns = function(dbot) { return { 'listener': function(data) { if(data.user == 'reality') { - dbot.instance.say(data.channel, dbot.db.quoteArrs['realityonce'].random()); + dbot.instance.say(data.channel, dbot.interpolatedQuote('realityonce')); } else if(dbot.db.quoteArrs.hasOwnProperty(data.user.toLowerCase())) { - dbot.say(data.channel, data.user + ': ' + dbot.db.quoteArrs[data.user.toLowerCase()].random()); + dbot.say(data.channel, data.user + ': ' + dbot.interpolatedQuote(data.user.toLowerCase())); } else if(dbot.instance.inChannel(data.channel)) { dbot.instance.say('aisbot', '.karma ' + data.user); dbot.waitingForKarma = data.channel; diff --git a/modules/quotes.js b/modules/quotes.js index 03e62a7..340adf2 100644 --- a/modules/quotes.js +++ b/modules/quotes.js @@ -10,7 +10,7 @@ var quotes = function(dbot) { q[1] = q[1].trim(); key = q[1].toLowerCase(); if(quotes.hasOwnProperty(key)) { - dbot.say(data.channel, q[1] + ': ' + quotes[key].random()); + dbot.say(data.channel, q[1] + ': ' + dbot.interpolatedQuote(key)); } else { dbot.say(data.channel, 'Nobody loves ' + q[1]); } @@ -189,11 +189,11 @@ var quotes = function(dbot) { '~rq': function(data, params) { var rQuote = Object.keys(quotes).random(); - dbot.say(data.channel, rQuote + ': ' + quotes[rQuote].random()); + dbot.say(data.channel, rQuote + ': ' + dbot.interpolatedQuote(rQuote)); }, '~d': function(data, params) { - dbot.say(data.channel, data.user + ': ' + dbot.db.quoteArrs['depressionbot'].random()); + dbot.say(data.channel, data.user + ': ' + dbot.interpolatedQuote('depressionbot')); }, '~link': function(data, params) { diff --git a/run.js b/run.js index 4d683fc..1071f15 100644 --- a/run.js +++ b/run.js @@ -61,6 +61,22 @@ 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) { + var quoteString = this.db.quoteArrs[key].random(); + var quoteRefs = quoteString.match(/~~([\d\w\s-]*)~~/); + if (quoteRefs) { + quoteRefs = quoteRefs.slice(1); + for(var i=0;i