mirror of
https://github.com/reality/dbot.git
synced 2024-12-25 04:02:39 +01:00
Some cleanup of quotes module postdatabank [#331] Addition of addQuote API and updated places what use it [#349]
This commit is contained in:
parent
f17f926a3b
commit
aad0b5e372
@ -3,33 +3,15 @@ var _ = require('underscore')._,
|
|||||||
uuid = require('node-uuid');
|
uuid = require('node-uuid');
|
||||||
|
|
||||||
var commands = function(dbot) {
|
var commands = function(dbot) {
|
||||||
var quotes = dbot.db.quoteArrs;
|
|
||||||
var commands = {
|
var commands = {
|
||||||
/*** Quote Addition ***/
|
/*** Quote Addition ***/
|
||||||
|
|
||||||
// Add a quote to a category
|
// Add a quote to a category
|
||||||
'~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,
|
|
||||||
category = false;
|
|
||||||
|
|
||||||
this.db.search('quote_category', { 'name': key }, function(result) {
|
this.api.addQuote(key, quote, event.user, function(newCount) {
|
||||||
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', {
|
dbot.api.event.emit('~qadd', {
|
||||||
'key': key,
|
'key': key,
|
||||||
'text': quote
|
'text': quote
|
||||||
@ -39,7 +21,6 @@ var commands = function(dbot) {
|
|||||||
'count': newCount
|
'count': newCount
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
}.bind(this));
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/*** Quote Retrieval ***/
|
/*** Quote Retrieval ***/
|
||||||
@ -102,10 +83,7 @@ var commands = function(dbot) {
|
|||||||
var rmCacheCount = rmCache.length;
|
var rmCacheCount = rmCache.length;
|
||||||
|
|
||||||
_.each(rmCache, function(quote, index) {
|
_.each(rmCache, function(quote, index) {
|
||||||
//TODO: Add quote add API func
|
this.api.addQuote(quote.key, quote.quote, event.user, function(newCount) { });
|
||||||
var qadd = _.clone(event);
|
|
||||||
qadd.message = '~qadd ' + quote.key + '=' + quote.quote;
|
|
||||||
dbot.instance.emit(qadd);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
rmCache.length = 0;
|
rmCache.length = 0;
|
||||||
@ -233,7 +211,6 @@ var commands = function(dbot) {
|
|||||||
}
|
}
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
if(matches.length > 0) {
|
if(matches.length > 0) {
|
||||||
console.log(matches);
|
|
||||||
event.reply(dbot.t('search_results', {
|
event.reply(dbot.t('search_results', {
|
||||||
'category': matches[0].category,
|
'category': matches[0].category,
|
||||||
'needle': needle,
|
'needle': needle,
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
var _ = require('underscore')._;
|
var _ = require('underscore')._,
|
||||||
|
uuid = require('node-uuid');
|
||||||
|
|
||||||
var quotes = function(dbot) {
|
var quotes = function(dbot) {
|
||||||
dbot.sessionData.rmCache = [];
|
dbot.sessionData.rmCache = [];
|
||||||
this.quotes = dbot.db.quoteArrs,
|
this.rmCache = dbot.sessionData.rmCache;
|
||||||
this.addStack = [],
|
this.quotes = dbot.db.quoteArrs;
|
||||||
this.rmAllowed = true,
|
this.rmAllowed = true;
|
||||||
this.rmCache = dbot.sessionData.rmCache,
|
|
||||||
this.rmTimer;
|
this.rmTimer;
|
||||||
|
|
||||||
this.internalAPI = {
|
this.internalAPI = {
|
||||||
'interpolatedQuote': function(server, channel, key, quote, callback) {
|
|
||||||
// Parse quote interpolations
|
// Parse quote interpolations
|
||||||
|
'interpolatedQuote': function(server, channel, key, quote, callback) {
|
||||||
var quoteRefs = quote.match(/~~([\d\w\s-]*)~~/g);
|
var quoteRefs = quote.match(/~~([\d\w\s-]*)~~/g);
|
||||||
if(quoteRefs) {
|
if(quoteRefs) {
|
||||||
var ref = dbot.cleanNick(quoteRefs[0].replace(/^~~/,'').replace(/~~$/,'').trim());
|
var ref = dbot.cleanNick(quoteRefs[0].replace(/^~~/,'').replace(/~~$/,'').trim());
|
||||||
@ -58,9 +58,36 @@ var quotes = function(dbot) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.api = {
|
this.api = {
|
||||||
|
'addQuote': function(key, quote, user, callback) {
|
||||||
|
var key = key.toLowerCase().trim(),
|
||||||
|
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': [],
|
||||||
|
'owner': user
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
newCount = category.quotes.push(quote);
|
||||||
|
this.db.save('quote_category', category.id, category, function(err) {
|
||||||
|
this.rmAllowed = true;
|
||||||
|
callback(newCount);
|
||||||
|
}.bind(this));
|
||||||
|
}.bind(this));
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
'getQuote': function(key, callback) {
|
'getQuote': function(key, callback) {
|
||||||
var category = false;
|
var category = false,
|
||||||
key = key.trim().toLowerCase(),
|
key = key.trim().toLowerCase();
|
||||||
|
|
||||||
this.db.search('quote_category', { 'name': key }, function(result) {
|
this.db.search('quote_category', { 'name': key }, function(result) {
|
||||||
category = result;
|
category = result;
|
||||||
@ -93,13 +120,12 @@ var quotes = function(dbot) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(once) {
|
if(once) {
|
||||||
event.message = '~qadd realityonce=reality ' + once[1];
|
this.api.addQuote('realityonce', 'reality' + once[1], event.user, function(newCount) {
|
||||||
event.action = 'PRIVMSG';
|
event.reply('\'reality ' + once[1] + '\' saved (' + newCount + ').');
|
||||||
event.params = event.message.split(' ');
|
});
|
||||||
dbot.instance.emit(event);
|
|
||||||
}
|
}
|
||||||
} else if(event.action == 'JOIN') {
|
} else if(event.action == 'JOIN') {
|
||||||
var userQuote = this.api.getQuote(event.user, function(quote) {
|
var userQuote = this.api.addQuote(event.user, function(quote) {
|
||||||
if(quote) {
|
if(quote) {
|
||||||
event.reply(event.user + ': ' + quote);
|
event.reply(event.user + ': ' + quote);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user