choice argument type

This commit is contained in:
Daniel Odendahl Jr
2018-03-17 13:02:45 +00:00
parent 7c12d04e42
commit 679bb538cb
17 changed files with 84 additions and 121 deletions
+32 -32
View File
@@ -1,34 +1,34 @@
[ [
"AUD", "aud",
"USD", "usd",
"BGN", "bgn",
"BRL", "brl",
"CAD", "cad",
"CHF", "chf",
"CNY", "cny",
"CZK", "czk",
"DKK", "dkk",
"GBP", "gbp",
"HKD", "hkd",
"HRK", "hrk",
"HUF", "huf",
"IDR", "idr",
"ILS", "ils",
"INR", "inr",
"JPY", "jpy",
"KRW", "krw",
"MXN", "mxn",
"MYR", "myr",
"NOK", "nok",
"NZD", "nzd",
"PHP", "php",
"PLN", "pln",
"RON", "ron",
"RUB", "rub",
"SEK", "sek",
"SGD", "sgd",
"THB", "thb",
"TRY", "try",
"ZAR", "zar",
"EUR" "eur"
] ]
+2 -6
View File
@@ -22,12 +22,8 @@ module.exports = class HatCommand extends Command {
{ {
key: 'type', key: 'type',
prompt: `What type of hat would you like to use? Either ${list(hats, 'or')}.`, prompt: `What type of hat would you like to use? Either ${list(hats, 'or')}.`,
type: 'string', type: 'choice',
validate: type => { choices: hats
if (hats.includes(type.toLowerCase())) return true;
return `Invalid type, please enter either ${list(hats, 'or')}.`;
},
parse: type => type.toLowerCase()
}, },
{ {
key: 'user', key: 'user',
+2 -6
View File
@@ -17,12 +17,8 @@ module.exports = class HoroscopeCommand extends Command {
{ {
key: 'sign', key: 'sign',
prompt: `Which sign would you like to get the horoscope for? Either ${list(signs, 'or')}.`, prompt: `Which sign would you like to get the horoscope for? Either ${list(signs, 'or')}.`,
type: 'string', type: 'choice',
validate: sign => { choices: signs
if (signs.includes(sign.toLowerCase())) return true;
return `Invalid sign, please enter either ${list(signs, 'or')}.`;
},
parse: sign => sign.toLowerCase()
} }
] ]
}); });
+2 -6
View File
@@ -24,12 +24,8 @@ module.exports = class MathQuizCommand extends Command {
{ {
key: 'difficulty', key: 'difficulty',
prompt: `What should the difficulty of the game be? Either ${list(difficulties, 'or')}.`, prompt: `What should the difficulty of the game be? Either ${list(difficulties, 'or')}.`,
type: 'string', type: 'choice',
validate: difficulty => { choices: difficulties
if (difficulties.includes(difficulty.toLowerCase())) return true;
return `Invalid difficulty, please enter either ${list(difficulties, 'or')}.`;
},
parse: difficulty => difficulty.toLowerCase()
} }
] ]
}); });
+4 -12
View File
@@ -22,24 +22,16 @@ module.exports = class QuizCommand extends Command {
{ {
key: 'type', key: 'type',
prompt: `Which type of question would you like to have? Either ${list(types, 'or')}.`, prompt: `Which type of question would you like to have? Either ${list(types, 'or')}.`,
type: 'string', type: 'choice',
default: 'multiple', default: 'multiple',
validate: type => { choices: types
if (types.includes(type.toLowerCase())) return true;
return `Invalid type, please enter either ${list(types, 'or')}.`;
},
parse: type => type.toLowerCase()
}, },
{ {
key: 'difficulty', key: 'difficulty',
prompt: `What should the difficulty of the game be? Either ${list(difficulties, 'or')}.`, prompt: `What should the difficulty of the game be? Either ${list(difficulties, 'or')}.`,
type: 'string', type: 'choice',
default: '', default: '',
validate: difficulty => { choices: difficulties
if (difficulties.includes(difficulty.toLowerCase())) return true;
return `Invalid difficulty, please enter either ${list(difficulties, 'or')}.`;
},
parse: difficulty => difficulty.toLowerCase()
} }
] ]
}); });
+2 -2
View File
@@ -13,8 +13,8 @@ module.exports = class RockPaperScissorsCommand extends Command {
{ {
key: 'choice', key: 'choice',
prompt: 'Rock, Paper, or Scissors?', prompt: 'Rock, Paper, or Scissors?',
type: 'string', type: 'choice',
parse: choice => choice.toLowerCase() choices
} }
] ]
}); });
+2 -6
View File
@@ -24,12 +24,8 @@ module.exports = class TypingTestCommand extends Command {
{ {
key: 'difficulty', key: 'difficulty',
prompt: `What should the difficulty of the game be? Either ${list(difficulties, 'or')}.`, prompt: `What should the difficulty of the game be? Either ${list(difficulties, 'or')}.`,
type: 'string', type: 'choice',
validate: difficulty => { choices: difficulties
if (difficulties.includes(difficulty.toLowerCase())) return true;
return `Invalid difficulty, please enter either ${list(difficulties, 'or')}.`;
},
parse: difficulty => difficulty.toLowerCase()
} }
] ]
}); });
+1 -1
View File
@@ -33,7 +33,7 @@ module.exports = class ChannelInfoCommand extends Command {
const embed = new MessageEmbed() const embed = new MessageEmbed()
.setColor(0x00AE86) .setColor(0x00AE86)
.addField(' Name', .addField(' Name',
channel.name || 'None', true) channel.type !== 'dm' ? channel.name : `@${channel.recipient.username}`, true)
.addField(' ID', .addField(' ID',
channel.id, true) channel.id, true)
.addField(' NSFW', .addField(' NSFW',
+2 -6
View File
@@ -15,13 +15,9 @@ module.exports = class EmojiListCommand extends Command {
{ {
key: 'type', key: 'type',
prompt: `What type of emoji would you like to view? Either ${list(types, 'or')}.`, prompt: `What type of emoji would you like to view? Either ${list(types, 'or')}.`,
type: 'string', type: 'choice',
default: 'regular', default: 'regular',
validate: type => { choices: types
if (types.includes(type.toLowerCase())) return true;
return `Invalid type, please enter either ${list(types, 'or')}.`;
},
parse: type => type.toLowerCase()
} }
] ]
}); });
+4 -12
View File
@@ -16,22 +16,14 @@ module.exports = class CurrencyCommand extends Command {
{ {
key: 'base', key: 'base',
prompt: `What currency code do you want to use as the base? Either ${list(codes, 'or')}.`, prompt: `What currency code do you want to use as the base? Either ${list(codes, 'or')}.`,
type: 'string', type: 'choice',
validate: base => { choices: codes
if (codes.includes(base.toUpperCase())) return true;
return `Invalid base, please enter either ${list(codes, 'or')}.`;
},
parse: base => base.toUpperCase()
}, },
{ {
key: 'target', key: 'target',
prompt: `What currency code do you want to convert to? Either ${list(codes, 'or')}.`, prompt: `What currency code do you want to convert to? Either ${list(codes, 'or')}.`,
type: 'string', type: 'choice',
validate: target => { choices: codes
if (codes.includes(target.toUpperCase())) return true;
return `Invalid target, please enter either ${list(codes, 'or')}.`;
},
parse: target => target.toUpperCase()
}, },
{ {
key: 'amount', key: 'amount',
+2 -6
View File
@@ -15,13 +15,9 @@ module.exports = class NameCommand extends Command {
{ {
key: 'gender', key: 'gender',
prompt: `Which gender do you want to generate a name for? Either ${list(genders, 'or')}.`, prompt: `Which gender do you want to generate a name for? Either ${list(genders, 'or')}.`,
type: 'string', type: 'choice',
default: 'both', default: 'both',
validate: gender => { choices: genders
if (genders.includes(gender.toLowerCase())) return true;
return `Invalid gender, please enter either ${list(genders, 'or')}.`;
},
parse: gender => gender.toLowerCase()
} }
] ]
}); });
+2 -6
View File
@@ -16,12 +16,8 @@ module.exports = class DeviantartCommand extends Command {
{ {
key: 'section', key: 'section',
prompt: `What section would you like to search? Either ${list(sections, 'or')}.`, prompt: `What section would you like to search? Either ${list(sections, 'or')}.`,
type: 'string', type: 'choice',
validate: section => { choices: sections
if (sections.includes(section.toLowerCase())) return true;
return `Invalid section, please enter either ${list(sections, 'or')}.`;
},
parse: section => section.toLowerCase()
}, },
{ {
key: 'query', key: 'query',
+3 -7
View File
@@ -1,7 +1,7 @@
const { Command } = require('discord.js-commando'); const { Command } = require('discord.js-commando');
const { MessageEmbed } = require('discord.js'); const { MessageEmbed } = require('discord.js');
const snekfetch = require('snekfetch'); const snekfetch = require('snekfetch');
const { shorten, list } = require('../../util/Util'); const { shorten } = require('../../util/Util');
const types = ['random', 'top']; const types = ['random', 'top'];
module.exports = class UrbanDictionaryCommand extends Command { module.exports = class UrbanDictionaryCommand extends Command {
@@ -23,13 +23,9 @@ module.exports = class UrbanDictionaryCommand extends Command {
{ {
key: 'type', key: 'type',
prompt: 'Do you want to get the top answer or a random one?', prompt: 'Do you want to get the top answer or a random one?',
type: 'string', type: 'choice',
default: 'top', default: 'top',
validate: type => { choices: types
if (types.includes(type.toLowerCase())) return true;
return `Invalid type, please enter either ${list(types, 'or')}.`;
},
parse: type => type.toLowerCase()
} }
] ]
}); });
+2 -6
View File
@@ -15,12 +15,8 @@ module.exports = class Base64Command extends Command {
{ {
key: 'mode', key: 'mode',
prompt: `Would you like to ${list(modes, 'or')}?`, prompt: `Would you like to ${list(modes, 'or')}?`,
type: 'string', type: 'choice',
validate: mode => { choices: modes
if (modes.includes(mode.toLowerCase())) return true;
return `Invalid mode, please enter either ${list(modes, 'or')}.`;
},
parse: mode => mode.toLowerCase()
}, },
{ {
key: 'text', key: 'text',
+2 -6
View File
@@ -14,12 +14,8 @@ module.exports = class BinaryCommand extends Command {
{ {
key: 'mode', key: 'mode',
prompt: `Would you like to ${list(modes, 'or')}?`, prompt: `Would you like to ${list(modes, 'or')}?`,
type: 'string', type: 'choice',
validate: mode => { choices: modes
if (modes.includes(mode.toLowerCase())) return true;
return `Invalid mode, please enter either ${list(modes, 'or')}.`;
},
parse: mode => mode.toLowerCase()
}, },
{ {
key: 'text', key: 'text',
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "xiao", "name": "xiao",
"version": "69.0.0", "version": "69.0.1",
"description": "Your personal server companion.", "description": "Your personal server companion.",
"main": "Xiao.js", "main": "Xiao.js",
"scripts": { "scripts": {
+19
View File
@@ -0,0 +1,19 @@
const { ArgumentType } = require('discord.js-commando');
const { list } = require('../util/Util');
class ChoiceArgumentType extends ArgumentType {
constructor(client) {
super(client, 'choice');
}
validate(value, msg, arg) {
if (arg.choices.includes(value.toLowerCase())) return true;
return `Invalid ${arg.label}, please enter either ${list(arg.choices, 'or')}.`;
}
parse(value) {
return value.toLowerCase();
}
}
module.exports = ChoiceArgumentType;