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?'));
}
}
};
+7 -2
View File
@@ -15,7 +15,13 @@ module.exports = class RomajiCommand extends commando.Command {
args: [{
key: 'kana',
prompt: 'What kana would you like to convert to romaji?',
type: 'string'
type: 'string',
validate: kana => {
if (hepburn.containsKana(kana)) {
return true;
}
return 'Please enter text in either Hiragana or Katakana.';
}
}]
});
}
@@ -26,7 +32,6 @@ module.exports = class RomajiCommand extends commando.Command {
}
console.log(`[Command] ${message.content}`);
let romajify = args.kana;
if (!hepburn.containsKana(romajify)) return message.channel.send(':x: Error! Message contains no Katakana or Hiragana!');
let romajified = hepburn.fromKana(romajify);
if (romajified.length > 1950) return message.channel.send(":x: Error! Your message is too long!");
return message.channel.send(romajified);
+15 -5
View File
@@ -120,11 +120,23 @@ module.exports = class TranslateCommand extends commando.Command {
args: [{
key: 'to',
prompt: 'What language would you like to translate to?',
type: 'string'
type: 'string',
validate: to => {
if (languages[to.toLowerCase()] || to.toLowerCase() === 'list') {
return true;
}
return 'Please enter a valid language code. Enter `list` for a list of codes.';
}
}, {
key: 'text',
prompt: 'What text would you like to translate?',
type: 'string'
type: 'string',
validate: content => {
if (content.length > 200) {
return 'Please keep translation queries under 200 characters.';
}
return true;
}
}]
});
}
@@ -134,11 +146,9 @@ module.exports = class TranslateCommand extends commando.Command {
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES', 'EMBED_LINKS'])) return;
}
console.log(`[Command] ${message.content}`);
let languageto = args.to;
if (!languages[languageto] || languageto.toLowerCase() !== 'list') return message.channel.send(':x: Error! Translation type is not valid!');
let languageto = args.to.toLowerCase();
let thingToTranslate = args.text;
if (languageto === "list") return message.channel.send("af': 'Afrikaans\nsq': 'Albanian'\n'ar': 'Arabic\nhy': 'Armenian\naz': 'Azerbaijani\neu': 'Basque\nbe': 'Belarusian\nbn': 'Bengali\nbs': 'Bosnian\nbg': 'Bulgarian\nca': 'Catalan\nceb': 'Cebuano\nny': 'Chichewa\nzh-cn': 'Chinese Simplified\nzh-tw': 'Chinese Traditional\nco': 'Corsican\nhr': 'Croatian\ncs': 'Czech\nda': 'Danish\nnl': 'Dutch\nen': 'English\neo': 'Esperanto\net': 'Estonian\ntl': 'Filipino\nfi': 'Finnish\nfr': 'French\nfy': 'Frisian\ngl': 'Galician\nka': 'Georgian\nde': 'German\nel': 'Greek\ngu': 'Gujarati\nht': 'Haitian Creole\nha': 'Hausa\nhaw': 'Hawaiian\niw': 'Hebrew\nhi': 'Hindi\nhmn': 'Hmong\nhu': 'Hungarian\nis': 'Icelandic\nig': 'Igbo\nid': 'Indonesian\nga': 'Irish\nit': 'Italian\nja': 'Japanese\njw': 'Javanese\nkn': 'Kannada\nkk': 'Kazakh\nkm': 'Khmer\nko': 'Korean\nku': 'Kurdish (Kurmanji)\nky': 'Kyrgyz\nlo': 'Lao\nla': 'Latin\nlv': 'Latvian\nlt': 'Lithuanian\nlb': 'Luxembourgish\nmk': 'Macedonian\nmg': 'Malagasy\nms': 'Malay\nml': 'Malayalam\nmt': 'Maltese\nmi': 'Maori\nmr': 'Marathi\nmn': 'Mongolian\nmy': 'Myanmar (Burmese)\nne': 'Nepali\nno': 'Norwegian\nps': 'Pashto\nfa': 'Persian\npl': 'Polish\npt': 'Portuguese\nma': 'Punjabi\nro': 'Romanian\nru': 'Russian\nsm': 'Samoan\ngd': 'Scots Gaelic\nsr': 'Serbian\nst': 'Sesotho\nsn': 'Shona\nsd': 'Sindhi\nsi': 'Sinhala\nsk': 'Slovak\nsl': 'Slovenian\nso': 'Somali\nes': 'Spanish\nsu': 'Sudanese\nsw': 'Swahili\nsv': 'Swedish\ntg': 'Tajik\nta': 'Tamil\nte': 'Telugu\nth': 'Thai\ntr': 'Turkish\nuk': 'Ukrainian\nur': 'Urdu\nuz': 'Uzbek\nvi': 'Vietnamese\ncy': 'Welsh\nxh': 'Xhosa\nyi': 'Yiddish\nyo': 'Yoruba\nzu': 'Zulu'");
if (thingToTranslate.length > 200) return message.channel.send(":x: Error! Please keep translations below 200 characters!");
try {
let res = await translate(thingToTranslate, {
to: languageto