From 6d5c6a5a78b306fd5d6f723f43f2a541614f1d1f Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Wed, 17 Aug 2011 17:02:38 +0100 Subject: [PATCH] Quote arrays. Perhaps needs a bit of cleaning up. --- run.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/run.js b/run.js index 2ebc514..a939809 100644 --- a/run.js +++ b/run.js @@ -110,6 +110,26 @@ instance.addListener('PRIVMSG', function(data) { var q = data.message.match(/~q ([\d\w\s]*)/)[1].trim(); instance.say(data.channel, q + ': ' + db.quotes[q]); break; + case '~qa': + var q = data.message.match(/~qa ([\d\w\s]*)/)[1].trim(); + if(db.quoteArrs[q] != undefined) { + instance.say(data.channel, q + ': ' + db.quoteArrs[q].random()); + } + break; + case '~qadd': + var qadd = data.message.match(/~qadd ([\d\w\s]*)=(.+)$/); + if(qadd != null && qadd.length >= 3) { + if(Object.isArray(db.quoteArrs[qadd[1]])) { + db.quoteArrs[qadd[1]].push(qadd[2]); + } else { + db.quoteArrs[qadd[1]] = [qadd[2]]; + } + instance.say(data.channel, 'Quote saved in \'' + qadd[1] + '\''); + fs.writeFile('db.json', JSON.stringify(db, null, ' ')); + } else { + instance.say(data.channel, 'Burn the invalid syntax!'); + } + break; case '~lamp': instance.say(data.channel, db.lampPuns.random()); break;