From 6f3677b8ee3569221189776511b18f89f6d08329 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Fri, 6 Oct 2017 13:41:43 +0000 Subject: [PATCH] Make emoji type consistent with others in commando --- types/emoji.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/types/emoji.js b/types/emoji.js index bd0bb8f9..4da0a7b3 100644 --- a/types/emoji.js +++ b/types/emoji.js @@ -8,16 +8,13 @@ class EmojiArgumentType extends ArgumentType { validate(value, msg) { const matches = value.match(/^(?:<:([a-zA-Z0-9_]+):)?([0-9]+)>?$/); - if (matches) { - const emoji = msg.client.emojis.get(matches[2]); - if (emoji) return true; - } + if (msg.client.emojis.has(matches[2])) return true; if (!msg.guild) return false; const search = value.toLowerCase(); - let emojis = msg.guild.emojis.filterArray(emoji => emoji.name.toLowerCase().includes(search)); + let emojis = msg.guild.emojis.filterArray(nameFilterInexact(search)); if (!emojis.length) return false; if (emojis.length === 1) return true; - const exactEmojis = msg.guild.emojis.filterArray(emoji => emoji.name.toLowerCase() === search); + const exactEmojis = emojis.filter(nameFilterExact(search)); if (exactEmojis.length === 1) return true; if (exactEmojis.length > 0) emojis = exactEmojis; return emojis.length <= 15 @@ -38,4 +35,12 @@ class EmojiArgumentType extends ArgumentType { } } +function nameFilterExact(search) { + return thing => thing.name.toLowerCase() === search; +} + +function nameFilterInexact(search) { + return thing => thing.name.toLowerCase().includes(search); +} + module.exports = EmojiArgumentType;