From 0702a2d459d4ba75cde59b00374648bc3aa411b4 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Fri, 23 Mar 2018 22:35:21 +0000 Subject: [PATCH] oneOf --- assets/json/currency.json | 64 ++++++++++++------------- commands/avatar-edit/hat.js | 5 +- commands/events/horoscope.js | 5 +- commands/events/neko-atsume-password.js | 5 +- commands/games/math-quiz.js | 5 +- commands/games/quiz.js | 10 +--- commands/games/typing-test.js | 5 +- commands/image-edit/illegal.js | 5 +- commands/info/emoji-list.js | 5 +- commands/number-edit/currency.js | 10 +--- commands/random/name.js | 5 +- commands/search/deviantart.js | 5 +- commands/search/urban-dictionary.js | 5 +- commands/text-edit/base64.js | 5 +- commands/text-edit/binary.js | 5 +- 15 files changed, 48 insertions(+), 96 deletions(-) diff --git a/assets/json/currency.json b/assets/json/currency.json index 06fe2787..c5d5599f 100644 --- a/assets/json/currency.json +++ b/assets/json/currency.json @@ -1,34 +1,34 @@ [ - "AUD", - "USD", - "BGN", - "BRL", - "CAD", - "CHF", - "CNY", - "CZK", - "DKK", - "GBP", - "HKD", - "HRK", - "HUF", - "IDR", - "ILS", - "INR", - "JPY", - "KRW", - "MXN", - "MYR", - "NOK", - "NZD", - "PHP", - "PLN", - "RON", - "RUB", - "SEK", - "SGD", - "THB", - "TRY", - "ZAR", - "EUR" + "aud", + "usd", + "bgn", + "brl", + "cad", + "chf", + "cny", + "czk", + "dkk", + "gbp", + "hkd", + "hrk", + "huf", + "idr", + "ils", + "inr", + "jpy", + "krw", + "mxn", + "myr", + "nok", + "nzd", + "php", + "pln", + "ron", + "rub", + "sek", + "sgd", + "thb", + "try", + "zar", + "eur" ] diff --git a/commands/avatar-edit/hat.js b/commands/avatar-edit/hat.js index 8afa9b51..30e9bc20 100644 --- a/commands/avatar-edit/hat.js +++ b/commands/avatar-edit/hat.js @@ -23,10 +23,7 @@ module.exports = class HatCommand extends Command { key: 'type', prompt: `What type of hat would you like to use? Either ${list(hats, 'or')}.`, type: 'string', - validate: type => { - if (hats.includes(type.toLowerCase())) return true; - return `Invalid type, please enter either ${list(hats, 'or')}.`; - }, + oneOf: hats, parse: type => type.toLowerCase() }, { diff --git a/commands/events/horoscope.js b/commands/events/horoscope.js index 83635114..6259eb5c 100644 --- a/commands/events/horoscope.js +++ b/commands/events/horoscope.js @@ -18,10 +18,7 @@ module.exports = class HoroscopeCommand extends Command { key: 'sign', prompt: `Which sign would you like to get the horoscope for? Either ${list(signs, 'or')}.`, type: 'string', - validate: sign => { - if (signs.includes(sign.toLowerCase())) return true; - return `Invalid sign, please enter either ${list(signs, 'or')}.`; - }, + oneOf: signs, parse: sign => sign.toLowerCase() } ] diff --git a/commands/events/neko-atsume-password.js b/commands/events/neko-atsume-password.js index 9e49a751..5fac829d 100644 --- a/commands/events/neko-atsume-password.js +++ b/commands/events/neko-atsume-password.js @@ -18,10 +18,7 @@ module.exports = class NekoAtsumePasswordCommand extends Command { prompt: `What locale do you want to use? Either ${list(locales, 'or')}.`, type: 'string', default: 'en', - validate: locale => { - if (locales.includes(locale.toLowerCase())) return true; - return `Invalid locale, please enter either ${list(locales, 'or')}.`; - }, + oneOf: locales, parse: locale => locale.toLowerCase() } ] diff --git a/commands/games/math-quiz.js b/commands/games/math-quiz.js index 02c85902..4a0a3da4 100644 --- a/commands/games/math-quiz.js +++ b/commands/games/math-quiz.js @@ -25,10 +25,7 @@ module.exports = class MathQuizCommand extends Command { key: 'difficulty', prompt: `What should the difficulty of the game be? Either ${list(difficulties, 'or')}.`, type: 'string', - validate: difficulty => { - if (difficulties.includes(difficulty.toLowerCase())) return true; - return `Invalid difficulty, please enter either ${list(difficulties, 'or')}.`; - }, + oneOf: difficulties, parse: difficulty => difficulty.toLowerCase() } ] diff --git a/commands/games/quiz.js b/commands/games/quiz.js index b3a34fdb..82b334ff 100644 --- a/commands/games/quiz.js +++ b/commands/games/quiz.js @@ -24,10 +24,7 @@ module.exports = class QuizCommand extends Command { prompt: `Which type of question would you like to have? Either ${list(types, 'or')}.`, type: 'string', default: 'multiple', - validate: type => { - if (types.includes(type.toLowerCase())) return true; - return `Invalid type, please enter either ${list(types, 'or')}.`; - }, + oneOf: types, parse: type => type.toLowerCase() }, { @@ -35,10 +32,7 @@ module.exports = class QuizCommand extends Command { prompt: `What should the difficulty of the game be? Either ${list(difficulties, 'or')}.`, type: 'string', default: '', - validate: difficulty => { - if (difficulties.includes(difficulty.toLowerCase())) return true; - return `Invalid difficulty, please enter either ${list(difficulties, 'or')}.`; - }, + oneOf: difficulties, parse: difficulty => difficulty.toLowerCase() } ] diff --git a/commands/games/typing-test.js b/commands/games/typing-test.js index 284ed17d..302801b3 100644 --- a/commands/games/typing-test.js +++ b/commands/games/typing-test.js @@ -25,10 +25,7 @@ module.exports = class TypingTestCommand extends Command { key: 'difficulty', prompt: `What should the difficulty of the game be? Either ${list(difficulties, 'or')}.`, type: 'string', - validate: difficulty => { - if (difficulties.includes(difficulty.toLowerCase())) return true; - return `Invalid difficulty, please enter either ${list(difficulties, 'or')}.`; - }, + oneOf: difficulties, parse: difficulty => difficulty.toLowerCase() } ] diff --git a/commands/image-edit/illegal.js b/commands/image-edit/illegal.js index d3e363ac..0fb6fb14 100644 --- a/commands/image-edit/illegal.js +++ b/commands/image-edit/illegal.js @@ -32,10 +32,7 @@ module.exports = class IllegalCommand extends Command { prompt: 'Should the text use is, are, or am?', type: 'string', default: 'IS', - validate: verb => { - if (['is', 'are', 'am'].includes(verb.toLowerCase())) return true; - return 'Invalid verb, please enter either is, are, or am.'; - }, + oneOf: ['is', 'are', 'am'], parse: verb => verb.toUpperCase() } ] diff --git a/commands/info/emoji-list.js b/commands/info/emoji-list.js index dc1fe096..62c09d15 100644 --- a/commands/info/emoji-list.js +++ b/commands/info/emoji-list.js @@ -17,10 +17,7 @@ module.exports = class EmojiListCommand extends Command { prompt: `What type of emoji would you like to view? Either ${list(types, 'or')}.`, type: 'string', default: 'regular', - validate: type => { - if (types.includes(type.toLowerCase())) return true; - return `Invalid type, please enter either ${list(types, 'or')}.`; - }, + oneOf: types, parse: type => type.toLowerCase() } ] diff --git a/commands/number-edit/currency.js b/commands/number-edit/currency.js index 7afde0e1..05b2bc43 100644 --- a/commands/number-edit/currency.js +++ b/commands/number-edit/currency.js @@ -22,20 +22,14 @@ module.exports = class CurrencyCommand extends Command { key: 'base', prompt: `What currency code do you want to use as the base? Either ${list(codes, 'or')}.`, type: 'string', - validate: base => { - if (codes.includes(base.toUpperCase())) return true; - return `Invalid base, please enter either ${list(codes, 'or')}.`; - }, + oneOf: codes, parse: base => base.toUpperCase() }, { key: 'target', prompt: `What currency code do you want to convert to? Either ${list(codes, 'or')}.`, type: 'string', - validate: target => { - if (codes.includes(target.toUpperCase())) return true; - return `Invalid target, please enter either ${list(codes, 'or')}.`; - }, + oneOf: codes, parse: target => target.toUpperCase() } ] diff --git a/commands/random/name.js b/commands/random/name.js index 5d2656ca..53be481f 100644 --- a/commands/random/name.js +++ b/commands/random/name.js @@ -17,10 +17,7 @@ module.exports = class NameCommand extends Command { prompt: `Which gender do you want to generate a name for? Either ${list(genders, 'or')}.`, type: 'string', default: 'both', - validate: gender => { - if (genders.includes(gender.toLowerCase())) return true; - return `Invalid gender, please enter either ${list(genders, 'or')}.`; - }, + oneOf: genders, parse: gender => gender.toLowerCase() } ] diff --git a/commands/search/deviantart.js b/commands/search/deviantart.js index 0ac50d58..0c9ee269 100644 --- a/commands/search/deviantart.js +++ b/commands/search/deviantart.js @@ -17,10 +17,7 @@ module.exports = class DeviantartCommand extends Command { key: 'section', prompt: `What section would you like to search? Either ${list(sections, 'or')}.`, type: 'string', - validate: section => { - if (sections.includes(section.toLowerCase())) return true; - return `Invalid section, please enter either ${list(sections, 'or')}.`; - }, + oneOf: sections, parse: section => section.toLowerCase() }, { diff --git a/commands/search/urban-dictionary.js b/commands/search/urban-dictionary.js index 8cf00d15..cbce67e5 100644 --- a/commands/search/urban-dictionary.js +++ b/commands/search/urban-dictionary.js @@ -25,10 +25,7 @@ module.exports = class UrbanDictionaryCommand extends Command { prompt: 'Do you want to get the top answer or a random one?', type: 'string', default: 'top', - validate: type => { - if (types.includes(type.toLowerCase())) return true; - return `Invalid type, please enter either ${list(types, 'or')}.`; - }, + oneOf: types, parse: type => type.toLowerCase() } ] diff --git a/commands/text-edit/base64.js b/commands/text-edit/base64.js index 05592468..d443aee1 100644 --- a/commands/text-edit/base64.js +++ b/commands/text-edit/base64.js @@ -16,10 +16,7 @@ module.exports = class Base64Command extends Command { key: 'mode', prompt: `Would you like to ${list(modes, 'or')}?`, type: 'string', - validate: mode => { - if (modes.includes(mode.toLowerCase())) return true; - return `Invalid mode, please enter either ${list(modes, 'or')}.`; - }, + oneOf: modes, parse: mode => mode.toLowerCase() }, { diff --git a/commands/text-edit/binary.js b/commands/text-edit/binary.js index 9d8056e3..beac47e2 100644 --- a/commands/text-edit/binary.js +++ b/commands/text-edit/binary.js @@ -15,10 +15,7 @@ module.exports = class BinaryCommand extends Command { key: 'mode', prompt: `Would you like to ${list(modes, 'or')}?`, type: 'string', - validate: mode => { - if (modes.includes(mode.toLowerCase())) return true; - return `Invalid mode, please enter either ${list(modes, 'or')}.`; - }, + oneOf: modes, parse: mode => mode.toLowerCase() }, {