import { ChatInputCommandInteraction, TextChannel, EmbedBuilder } from "discord.js"; import { cfg } from "../../systems/config"; import { getCurrentWeek, getWeekKey, getBringer } from "../../systems/wrank"; 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; const delta = e.previousRank !== undefined ? e.currentRank - e.previousRank : 0; const deltaStr = delta < 0 ? ` โ†‘${Math.abs(delta)}` : delta > 0 ? ` โ†“${delta}` : ""; const bringerStr = bringer === e.userKey && isDone ? ` ยท ${nation === "capella" ? "Luminous Bringer" : "Storm Bringer"}` : ""; return `${isDone ? "๐ŸŸก" : "โฌœ"}${e.currentRank}${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."); }