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
+1 -2
View File
@@ -1,6 +1,5 @@
{
"banned": {
"155112606661607425": "155112606661607425",
"242699360352206850": "242699360352206850"
"155112606661607425": "155112606661607425"
}
}
+7 -1
View File
@@ -12,7 +12,13 @@ module.exports = class TypingGameCommand extends commando.Command {
args: [{
key: 'difficulty',
prompt: 'What difficulty should the typing game be? Easy, Medium, Hard, or Extreme?',
type: 'string'
type: 'string',
validate: difficulty => {
if (difficulty.toLowerCase() === 'easy' || difficulty.toLowerCase() === 'medium' || difficulty.toLowerCase() === 'hard' || difficulty.toLowerCase() === 'extreme') {
return true;
}
return 'Please set the difficulty to either `easy`, `medium`, `hard`, or `extreme`.';
}
}]
});
}
+14 -4
View File
@@ -112,11 +112,23 @@ module.exports = class MemeCommand extends commando.Command {
args: [{
key: 'type',
prompt: 'What meme type do you want to use?',
type: 'string'
type: 'string',
validate: type => {
if (memecodes[type.toLowerCase()] || type.toLowerCase() === 'list') {
return true;
}
return 'Please enter a valid meme type. Enter `list` to view a list of types.';
}
}, {
key: 'content',
prompt: 'What should the meme content be?',
type: 'string'
type: 'string',
validate: content => {
if (content.includes(' | ') && content.match(/^[a-zA-Z0-9|.,!?'-\s]+$/)) {
return true;
}
return 'Please split your choices with ` | ` and do not use special characters.';
}
}]
});
}
@@ -127,9 +139,7 @@ module.exports = class MemeCommand extends commando.Command {
}
console.log(`[Command] ${message.content}`);
let type = args.type.toLowerCase();
if (!memecodes[type] || type !== 'list') return message.channel.send(':x: Error! Meme type not found! Use `;meme list` to view a list of meme types.');
let content = args.content;
if (!content.includes(' | ') || !content.match(/^[a-zA-Z0-9|.,!?'-\s]+$/)) return message.channel.send(':x: Error! Invalid content! Split your choices with a " | " or do not use special characters!');
if (type === "list") return message.channel.send("**Type Codes:** tenguy, afraid, older, aag, tried, biw, blb, kermit, bd, ch, cbg, wonka, cb, keanu, dsm, live, ants, doge, alwaysonbeat, ermg, facepalm, fwp, fa, fbf, fry, hipster, icanhas, crazypills, mw, noidea, regret, boat, hagrid, sohappy, captain, inigo, iw, ackbar, happening, joker, ive, ll, morpheus, mb, badchoice, mmm, jetpack, red, mordor, oprah, oag, remembers, philosoraptor, jw, patrick, rollsafe, sad-obama, sad-clinton, sadfrog, sad-bush, sad-biden, sad-boehner, saltbae, sarcasticbear, dwight, sb, ss, sf, dodgson, money, sohot, nice, awesome-awkward, awesome, awkward-awesome, awkward, fetch, success, scc, ski, officespace, interesting, toohigh, bs, center, both, winter, xy, buzz, yodawg, uno, yallgot, bad, elf, chosen");
let memeQuery = content.split(" ").join("-").split("-|-");
let toprow = memeQuery[0].split("?").join("~q");
+7 -2
View File
@@ -12,7 +12,13 @@ module.exports = class RomanCommand extends commando.Command {
args: [{
key: 'number',
prompt: 'What do you want to convert to Roman?',
type: 'integer'
type: 'integer',
validate: number => {
if (number > 1000000) {
return 'Please enter a number below one million.';
}
return true;
}
}]
});
}
@@ -24,7 +30,6 @@ module.exports = class RomanCommand extends commando.Command {
console.log(`[Command] ${message.content}`);
let numberToRoman = args.number;
let romanInterger = numberToRoman;
if (romanInterger > 1000000) return message.channel.send(':x: Error! Number is too high!');
return message.channel.send(romanNumeralConverter.getRomanFromInteger(romanInterger));
}
};
+8 -3
View File
@@ -17,7 +17,13 @@ module.exports = class SoundBoardCommand extends commando.Command {
args: [{
key: 'sound',
prompt: 'What sound do you want me to play?',
type: 'string'
type: 'string',
validate: sound => {
if (sound.avaliable[sound.toLowerCase()] || sound.toLowerCase() === 'list') {
return true;
}
return 'Sound not found. Enter `list` to view a list of sounds.';
}
}]
});
}
@@ -29,9 +35,8 @@ module.exports = class SoundBoardCommand extends commando.Command {
console.log(`[Command] ${message.content}`);
let voiceChannel = message.member.voiceChannel;
if (!voiceChannel) return message.channel.send(`:x: Error! Please be in a voice channel first!`);
let soundToPlay = args.sound;
let soundToPlay = args.sound.toLowerCase();
if (soundToPlay === 'list') return message.channel.send("**Available Sounds:** Cat, Pikachu, Vader, Doh, It's a Trap, Mario Death, Pokemon Center, Dun Dun Dun, Spongebob, Ugly Barnacle, Woo Hoo, Space, GLaDOS Bird, Airhorn, Zelda Chest, Eat my Shorts, No This is Patrick, Wumbo");
if (soundToPlay !== sounds.avaliable[soundToPlay]) return message.channel.send(':x: Error! Sound not found! Use `;soundboard list` to see a list of sounds you can play.');
let alreadyConnected = await this.client.voiceConnections.get(voiceChannel.guild.id);
if (alreadyConnected) {
if (alreadyConnected.channel.id === voiceChannel.id) return message.channel.send(':x: Error! I am already playing a sound!');
+7 -1
View File
@@ -14,7 +14,13 @@ module.exports = class ChooseCommand extends commando.Command {
args: [{
key: 'choices',
prompt: 'What choices do you want me pick from? Split them with " | "!',
type: 'string'
type: 'string',
validate: content => {
if (content.includes(' | ')) {
return true;
}
return 'Please split your choices with ` | `.';
}
}]
});
}
+7 -4
View File
@@ -15,7 +15,13 @@ module.exports = class RandomNameGen extends commando.Command {
args: [{
key: 'gender',
prompt: 'Which gender do you want to generate a name for?',
type: 'string'
type: 'string',
validate: gender => {
if (gender.toLowerCase() === 'male' || gender.toLowerCase() === 'female') {
return true;
}
return 'Please enter either `male` or `female`.';
}
}]
});
}
@@ -38,8 +44,5 @@ module.exports = class RandomNameGen extends commando.Command {
else if (gender === "female") {
return message.channel.send(`${randomFirstFemale} ${randomLast}`);
}
else {
return message.channel.send(':x: Error! Please set either male or female!');
}
}
};
+7 -1
View File
@@ -18,7 +18,13 @@ module.exports = class BotSearchCommand extends commando.Command {
args: [{
key: 'bot',
prompt: 'Which bot do you want to get information for?',
type: 'user'
type: 'user',
validate: user => {
if (user.bot) {
return true;
}
return 'Please mention a bot account, not a user account.';
}
}]
});
}
+7 -2
View File
@@ -16,7 +16,13 @@ module.exports = class DiscrimCommand extends commando.Command {
args: [{
key: 'discrim',
prompt: 'Which discriminator would you like to search for?',
type: 'string'
type: 'string',
validate: discrim => {
if (discrim.match(/^[0-9]+$/) || discrim.length === 4) {
return true;
}
return 'Invalid discriminator.';
}
}]
});
}
@@ -27,7 +33,6 @@ module.exports = class DiscrimCommand extends commando.Command {
}
console.log(`[Command] ${message.content}`);
let userToSearch = args.discrim;
if (!userToSearch.match(/^[0-9]+$/) || userToSearch.length !== 4) return message.channel.send(':x: Error! Invalid Discriminator!');
let users = await this.client.users.filter(u => u.discriminator === userToSearch).map(u => u.username).sort();
const embed = new Discord.RichEmbed()
.setTitle(`${users.length} Users with the discriminator: ${userToSearch}`)
+8 -3
View File
@@ -16,7 +16,13 @@ module.exports = class PokedexCommand extends commando.Command {
args: [{
key: 'pokemon',
prompt: 'What Pokémon would you like to get info on?',
type: 'string'
type: 'string',
validate: pokemon => {
if (pokedex.name[pokemon.toLowerCase()]) {
return true;
}
return 'Please enter a valid Pokémon from either Kanto or Johto.';
}
}]
});
}
@@ -26,8 +32,7 @@ module.exports = class PokedexCommand extends commando.Command {
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES', 'EMBED_LINKS'])) return;
}
console.log(`[Command] ${message.content}`);
let pokemon = args.pokemon;
if (!pokedex.name[pokemon.toLowerCase()]) return message.channel.send(':x: Error! This Pokémon is either not valid, or is not yet implemented!');
let pokemon = args.pokemon.toLowerCase();
const embed = new Discord.RichEmbed()
.setTitle('Information')
.setAuthor(`#${pokedex.index[pokemon]} ${pokedex.name[pokemon]}`, `http://www.serebii.net/pokedex-sm/icon/${pokedex.index[pokemon]}.png`)
+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