/** * Leaderboard highlights โ€” secondary embed with weekly standout stats. * Most kills, most deaths, next bringer per nation, etc. */ import { EmbedBuilder } from "discord.js"; import { Nation } from "@types"; import { Emoji } from "@systems/emojis"; import { Config } from "@systems/config"; import { LeaderboardRow } from "./index"; function topByKills(rows: LeaderboardRow[]): LeaderboardRow | null { return [...rows].sort((a, b) => b.totalKills - a.totalKills)[0] ?? null; } function topByDeaths(rows: LeaderboardRow[]): LeaderboardRow | null { return [...rows].sort((a, b) => b.totalDeaths - a.totalDeaths)[0] ?? null; } function nextBringerCandidate(rows: LeaderboardRow[], goal: number): LeaderboardRow | null { // Rank 1 with goal TGs met is eligible โ€” pick the rank-1 player if they qualify const rank1 = rows.find((r) => r.position?.currentRank === 1); if (!rank1) return null; return rank1.tgCount >= goal ? rank1 : null; } export function buildHighlightsEmbed(allRows: LeaderboardRow[], weekKey: string): EmbedBuilder { const goal = Config.get({ section: "wrank", key: "goal" }); const capellaRows = allRows.filter((r) => r.character.nation === Nation.Capella); const procyonRows = allRows.filter((r) => r.character.nation === Nation.Procyon); const topKillsCapella = topByKills(capellaRows); const topKillsProcyon = topByKills(procyonRows); const topDeathsAll = topByDeaths(allRows); // Storm Bringer -> Procyon, Luminous Bringer -> Capella const nextLuminousBringer = nextBringerCandidate(capellaRows, goal); // Capella const nextStormBringer = nextBringerCandidate(procyonRows, goal); // Procyon const capellaEmoji = Emoji.get("capella"); const procyonEmoji = Emoji.get("procyon"); const killEmoji = Emoji.get("wrank_down_1") || "โš”๏ธ"; const deathEmoji = Emoji.get("wrank_up_1") || "๐Ÿ’€"; const stormEmoji = Emoji.get("storm_bringer") || "โšก"; const luminousEmoji = Emoji.get("luminous_bringer") || "๐ŸŒŸ"; const lines: string[] = []; if (topKillsCapella && topKillsCapella.totalKills > 0) { lines.push(`${killEmoji} Most Kills (${capellaEmoji}): **${topKillsCapella.character.name}** (${topKillsCapella.totalKills})`); } if (topKillsProcyon && topKillsProcyon.totalKills > 0) { lines.push(`${killEmoji} Most Kills (${procyonEmoji}): **${topKillsProcyon.character.name}** (${topKillsProcyon.totalKills})`); } if (topDeathsAll && topDeathsAll.totalDeaths > 0) { lines.push(`${deathEmoji} Most Deaths: **${topDeathsAll.character.name}** (${topDeathsAll.totalDeaths})`); } lines.push(""); // spacer lines.push(`${luminousEmoji} Next Luminous Bringer (${capellaEmoji}): ${nextLuminousBringer ? `**${nextLuminousBringer.character.name}**` : "โ€”"}`); lines.push(`${stormEmoji} Next Storm Bringer (${procyonEmoji}): ${nextStormBringer ? `**${nextStormBringer.character.name}**` : "โ€”"}`); return new EmbedBuilder() .setTitle("๐Ÿ“Š Weekly Highlights") .setColor(0x5865f2) .setDescription(lines.join("\n")) .setFooter({ text: `Highlights ยท ${weekKey}` }); }