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:
parent
23dace4257
commit
58b58aa15f
@ -11,36 +11,34 @@ var commands = function(dbot) {
|
|||||||
'~qadd': function(event) {
|
'~qadd': function(event) {
|
||||||
var key = event.input[1].toLowerCase().trim(),
|
var key = event.input[1].toLowerCase().trim(),
|
||||||
quote = event.input[2],
|
quote = event.input[2],
|
||||||
newCount;
|
newCount,
|
||||||
var quoteAdded = function(err, result) {
|
category = false;
|
||||||
this.rmAllowed = true;
|
|
||||||
dbot.api.event.emit('~qadd', {
|
|
||||||
'key': key,
|
|
||||||
'text': quote
|
|
||||||
});
|
|
||||||
event.reply(dbot.t('quote_saved', {
|
|
||||||
'category': key,
|
|
||||||
'count': newCount
|
|
||||||
}));
|
|
||||||
}.bind(this);
|
|
||||||
|
|
||||||
var category = false;
|
|
||||||
this.db.search('quote_category', { 'name': key }, function(result) {
|
this.db.search('quote_category', { 'name': key }, function(result) {
|
||||||
category = result;
|
category = result;
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
if(!category) {
|
if(!category) {
|
||||||
var id = uuid.v4();
|
var id = uuid.v4();
|
||||||
newCount = 1;
|
category = {
|
||||||
this.db.create('quote_category', id, {
|
|
||||||
'id': id,
|
'id': id,
|
||||||
'name': key,
|
'name': key,
|
||||||
'quotes': [ quote ],
|
'quotes': [],
|
||||||
'creator': event.user
|
'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));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user