import { ClassKey, Nation } from "@src/types"; import { getClassEmoji, getNationEmoji, getEmoji } from "@systems/emojis"; // ─── Individual formatters ──────────────────────────────────────────────────── export interface CharDisplayOptions { emoji?: boolean; // show class emoji (default: true) level?: boolean; // show level (default: true) } /** * Format a character for display in embeds and messages. * Output: <:class:> 79 «Flash» */ function char( c: { class: ClassKey; level: number; name: string }, options?: CharDisplayOptions ): string { const showEmoji = options?.emoji ?? true; const showLevel = options?.level ?? true; const classStr = showEmoji ? (getClassEmoji(c.class) || c.class) : c.class; const levelStr = showLevel ? `${c.level} ` : ""; return `${classStr} ${levelStr}${c.name}`.trim(); } /** * Format a nation name with its emoji. * Output: <:capella:> Capella */ function nation(n: Nation): string { const emoji = getNationEmoji(n); return emoji ? `${emoji} ${n}` : n; } /** * Format a score line. * Output: <:score:> 3000 <:kd:> 32/18 */ function score(pts: number, k?: number, d?: number): string { const scoreEmoji = getEmoji("score") || "📊"; const kdEmoji = getEmoji("kd") || "⚔️"; const kdStr = k !== undefined && d !== undefined ? ` ${kdEmoji} ${k}/${d}` : ""; return `${scoreEmoji} ${pts}${kdStr}`; } /** * Parse a Discord custom emoji string to an object for ButtonBuilder.setEmoji() * Input: "<:fb:1511020923510194428>" * Output: { name: "fb", id: "1511020923510194428" } */ function emoji(emojiStr: string): { name: string; id: string } | string | null { if (!emojiStr) return null; const match = emojiStr.match(/^<:(\w+):(\d+)>$/); if (match) return { name: match[1], id: match[2] }; return emojiStr; } // ─── Namespace export ───────────────────────────────────────────────────────── export const format = { char, nation, score, emoji, };