mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Make emoji type consistent with others in commando
This commit is contained in:
+11
-6
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user