Validators Added for all Commands

This commit is contained in:
Daniel Odendahl Jr
2017-03-25 06:43:03 +00:00
parent f6af93dee4
commit be79696113
13 changed files with 109 additions and 35 deletions
+14 -5
View File
@@ -15,7 +15,13 @@ module.exports = class MorseCommand extends commando.Command {
args: [{
key: 'method',
prompt: 'Would you like to encode or decode the text?',
type: 'string'
type: 'string',
validate: method => {
if (method.toLowerCase() === 'encode' || method.toLowerCase() === 'decode') {
return true;
}
return 'Please enter either `encode` or `decode`.'
}
}, {
key: 'text',
prompt: 'What text would you like to convert to morse?',
@@ -29,10 +35,13 @@ module.exports = class MorseCommand extends commando.Command {
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
}
console.log(`[Command] ${message.content}`);
let methodToUse = args.method;
if (methodToUse.toLowerCase() !== 'encode' || methodToUse.toLowerCase() !== 'decode') return message.channel.send(':x: Error! Please set either encode or decode!');
let methodToUse = args.method.toLowerCase();
let toMorse = args.text;
if (methodToUse === 'encode') return message.channel.send(morse.encode(toMorse)).catch(error => message.channel.send(':x: Error! Something went wrong! Perhaps you entered incorrect text?'));
if (methodToUse === 'decode') return message.channel.send(morse.decode(toMorse)).catch(error => message.channel.send(':x: Error! Something went wrong! Perhaps you entered incorrect text?'));
if (methodToUse === 'encode') {
return message.channel.send(morse.encode(toMorse)).catch(error => message.channel.send(':x: Error! Something went wrong! Perhaps you entered incorrect text?'));
}
else if (methodToUse === 'decode') {
return message.channel.send(morse.decode(toMorse)).catch(error => message.channel.send(':x: Error! Something went wrong! Perhaps you entered incorrect text?'));
}
}
};