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