3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-24 19:52:36 +01:00

~qadd uses only save rather than save|create [#331]

This commit is contained in:
reality 2013-04-12 17:33:13 +00:00
parent 23dace4257
commit 58b58aa15f

View File

@ -11,8 +11,24 @@ var commands = function(dbot) {
'~qadd': function(event) {
var key = event.input[1].toLowerCase().trim(),
quote = event.input[2],
newCount;
var quoteAdded = function(err, result) {
newCount,
category = false;
this.db.search('quote_category', { 'name': key }, function(result) {
category = result;
}, function(err) {
if(!category) {
var id = uuid.v4();
category = {
'id': id,
'name': key,
'quotes': [],
'creator': event.user
};
}
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,
@ -22,25 +38,7 @@ var commands = function(dbot) {
'category': key,
'count': newCount
}));
}.bind(this);
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, {
'id': id,
'name': key,
'quotes': [ quote ],
'creator': event.user
}, quoteAdded);
} else {
newCount = category.quotes.push(quote);
this.db.save('quote_category', category.id, category, quoteAdded);
}
});
}.bind(this));
},