3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-24 19:52:36 +01:00

fix the quote/command correct order thing

This commit is contained in:
reality 2013-08-17 18:13:38 +00:00
parent 52d38aa1e7
commit 6fb7c8e91f
3 changed files with 37 additions and 32 deletions

View File

@ -16,28 +16,44 @@ var command = function(dbot) {
return; return;
} }
if(!_.has(dbot.commands, commandName)) { if(!_.has(dbot.commands, commandName)) {
if(_.has(dbot.modules, 'spelling')) { if(_.has(dbot.modules, 'quotes')) {
var commands = _.keys(dbot.commands) var key = event.message.substring(1);
winner = false, dbot.api.quotes.getInterpolatedQuote(event.server, event.channel.name, key, function(quote) {
closestMatch = Infinity; if(quote) {
event.reply(key + ': ' + quote);
} else if(_.has(dbot.modules, 'spelling')) {
var commands = _.keys(dbot.commands)
winner = false,
closestMatch = Infinity;
_.each(commands, function(command) { _.each(commands, function(command) {
var distance = dbot.api.spelling.distance(commandName, command); var distance = dbot.api.spelling.distance(commandName, command);
if(distance < closestMatch) { if(distance < closestMatch) {
closestMatch = distance; closestMatch = distance;
winner = command; winner = command;
}
});
if(closestMatch < 3) {
event.reply(commandName + ' not found. Did you mean ' + winner + '?');
return;
} else if(_.has(dbot.modules, 'quotes')) {
dbot.api.link.udLookup(key, function(word, definition) {
if(word) {
event.reply(key + '[UD]: ' + definition);
} else {
event.reply(dbot.t('category_not_found', { 'category': key }));
}
});
} else {
return;
}
} }
}); });
return;
}
if(closestMatch < 3) { else if(_.has(dbot.modules, 'quotes')) {
event.reply(commandName + ' not found. Did you mean ' + winner + '?');
return;
} else if(_.has(dbot.modules, 'quotes')) {
commandName = '~';
} else {
return;
}
} else if(_.has(dbot.modules, 'quotes')) {
commandName = '~'; commandName = '~';
} else { } else {
return; return;

View File

@ -38,17 +38,7 @@ var commands = function(dbot) {
if(quote) { if(quote) {
event.reply(key + ': ' + quote); event.reply(key + ': ' + quote);
} else { } else {
if(this.config.udFallback === true && _.has(dbot.modules, 'link')) { event.reply(dbot.t('category_not_found', { 'category': key }));
dbot.api.link.udLookup(key, function(word, definition) {
if(word) {
event.reply(key + '[UD]: ' + definition);
} else {
event.reply(dbot.t('category_not_found', { 'category': key }));
}
});
} else {
event.reply(dbot.t('category_not_found', { 'category': key }));
}
} }
}.bind(this)); }.bind(this));
}, },

View File

@ -3,6 +3,5 @@
"dependencies": [ "users", "event" ], "dependencies": [ "users", "event" ],
"rmLimit": 10, "rmLimit": 10,
"ignorable": true, "ignorable": true,
"quotesOnJoin": false, "quotesOnJoin": false
"udFallback": false
} }