Ostatnio aktywny 1 month ago

nuno zrewidował ten Gist 1 month ago. Przejdź do rewizji

1 file changed, 27 insertions

emojis.ts(stworzono plik)

@@ -0,0 +1,27 @@
1 + import fs from "fs";
2 + import path from "path";
3 + import { EmojiMap, ClassKey } from "../types";
4 +
5 + const EMOJI_PATH = path.join(__dirname, "../../messages/emojis.json");
6 + let _emojis: EmojiMap = {};
7 +
8 + export function loadEmojis(): void {
9 + try { _emojis = JSON.parse(fs.readFileSync(EMOJI_PATH, "utf8")); }
10 + catch (err) { console.error("Failed to load emojis.json:", err); _emojis = {}; }
11 + }
12 +
13 + export function getEmoji(key: string): string {
14 + return _emojis[key] ?? "";
15 + }
16 +
17 + export function getClassEmoji(cls: ClassKey): string {
18 + return getEmoji(cls.toLowerCase());
19 + }
20 +
21 + export function getNationEmoji(nation: string): string {
22 + return getEmoji(nation.toLowerCase());
23 + }
24 +
25 + export function resolveEmojiTokens(text: string): string {
26 + return text.replace(/\{emoji:([^}]+)\}/g, (_, key: string) => getEmoji(key));
27 + }
Nowsze Starsze