Small changes, reply to some things

This commit is contained in:
Daniel Odendahl Jr
2017-10-24 19:02:27 +00:00
parent e0594c8749
commit c225ea4659
141 changed files with 251 additions and 254 deletions
+1 -3
View File
@@ -28,15 +28,13 @@ module.exports = class AnagramCommand extends Command {
async run(msg, { word, strict }) {
try {
const { body } = await snekfetch.get(`http://www.anagramica.com/best/${word}`);
if (!body.best.length) return msg.say('Could not find any results.');
const all = body.best.filter(anagram => anagram.toLowerCase() !== word);
if (!all.length) return msg.say('Could not find any results.');
const words = strict ? all.filter(anagram => anagram.length === word.length) : all;
if (!words.length) return msg.say('Could not find any results.');
return msg.say(words[Math.floor(Math.random() * words.length)]);
} catch (err) {
if (err.status === 500) return msg.say('Could not find any results.');
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};