Change in the way choice commands work

This commit is contained in:
Daniel Odendahl Jr
2017-04-11 13:44:43 +00:00
parent 0a3d8dc6a5
commit f0ad17ab4b
6 changed files with 71 additions and 38 deletions
+40
View File
@@ -0,0 +1,40 @@
const { ArgumentType } = require('discord.js-commando');
const emojiRanges = [
'[\u0023-\u0039]\u20E3',
'[\u2002-\u21AA]',
'[\u231A-\u27bf]',
'[\u2934-\u2b55]',
'\u3030', '\u303D',
'\u3297', '\u3299',
'\uD83C[\udc04-\uDFFF]',
'\uD83D[\uDC00-\uDE4F]'
];
const emojiRegex = new RegExp(emojiRanges.join('|'), 'g');
const regex = /<:([a-zA-Z0-9_]+):(\d+)>/;
class EmojiArgumentType extends ArgumentType {
constructor(client) {
super(client, 'emoji');
}
validate(value, msg) {
if (value.match(regex)) {
const emoji = msg.client.emojis.get(value.match(regex)[2]);
if (emoji) return true;
} else if (value.match(emojiRegex)) {
return true;
}
return false;
}
parse(value, msg) { // eslint-disable-line consistent-return
if (value.match(regex)) {
const emoji = msg.client.emojis.get(value.match(regex)[2]);
if (emoji) return emoji;
} else if (value.match(emojiRegex)) {
return value.match(emojiRegex)[0];
}
}
}
module.exports = EmojiArgumentType;