forked from GitHub/dbot
~qsearch can search all categories with * [#331]
This commit is contained in:
parent
b1f450a3e1
commit
f17f926a3b
@ -218,6 +218,33 @@ var commands = function(dbot) {
|
||||
needle = event.input[2],
|
||||
category = false;
|
||||
|
||||
if(haystack == '*') {
|
||||
var matches = [];
|
||||
this.db.scan('quote_category', function(category) {
|
||||
if(category) {
|
||||
var theseMatches =_.each(category.quotes, function(quote) {
|
||||
if(quote.indexOf(needle) != -1) {
|
||||
matches.push({
|
||||
'category': category.name,
|
||||
'quote': quote
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}, function(err) {
|
||||
if(matches.length > 0) {
|
||||
console.log(matches);
|
||||
event.reply(dbot.t('search_results', {
|
||||
'category': matches[0].category,
|
||||
'needle': needle,
|
||||
'quote': matches[0].quote,
|
||||
'matches': matches.length
|
||||
}));
|
||||
} else {
|
||||
event.reply(dbot.t('no_results'));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.db.search('quote_category', { 'name': haystack }, function(result) {
|
||||
category = result;
|
||||
}, function(err) {
|
||||
@ -240,6 +267,7 @@ var commands = function(dbot) {
|
||||
event.reply(dbot.t('empty_category'));
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// Count quotes in a given category or total quotes overall
|
||||
@ -365,7 +393,7 @@ var commands = function(dbot) {
|
||||
|
||||
commands['~'].regex = [/^~([\d\w\s-]*)/, 2];
|
||||
commands['~q'].regex = [/^~q ([\d\w\s-]*)/, 2];
|
||||
commands['~qsearch'].regex = [/^~qsearch ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3];
|
||||
commands['~qsearch'].regex = [/^~qsearch ([\d\w\s*-]+?)[ ]?=[ ]?(.+)$/, 3];
|
||||
commands['~rm'].regex = [/^~rm ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3];
|
||||
commands['~rmlast'].regex = [/^~rmlast ([\d\w\s-]*)/, 2];
|
||||
commands['~qadd'].regex = [/^~qadd ([\d\w-]+[\d\w\s-]*)[ ]?=[ ]?(.+)$/, 3];
|
||||
|
Loading…
Reference in New Issue
Block a user