3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-30 16:09:27 +01:00

Automatically replace spaces in quotes with underscores, then use that quote if the originally given quote can't be found

This commit is contained in:
Luke Slater 2012-06-15 10:52:11 +01:00
parent 333e3c592d
commit b9b5d9913d

View File

@ -41,8 +41,15 @@ var quotes = function(dbot) {
// Retrieve quote from a category in the database. // Retrieve quote from a category in the database.
'~q': function(event) { '~q': function(event) {
var key = event.input[1].trim().toLowerCase(); var key = event.input[1].trim().toLowerCase();
var altKey;
if(key.split(' ').length > 0) {
altKey = key.replace(/ /g, '_');
}
if(quotes.hasOwnProperty(key)) { if(quotes.hasOwnProperty(key)) {
event.reply(key + ': ' + interpolatedQuote(key)); event.reply(key + ': ' + interpolatedQuote(key));
} else if(quotes.hasOwnProperty(altKey)) {
event.reply(key + ': ' + interpolatedQuote(altKey));
} else { } else {
event.reply(dbot.t('category_not_found', {'category': key})); event.reply(dbot.t('category_not_found', {'category': key}));
} }