From cb4abd7ac49014ede545b3b0ef2d50bc17c2fcf3 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Sat, 25 Mar 2017 04:52:59 +0000 Subject: [PATCH] Fix All the Crap --- commands/games/mathgame.js | 8 +++----- commands/games/rockpaperscissors.js | 6 ++---- commands/games/typinggame.js | 8 +++----- commands/imageedit/meme.js | 14 +++++--------- commands/response/choose.js | 4 +++- commands/response/name.js | 8 ++++---- commands/search/discrim.js | 6 ++---- commands/search/pokedex.js | 6 ++---- commands/textedit/morse.js | 6 ++---- commands/textedit/romaji.js | 6 ++---- commands/textedit/translate.js | 6 ++---- index.js | 23 ++++++++++++----------- 12 files changed, 42 insertions(+), 59 deletions(-) diff --git a/commands/games/mathgame.js b/commands/games/mathgame.js index 19625953..f0b78e08 100644 --- a/commands/games/mathgame.js +++ b/commands/games/mathgame.js @@ -13,10 +13,7 @@ module.exports = class MathGameCommand extends commando.Command { args: [{ key: 'difficulty', prompt: 'What difficulty should the math game be? Easy, Medium, Hard, or Extreme?', - type: 'string', - validate: (str) => { - str.toLowerCase() === 'easy' || str.toLowerCase() === 'medium' || str.toLowerCase() === 'hard' || str.toLowerCase() === 'extreme'; - } + type: 'string' }] }); } @@ -26,7 +23,8 @@ module.exports = class MathGameCommand extends commando.Command { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES', 'EMBED_LINKS'])) return; } console.log(`[Command] ${message.content}`); - let level = args.difficulty; + let level = args.difficulty.toLowerCase(); + if (level !== 'easy' || level !== 'medium' || level !== 'hard' || level !== 'extreme') return message.channel.send(':x: Error! Please set the difficulty to either easy, medium, hard, or extreme!'); let randomType = ['+', '-', '*']; randomType = randomType[Math.floor(Math.random() * randomType.length)]; let randomValue; diff --git a/commands/games/rockpaperscissors.js b/commands/games/rockpaperscissors.js index 5bc134ba..44ecde44 100644 --- a/commands/games/rockpaperscissors.js +++ b/commands/games/rockpaperscissors.js @@ -15,9 +15,6 @@ module.exports = class RockPaperScissors extends commando.Command { key: 'choice', prompt: 'Rock, Paper, or Scissors?', type: 'string', - validate: (str) => { - str.toLowerCase() === 'rock' || str.toLowerCase() === 'paper' || str.toLowerCase() === 'scissors'; - } }] }); } @@ -27,7 +24,7 @@ module.exports = class RockPaperScissors extends commando.Command { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return; } console.log(`[Command] ${message.content}`); - let rps = args.choice; + let rps = args.choice.toLowerCase(); let response = ['Paper', 'Rock', 'Scissors']; response = response[Math.floor(Math.random() * response.length)]; if (rps.includes("rock")) { @@ -63,5 +60,6 @@ module.exports = class RockPaperScissors extends commando.Command { return message.channel.send("Scissors! Aw, it's a tie!"); } } + else return message.channel.send(':x: Error! Please enter rock, paper, or scissors!'); } }; diff --git a/commands/games/typinggame.js b/commands/games/typinggame.js index ea718320..bbfc0ea8 100644 --- a/commands/games/typinggame.js +++ b/commands/games/typinggame.js @@ -12,10 +12,7 @@ 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', - validate: (str) => { - str.toLowerCase() === 'easy' || str.toLowerCase() === 'medium' || str.toLowerCase() === 'hard' || str.toLowerCase() === 'extreme'; - } + type: 'string' }] }); } @@ -25,7 +22,8 @@ module.exports = class TypingGameCommand extends commando.Command { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES', 'EMBED_LINKS'])) return; } console.log(`[Command] ${message.content}`); - let level = args.difficulty; + let level = args.difficulty.toLowerCase(); + if (level !== 'easy' || level !== 'medium' || level !== 'hard' || level !== 'extreme') return message.channel.send(':x: Error! Please set the difficulty to either easy, medium, hard, or extreme!'); let randomSentence = ['The quick brown fox jumps over the lazy dog.', 'Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo.', 'How razorback-jumping frogs can level six piqued gymnasts!', 'Amazingly few discotheques provide jukeboxes.']; randomSentence = randomSentence[Math.floor(Math.random() * randomSentence.length)]; let time; diff --git a/commands/imageedit/meme.js b/commands/imageedit/meme.js index edcec8cd..b6defc0d 100644 --- a/commands/imageedit/meme.js +++ b/commands/imageedit/meme.js @@ -112,17 +112,11 @@ module.exports = class MemeCommand extends commando.Command { args: [{ key: 'type', prompt: 'What meme type do you want to use?', - type: 'string', - validate: (str) => { - memecodes[str] || str === 'list'; - } + type: 'string' }, { key: 'content', prompt: 'What should the meme content be?', - type: 'string', - validate: (str) => { - str.includes(" | ") && str.match(/^[a-zA-Z0-9|.,!?'-\s]+$/); - } + type: 'string' }] }); } @@ -132,8 +126,10 @@ module.exports = class MemeCommand extends commando.Command { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES', 'ATTACH_FILES'])) return; } console.log(`[Command] ${message.content}`); - let type = args.type; + 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"); diff --git a/commands/response/choose.js b/commands/response/choose.js index 3511220a..bf6e2817 100644 --- a/commands/response/choose.js +++ b/commands/response/choose.js @@ -27,7 +27,9 @@ module.exports = class ChooseCommand extends commando.Command { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return; } console.log(`[Command] ${message.content}`); - let choices = args.choices.split(' | '); + let choices = args.choices; + if (!choices.includes(' | ')) return message.channel.send(':x: Error! Split your messages with a " | "!'); + choices = choices.split(" | "); choices = choices[Math.floor(Math.random() * choices.length)]; return message.channel.send(`I choose ${choices}!`); } diff --git a/commands/response/name.js b/commands/response/name.js index c1d090fe..8347ec08 100644 --- a/commands/response/name.js +++ b/commands/response/name.js @@ -15,10 +15,7 @@ module.exports = class RandomNameGen extends commando.Command { args: [{ key: 'gender', prompt: 'Which gender do you want to generate a name for?', - type: 'string', - validate: (str) => { - str.toLowerCase() === 'male' || str.toLowerCase() === 'female'; - } + type: 'string' }] }); } @@ -41,5 +38,8 @@ 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!'); + } } }; diff --git a/commands/search/discrim.js b/commands/search/discrim.js index 70eb571e..a11dba24 100644 --- a/commands/search/discrim.js +++ b/commands/search/discrim.js @@ -16,10 +16,7 @@ module.exports = class DiscrimCommand extends commando.Command { args: [{ key: 'discrim', prompt: 'Which discriminator would you like to search for?', - type: 'string', - validate: (str) => { - str.match(/^[0-9]+$/) && str.length === 4; - } + type: 'string' }] }); } @@ -30,6 +27,7 @@ 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}`) diff --git a/commands/search/pokedex.js b/commands/search/pokedex.js index 4dc995fe..4a078cd2 100644 --- a/commands/search/pokedex.js +++ b/commands/search/pokedex.js @@ -16,10 +16,7 @@ module.exports = class PokedexCommand extends commando.Command { args: [{ key: 'pokemon', prompt: 'What Pokémon would you like to get info on?', - type: 'string', - validate: (str) => { - pokedex.name[str.toLowerCase()]; - } + type: 'string' }] }); } @@ -30,6 +27,7 @@ module.exports = class PokedexCommand extends commando.Command { } 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!'); 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`) diff --git a/commands/textedit/morse.js b/commands/textedit/morse.js index 11a95c6b..b85cece3 100644 --- a/commands/textedit/morse.js +++ b/commands/textedit/morse.js @@ -15,10 +15,7 @@ module.exports = class MorseCommand extends commando.Command { args: [{ key: 'method', prompt: 'Would you like to encode or decode the text?', - type: 'string', - validate: (str) => { - str.toLowerCase() === 'encode' || str.toLowerCase() === 'decode'; - } + type: 'string' }, { key: 'text', prompt: 'What text would you like to convert to morse?', @@ -33,6 +30,7 @@ module.exports = class MorseCommand extends commando.Command { } 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 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?')); diff --git a/commands/textedit/romaji.js b/commands/textedit/romaji.js index 40c216ef..d2aa89c6 100644 --- a/commands/textedit/romaji.js +++ b/commands/textedit/romaji.js @@ -15,10 +15,7 @@ module.exports = class RomajiCommand extends commando.Command { args: [{ key: 'kana', prompt: 'What kana would you like to convert to romaji?', - type: 'string', - validate: (str) => { - hepburn.containsKana(str); - } + type: 'string' }] }); } @@ -29,6 +26,7 @@ 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); diff --git a/commands/textedit/translate.js b/commands/textedit/translate.js index 43d5188c..2ea13ae4 100644 --- a/commands/textedit/translate.js +++ b/commands/textedit/translate.js @@ -120,10 +120,7 @@ module.exports = class TranslateCommand extends commando.Command { args: [{ key: 'to', prompt: 'What language would you like to translate to?', - type: 'string', - validate: (str) => { - languages[str] || str.toLowerCase() === 'list'; - } + type: 'string' }, { key: 'text', prompt: 'What text would you like to translate?', @@ -138,6 +135,7 @@ module.exports = class TranslateCommand extends commando.Command { } 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 thingToTranslate = args.text; if (languageto === "list") return message.channel.send("‘af': 'Afrikaans’\n’sq': 'Albanian'\n'ar': 'Arabic’\n’hy': 'Armenian’\n’az': 'Azerbaijani’\n’eu': 'Basque’\n’be': 'Belarusian’\n’bn': 'Bengali’\n’bs': 'Bosnian’\n’bg': 'Bulgarian’\n’ca': 'Catalan’\n’ceb': 'Cebuano’\n’ny': 'Chichewa’\n’zh-cn': 'Chinese Simplified’\n’zh-tw': 'Chinese Traditional’\n’co': 'Corsican’\n’hr': 'Croatian’\n’cs': 'Czech’\n’da': 'Danish’\n’nl': 'Dutch’\n’en': 'English’\n’eo': 'Esperanto’\n’et': 'Estonian’\n’tl': 'Filipino’\n’fi': 'Finnish’\n’fr': 'French’\n’fy': 'Frisian’\n’gl': 'Galician’\n’ka': 'Georgian’\n’de': 'German’\n’el': 'Greek’\n’gu': 'Gujarati’\n’ht': 'Haitian Creole’\n’ha': 'Hausa’\n’haw': 'Hawaiian’\n’iw': 'Hebrew’\n’hi': 'Hindi’\n’hmn': 'Hmong’\n’hu': 'Hungarian’\n’is': 'Icelandic’\n’ig': 'Igbo’\n’id': 'Indonesian’\n’ga': 'Irish’\n’it': 'Italian’\n’ja': 'Japanese’\n’jw': 'Javanese’\n’kn': 'Kannada’\n’kk': 'Kazakh’\n’km': 'Khmer’\n’ko': 'Korean’\n’ku': 'Kurdish (Kurmanji)’\n’ky': 'Kyrgyz’\n’lo': 'Lao’\n’la': 'Latin’\n’lv': 'Latvian’\n’lt': 'Lithuanian’\n’lb': 'Luxembourgish’\n’mk': 'Macedonian’\n’mg': 'Malagasy’\n’ms': 'Malay’\n’ml': 'Malayalam’\n’mt': 'Maltese’\n’mi': 'Maori’\n’mr': 'Marathi’\n’mn': 'Mongolian’\n’my': 'Myanmar (Burmese)’\n’ne': 'Nepali’\n’no': 'Norwegian’\n’ps': 'Pashto’\n’fa': 'Persian’\n’pl': 'Polish’\n’pt': 'Portuguese’\n’ma': 'Punjabi’\n’ro': 'Romanian’\n’ru': 'Russian’\nsm': 'Samoan’\n’gd': 'Scots Gaelic’\n’sr': 'Serbian’\n’st': 'Sesotho’\n’sn': 'Shona’\n’sd': 'Sindhi’\n’si': 'Sinhala’\n’sk': 'Slovak’\n’sl': 'Slovenian’\n’so': 'Somali’\n’es': 'Spanish’\n’su': 'Sudanese’\n’sw': 'Swahili’\n’sv': 'Swedish’\n’tg': 'Tajik’\n’ta': 'Tamil’\n’te': 'Telugu’\n’th': 'Thai’\n’tr': 'Turkish’\n’uk': 'Ukrainian’\n’ur': 'Urdu’\n’uz': 'Uzbek’\n’vi': 'Vietnamese’\n’cy': 'Welsh’\n’xh': 'Xhosa’\n’yi': 'Yiddish’\n’yo': 'Yoruba’\n’zu': 'Zulu'"); if (thingToTranslate.length > 200) return message.channel.send(":x: Error! Please keep translations below 200 characters!"); diff --git a/index.js b/index.js index ec3e3111..b7d02c49 100644 --- a/index.js +++ b/index.js @@ -38,19 +38,20 @@ client.registry }) .registerCommandsIn(path.join(__dirname, 'commands')); -client.on('message', message => { +client.on('message', (message) => { if (message.author.bot) return; if (message.channel.type === 'dm') return; - if (!message.content.startsWith(`<@${client.user.id}>`)) { - if (message.guild.id !== config.server || message.guild.id !== config.personalServer || message.author.id !== config.owner) return; - if (clevusers.allowed[message.author.id]) { - let cleverMessage = message.content.replace(`<@${client.user.id}>`, ""); - console.log(`[Cleverbot] ${cleverMessage}`); - message.channel.startTyping(); - cleverbot.write(cleverMessage, function(response) { - message.reply(response.output); - message.channel.stopTyping(); - }); + if (message.content.startsWith(`<@${client.user.id}>`)) { + if (message.guild.id === config.server || message.guild.id === config.personalServer || message.author.id === config.owner) { + if (message.author.id === clevusers.allowed[message.author.id]) { + let cleverMessage = message.content.replace(`<@${client.user.id}>`, ""); + console.log(`[Cleverbot] ${cleverMessage}`); + message.channel.startTyping(); + cleverbot.write(cleverMessage, function(response) { + message.reply(response.output); + message.channel.stopTyping(); + }); + } } } });