args and more

This commit is contained in:
Daniel Odendahl Jr
2017-03-25 04:16:27 +00:00
parent 8dd6ec1f9b
commit e2a4a92990
82 changed files with 1089 additions and 1021 deletions
+18 -16
View File
@@ -11,28 +11,30 @@ module.exports = class MorseCommand extends commando.Command {
group: 'textedit',
memberName: 'morse',
description: 'Translates text to and from morse code. (;morse encode This is Morse Code.)',
examples: [';morse encode This is Morse Code.', ';morse decode .... . .-.. .-.. --- --..-- ....... .-- --- .-. .-.. -.. .-.-.-']
examples: [';morse encode This is Morse Code.', ';morse decode .... . .-.. .-.. --- --..-- ....... .-- --- .-. .-.. -.. .-.-.-'],
args: [{
key: 'method',
prompt: 'Would you like to encode or decode the text?',
type: 'string',
validate: (str) => {
str.toLowerCase() === 'encode' || str.toLowerCase() === 'decode';
}
}, {
key: 'text',
prompt: 'What text would you like to convert to morse?',
type: 'string'
}]
});
}
run(message) {
run(message, args) {
if (message.channel.type !== 'dm') {
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
}
console.log(`[Command] ${message.content}`);
let [methodToUse] = message.content.toLowerCase().split(" ").slice(1);
let toMorse = message.content.split(" ").slice(2).join(" ");
if (!toMorse) {
return message.channel.send(":x: Error! Nothing to translate! Perhaps you forgot to set the method? Use either encode or decode before your text.");
}
else 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?'));
}
else {
return message.channel.send(":x: Error! Method not set/not correct! Use either encode or decode.");
}
let methodToUse = args.method;
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?'));
}
};