@ayanaware/bentocord
Version:
Bentocord is a Bento plugin designed to rapidly build fully functional Discord Bots.
40 lines • 1.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EmojiOptionResolver = void 0;
/* eslint-disable @typescript-eslint/naming-convention */
const eris_1 = require("eris");
const OptionType_1 = require("../constants/OptionType");
class EmojiOptionResolver {
constructor() {
this.option = OptionType_1.OptionType.EMOJI;
this.convert = eris_1.Constants.ApplicationCommandOptionTypes.STRING;
}
async reduce(ctx, option, emoji) {
return { display: emoji.name };
}
async resolve(ctx, option, input) {
const guild = ctx.guild;
if (!guild)
return null;
// guild emojis
const emojis = guild.emojis.filter(e => this.checkEmoji(input, e));
// unicode
const unicode = /(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/.exec(input);
if (unicode)
return { id: null, name: unicode[1], require_colons: false, animated: false, available: true, managed: false, roles: [] };
return emojis;
}
checkEmoji(input, emoji) {
if (emoji.id === input)
return true;
// handle usage
const custom = /^<(?<a>a)?:(?<name>[a-zA-Z0-9_]+):(?<id>\d{17,19})>$/.exec(input);
if (custom && custom.groups.id === emoji.id)
return true;
// handle name
input = input.replace(/:/g, '');
return emoji.name.toLocaleLowerCase().includes(input.toLocaleLowerCase());
}
}
exports.EmojiOptionResolver = EmojiOptionResolver;
//# sourceMappingURL=EmojiOption.js.map