import { ChatInputCommandInteraction, TextChannel, EmbedBuilder } from "discord.js"; import { cfg } from "@systems/config"; import { getCurrentWeek, getWeekKey, getBringer } from "@systems/wrank"; import { getEmoji } from "@systems/emojis"; import { replyAndDelete } from "@utils"; export async function handleRankPost(interaction: ChatInputCommandInteraction): Promise { const week = getCurrentWeek(); const goal = cfg("wRankGoal"); const weekKey = getWeekKey(); const formatNation = (nation: "capella" | "procyon"): string => { const entries = [...week.entries[nation]].sort((a, b) => a.currentRank - b.currentRank); if (entries.length === 0) return "—"; const bringer = getBringer(nation === "capella" ? "Capella" : "Procyon"); return entries.map((e) => { const isDone = e.tgCount >= goal; // ── Rank indicator ─────────────────────────────────────────────────── // Use wrank_1_gold emoji if rank 1 and done, wrank_N emoji if available, // otherwise bold number as fallback (no colors in Discord plain text) const rankKey = isDone ? `wrank_${e.currentRank}_gold` : `wrank_${e.currentRank}`; const rankEmoji = getEmoji(rankKey); const rankStr = rankEmoji ?? (isDone ? `**${e.currentRank}**` : `${e.currentRank}`); // ── Delta ──────────────────────────────────────────────────────────── // Use wrank_up_N / wrank_down_N emoji if available, text arrow as fallback const delta = e.previousRank !== undefined ? e.currentRank - e.previousRank : 0; let deltaStr = ""; if (delta < 0) { const abs = Math.abs(delta); deltaStr = " " + (getEmoji(`wrank_up_${abs}`) ?? `↑${abs}`); } else if (delta > 0) { deltaStr = " " + (getEmoji(`wrank_down_${delta}`) ?? `↓${delta}`); } console.log(`rankKey: ${rankKey} rankEmoji: ${rankEmoji} rankStr: ${rankStr} isDone: ${isDone} delta: ${delta}`); // ── Bringer label ──────────────────────────────────────────────────── const bringerStr = bringer === e.userKey && isDone ? ` · ${nation === "capella" ? "Luminous Bringer" : "Storm Bringer"}` : ""; return `${rankStr}${deltaStr} «${e.characterName}» — ${e.weeklyPoints} pts (${e.tgCount}/${goal}${bringerStr})`; }).join("\n"); }; const embed = new EmbedBuilder() .setTitle(`⚔️ W.Rank Leaderboard — ${weekKey}`) .setColor(0xe8a317) .addFields( { name: "🔵 Capella", value: formatNation("capella"), inline: true }, { name: "🔴 Procyon", value: formatNation("procyon"), inline: true }, ) .setTimestamp(); const channelId = cfg("resultsChannelId") || cfg("pollChannelId"); const channel = await interaction.client.channels.fetch(channelId) as TextChannel; await channel.send({ embeds: [embed] }); return void replyAndDelete(interaction, "✅ Leaderboard posted."); }