From 099d278cbcc9abe32c9bb5629a2ba3de0d5f3792 Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 22 Apr 2013 15:50:05 +0000 Subject: [PATCH] dont add quotes that already exist [#331] --- modules/quotes/commands.js | 14 +++++++++----- modules/quotes/quotes.js | 14 +++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/modules/quotes/commands.js b/modules/quotes/commands.js index fe3fc3e..e8205c7 100644 --- a/modules/quotes/commands.js +++ b/modules/quotes/commands.js @@ -12,11 +12,15 @@ var commands = function(dbot) { quote = event.input[2]; this.api.addQuote(key, quote, event.user, function(newCount) { - dbot.api.event.emit('~qadd', [ key, quote ]); - event.reply(dbot.t('quote_saved', { - 'category': key, - 'count': newCount - })); + if(newCount) { + dbot.api.event.emit('~qadd', [ key, quote ]); + event.reply(dbot.t('quote_saved', { + 'category': key, + 'count': newCount + })); + } else { + event.reply(dbot.t('quote_exists')); + } }); }, diff --git a/modules/quotes/quotes.js b/modules/quotes/quotes.js index e61ca15..36287f1 100644 --- a/modules/quotes/quotes.js +++ b/modules/quotes/quotes.js @@ -76,11 +76,15 @@ var quotes = function(dbot) { }; } - newCount = category.quotes.push(quote); - this.db.save('quote_category', category.id, category, function(err) { - this.rmAllowed = true; - callback(newCount); - }.bind(this)); + if(_.include(category.quotes, quote)) { + callback(false); + } else { + newCount = category.quotes.push(quote); + this.db.save('quote_category', category.id, category, function(err) { + this.rmAllowed = true; + callback(newCount); + }.bind(this)); + } }.bind(this)); },