From 4a8e5d0cc05181b90455b55015721f31b8baa445 Mon Sep 17 00:00:00 2001 From: John Maguire Date: Thu, 21 Mar 2013 03:41:27 -0400 Subject: [PATCH 1/4] fix error on ~link when web is misconfigured/not loaded --- modules/quotes/commands.js | 21 +++++++++++++-------- modules/quotes/strings.json | 3 +++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/modules/quotes/commands.js b/modules/quotes/commands.js index 34166aa..336f89d 100644 --- a/modules/quotes/commands.js +++ b/modules/quotes/commands.js @@ -194,14 +194,19 @@ var commands = function(dbot) { '~link': function(event) { var key = event.input[1].toLowerCase(); if(_.has(quotes, key)) { - event.reply(dbot.t('quote_link', { - 'category': key, - 'url': dbot.t('url', { - 'host': dbot.config.web.webHost, - 'port': dbot.config.web.webPort, - 'path': 'quotes/' + encodeURIComponent(key) - }) - })); + if(_.has(dbot.config, 'web') && _.has(dbot.config.web, 'webHost') && + _.has(dbot.config.web, 'webPort')) { + event.reply(dbot.t('quote_link', { + 'category': key, + 'url': dbot.t('url', { + 'host': dbot.config.web.webHost, + 'port': dbot.config.web.webPort, + 'path': 'quotes/' + encodeURIComponent(key) + }) + })); + } else { + event.reply(dbot.t('web_not_configured')); + } } else { event.reply(dbot.t('category_not_found', { 'category': key })); } diff --git a/modules/quotes/strings.json b/modules/quotes/strings.json index 5c3d3d3..2622f68 100644 --- a/modules/quotes/strings.json +++ b/modules/quotes/strings.json @@ -126,5 +126,8 @@ "rm_cache_limit": { "en": "Attention: Too many quotes removed, rmCache must be cleared or reinstated manually with ~rmconfirm or ~rmdeny.", "na'vi": "Oel zerok 'upxareti apxay set, sweylu txo nga 'aivku upxareti ìlä ~rmconfirm fu ~rmdeny." + }, + "web_not_configured": { + "en": "Cannot link to category. Web module is either not loaded or misconfigured." } } From 25b6099fbd3db4c0873c3c8bc6c057bc0b5f245c Mon Sep 17 00:00:00 2001 From: John Maguire Date: Thu, 21 Mar 2013 03:41:53 -0400 Subject: [PATCH 2/4] fix error on ~rmlast when category doesn't exist --- modules/quotes/commands.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/quotes/commands.js b/modules/quotes/commands.js index 336f89d..608b159 100644 --- a/modules/quotes/commands.js +++ b/modules/quotes/commands.js @@ -110,7 +110,7 @@ var commands = function(dbot) { 'category': key })); } else { - event.reply(dbot.t('no_quotes', {'category': q[1]})); + event.reply(dbot.t('no_quotes', {'category': key})); } } else { event.reply(dbot.t('rmlast_spam')); From 4e6393dd9a9f177361faf1593bec7fd24334f98e Mon Sep 17 00:00:00 2001 From: John Maguire Date: Thu, 21 Mar 2013 03:42:13 -0400 Subject: [PATCH 3/4] don't allow whitespace-only categories for ~qadd --- modules/quotes/commands.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/quotes/commands.js b/modules/quotes/commands.js index 608b159..89fc33c 100644 --- a/modules/quotes/commands.js +++ b/modules/quotes/commands.js @@ -218,7 +218,7 @@ var commands = function(dbot) { commands['~qsearch'].regex = [/^~qsearch ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3]; commands['~rm'].regex = [/^~rm ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3]; commands['~rmlast'].regex = [/^~rmlast ([\d\w\s-]*)/, 2]; - commands['~qadd'].regex = [/^~qadd ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3]; + commands['~qadd'].regex = [/^~qadd ([\d\w-]+[\d\w\s-]*)[ ]?=[ ]?(.+)$/, 3]; commands['~link'].regex = [/^~link ([\d\w\s-]*)/, 2]; commands['~rmconfirm'].access = 'moderator'; From fac4cb73b13d416f9a8ffcc79a074144ee7d6ac9 Mon Sep 17 00:00:00 2001 From: John Maguire Date: Thu, 21 Mar 2013 04:00:07 -0400 Subject: [PATCH 4/4] fixing ~rq error on empty quote db --- modules/quotes/commands.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/quotes/commands.js b/modules/quotes/commands.js index 89fc33c..207a30d 100644 --- a/modules/quotes/commands.js +++ b/modules/quotes/commands.js @@ -187,8 +187,12 @@ var commands = function(dbot) { }, '~rq': function(event) { - var category = _.keys(quotes)[_.random(0, _.size(quotes) -1)]; - event.reply(category + ': ' + this.internalAPI.interpolatedQuote(event.server, event.channel.name, category)); + if(_.keys(quotes).length > 0) { + var category = _.keys(quotes)[_.random(0, _.size(quotes) -1)]; + event.reply(category + ': ' + this.internalAPI.interpolatedQuote(event.server, event.channel.name, category)); + } else { + event.reply(dbot.t('no_results')); + } }, '~link': function(event) {