Make emoji type consistent with others in commando

This commit is contained in:
Daniel Odendahl Jr
2017-10-06 13:41:43 +00:00
parent 5564f09c51
commit 6f3677b8ee
+11 -6
View File
@@ -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;