Last active 3 weeks ago

gistfile1.txt Raw
1export async function handleRankPost(interaction: ChatInputCommandInteraction): Promise<void> {
2 const week = getCurrentWeek();
3 const goal = cfg("wRankGoal");
4 const weekKey = getWeekKey();
5
6 const formatNation = (nation: "capella" | "procyon"): string => {
7 const entries = [...week.entries[nation]].sort((a, b) => a.currentRank - b.currentRank);
8 if (entries.length === 0) return "—";
9
10 const bringer = getBringer(nation === "capella" ? Nation.Capella : Nation.Procyon);
11
12 return entries.map((e) => {
13 const isDone = e.tgCount >= goal;
14
15 // ── Character indicator ───────────────────────────────────────────────────
16 const char = CharacterRegistry.find(e.characterName);
17 console.log(`[rank/post.ts:] char: ${char}`);
18 const charStr = char ? format.char(char) : `${e.class} ${e.characterName}`;
19 // const charStr = format.char({ class: e.class, level: 78, name: e.characterName });
20
21 // ── Rank indicator ───────────────────────────────────────────────────
22 const rankStr = format.wrank.rank(e, goal);
23 const deltaStr = format.wrank.delta(e, { brackets: false });
24
25 // ── Bringer label ────────────────────────────────────────────────────
26 const bringerStr = bringer === e.userKey && isDone
27 ? ` · ${nation === "capella" ? "Luminous Bringer" : "Storm Bringer"}`
28 : "";
29
30 // ── Score indicator ───────────────────────────────────────────────────
31 const scoreStr = format.score(e.weeklyPoints);
32
33 return `${rankStr}(${deltaStr}) ${charStr} — ${scoreStr} ${bringerStr}`;
34 }).join("\n");
35 // return `${rankStr}(${deltaStr}) ${e.characterName} — ${e.weeklyPoints} pts (${e.tgCount}/${goal}${bringerStr})`;
36 // }).join("\n");
37 };
38
39 const embed = new EmbedBuilder()
40 .setTitle(`⚔️ TG Leaderboard — ${weekKey}`)
41 .setColor(0xe8a317)
42 .addFields(
43 { name: format.nation("Capella"), value: formatNation("capella"), inline: true },
44 { name: format.nation("Procyon"), value: formatNation("procyon"), inline: true },
45 )
46 .setTimestamp();
47
48 const channelId = cfg("resultsChannelId") || cfg("pollChannelId");
49 const channel = await interaction.client.channels.fetch(channelId) as TextChannel;
50 await channel.send({ embeds: [embed] });
51 return void replyAndDelete(interaction, "✅ Leaderboard posted.");
52}