mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-20 05:51:35 +02:00
args and more
This commit is contained in:
+18
-16
@@ -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?'));
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user