3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-23 20:39:25 +01:00

dont add quotes that already exist [#331]

This commit is contained in:
reality 2013-04-22 15:50:05 +00:00
parent f905c58877
commit 099d278cbc
2 changed files with 18 additions and 10 deletions

View File

@ -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'));
}
});
},

View File

@ -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));
},