Skip to content

Commit

Permalink
EmojiArgument: Add support for regional indicators
Browse files Browse the repository at this point in the history
This is a temporary fix until omnidan/node-emoji#109 gets
resolved
  • Loading branch information
networkException committed May 13, 2021
1 parent ed4eae3 commit 9bf8c32
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions arguments/emojiArgument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,35 @@ export type EmojiType = 'all' | 'unicode' | 'custom';

export class EmojiArgument extends RegexBasedArgument {

private static readonly regionalIndicators: Map<string, string> = new Map<string, string>([
['๐Ÿ‡ฆ', ':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<string | Emoji> {
if (!input)
throw CommandError.syntax('EmojiArgument', 'No input provided');
Expand All @@ -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`);

Expand Down

0 comments on commit 9bf8c32

Please sign in to comment.