diff --git a/jsbot b/jsbot index 84a4783..2be1731 160000 --- a/jsbot +++ b/jsbot @@ -1 +1 @@ -Subproject commit 84a4783db76bdd729bd720c43485893ebe78a8c9 +Subproject commit 2be1731911bf2a207b963ac79656f626e09eac6f diff --git a/modules/github b/modules/github index 93337f4..e9e9089 160000 --- a/modules/github +++ b/modules/github @@ -1 +1 @@ -Subproject commit 93337f4ddf6b9cfa28f2972b4ac893b672d3227e +Subproject commit e9e9089f282b0455a481460ebec17a4672617ceb diff --git a/modules/quotes/commands.js b/modules/quotes/commands.js index ef90295..e770309 100644 --- a/modules/quotes/commands.js +++ b/modules/quotes/commands.js @@ -80,9 +80,7 @@ var commands = function(dbot) { }); }, - /*** Quote Removal - TODO: Remove empty quote categories - ***/ + /*** Quote Removal ***/ // Show number of quotes in removal cache '~rmstatus': function(event) { @@ -125,20 +123,26 @@ var commands = function(dbot) { '~rmlast': function(event) { if(this.rmAllowed === true || _.include(dbot.config.admins, event.user)) { var key = event.input[1].trim().toLowerCase(), - category = false; + category = false, + removedQuote; + var quoteRemoved = function(err) { + this.internalAPI.resetRemoveTimer(event, key, removedQuote); + event.reply(dbot.t('removed_from', { + 'quote': removedQuote, + 'category': key + })); + }.bind(this); this.db.search('quote_category', { 'name': key }, function(result) { category = result; }, function(err) { if(category) { - var removedQuote = category.quotes.pop(); - this.db.save('quote_category', category.id, category, function(err) { - this.internalAPI.resetRemoveTimer(event, key, removedQuote); - event.reply(dbot.t('removed_from', { - 'quote': removedQuote, - 'category': key - })); - }.bind(this)); + removedQuote = category.quotes.pop(); + if(category.quotes.length == 0) { + this.db.del('quote_category', category.id, quoteRemoved); + } else { + this.db.save('quote_category', category.id, category, quoteRemoved); + } } else { event.reply(dbot.t('category_not_found', { 'category': key })); } @@ -154,6 +158,13 @@ var commands = function(dbot) { var key = event.input[1].trim().toLowerCase(); quote = event.input[2], category = false; + var quoteRemoved = function(err) { + this.internalAPI.resetRemoveTimer(event, key, quote); + event.reply(dbot.t('removed_from', { + 'category': key, + 'quote': quote + })); + }.bind(this); this.db.search('quote_category', { 'name': key }, function(result) { category = result; @@ -161,13 +172,11 @@ var commands = function(dbot) { if(category) { if(category.quotes.indexOf(quote) != -1) { category.quotes = _.without(category.quotes, quote); - this.db.save('quote_category', category.id, category, function(err) { - this.internalAPI.resetRemoveTimer(event, key, quote); - event.reply(dbot.t('removed_from', { - 'category': key, - 'quote': quote - })); - }.bind(this)); + if(category.quotes.length == 0) { + this.db.del('quote_category', category.id, quoteRemoved); + } else { + this.db.save('quote_category', category.id, category, quoteRemoved); + } } else { event.reply(dbot.t('q_not_exist_under', { 'category': key, diff --git a/modules/stats b/modules/stats index eee5861..e5519f3 160000 --- a/modules/stats +++ b/modules/stats @@ -1 +1 @@ -Subproject commit eee5861dca00f0d2b2f146820870abb888ed8f4a +Subproject commit e5519f353abf00e4ec25702f8e02231c9b1f5258