From 58b58aa15fe26e15a3a25341a35d8102ff1ff23d Mon Sep 17 00:00:00 2001 From: reality Date: Fri, 12 Apr 2013 17:33:13 +0000 Subject: [PATCH] ~qadd uses only save rather than save|create [#331] --- modules/quotes/commands.js | 40 ++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/modules/quotes/commands.js b/modules/quotes/commands.js index e9b6719..f126360 100644 --- a/modules/quotes/commands.js +++ b/modules/quotes/commands.js @@ -11,36 +11,34 @@ var commands = function(dbot) { '~qadd': function(event) { var key = event.input[1].toLowerCase().trim(), quote = event.input[2], - newCount; - var quoteAdded = function(err, result) { - this.rmAllowed = true; - dbot.api.event.emit('~qadd', { - 'key': key, - 'text': quote - }); - event.reply(dbot.t('quote_saved', { - 'category': key, - 'count': newCount - })); - }.bind(this); + newCount, + category = false; - var category = false; this.db.search('quote_category', { 'name': key }, function(result) { category = result; }, function(err) { if(!category) { var id = uuid.v4(); - newCount = 1; - this.db.create('quote_category', id, { + category = { 'id': id, 'name': key, - 'quotes': [ quote ], + 'quotes': [], 'creator': event.user - }, quoteAdded); - } else { - newCount = category.quotes.push(quote); - this.db.save('quote_category', category.id, category, quoteAdded); - } + }; + } + + newCount = category.quotes.push(quote); + this.db.save('quote_category', category.id, category, function(err) { + this.rmAllowed = true; + dbot.api.event.emit('~qadd', { + 'key': key, + 'text': quote + }); + event.reply(dbot.t('quote_saved', { + 'category': key, + 'count': newCount + })); + }); }.bind(this)); },