From 9bf8c321381064a50c00b99712efd7984dbf6490 Mon Sep 17 00:00:00 2001 From: networkException Date: Fri, 14 May 2021 01:52:27 +0200 Subject: [PATCH] EmojiArgument: Add support for regional indicators This is a temporary fix until https://github.com/omnidan/node-emoji/issues/109 gets resolved --- arguments/emojiArgument.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/arguments/emojiArgument.ts b/arguments/emojiArgument.ts index e36c4b3..a4a7ace 100644 --- a/arguments/emojiArgument.ts +++ b/arguments/emojiArgument.ts @@ -7,6 +7,35 @@ export type EmojiType = 'all' | 'unicode' | 'custom'; export class EmojiArgument extends RegexBasedArgument { + private static readonly regionalIndicators: Map = new Map([ + ['🇦', ':regional_indicator_a:'], + ['🇧', ':regional_indicator_b:'], + ['🇨', ':regional_indicator_c:'], + ['🇩', ':regional_indicator_d:'], + ['🇪', ':regional_indicator_e:'], + ['🇫', ':regional_indicator_f:'], + ['🇬', ':regional_indicator_g:'], + ['🇭', ':regional_indicator_h:'], + ['🇮', ':regional_indicator_i:'], + ['🇯', ':regional_indicator_j:'], + ['🇰', ':regional_indicator_k:'], + ['🇱', ':regional_indicator_l:'], + ['🇲', ':regional_indicator_m:'], + ['🇳', ':regional_indicator_n:'], + ['🇴', ':regional_indicator_o:'], + ['🇵', ':regional_indicator_p:'], + ['🇶', ':regional_indicator_q:'], + ['🇷', ':regional_indicator_r:'], + ['🇸', ':regional_indicator_s:'], + ['🇹', ':regional_indicator_t:'], + ['🇺', ':regional_indicator_u:'], + ['🇻', ':regional_indicator_v:'], + ['🇼', ':regional_indicator_w:'], + ['🇽', ':regional_indicator_x:'], + ['🇾', ':regional_indicator_y:'], + ['🇿', ':regional_indicator_z:'] + ]); + public static async parse(message: Message, input: string, type: EmojiType = 'all'): Promise { if (!input) throw CommandError.syntax('EmojiArgument', 'No input provided'); @@ -24,6 +53,13 @@ export class EmojiArgument extends RegexBasedArgument { } } + if (this.regionalIndicators.has(input)) { + if (type === 'custom') + throw CommandError.syntax('EmojiArgument', 'Required type custom but input is of type unicode'); + + return this.regionalIndicators.get(input); + } + if (type === 'unicode') throw CommandError.syntax('EmojiArgument', `Required type ${type} but got \`${input.replaceAll('`', '')}\` instead`);