3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-27 14:29:29 +01:00

Empty quote category records are now removed [#331][#346]

This commit is contained in:
reality 2013-04-12 19:28:23 +00:00
parent 5892bd83aa
commit 7ceba078e2
4 changed files with 31 additions and 22 deletions

2
jsbot

@ -1 +1 @@
Subproject commit 84a4783db76bdd729bd720c43485893ebe78a8c9
Subproject commit 2be1731911bf2a207b963ac79656f626e09eac6f

@ -1 +1 @@
Subproject commit 93337f4ddf6b9cfa28f2972b4ac893b672d3227e
Subproject commit e9e9089f282b0455a481460ebec17a4672617ceb

View File

@ -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,

@ -1 +1 @@
Subproject commit eee5861dca00f0d2b2f146820870abb888ed8f4a
Subproject commit e5519f353abf00e4ec25702f8e02231c9b1f5258