Son aktivite 1 month ago

Revizyon 576352f16730dcaa69794b2ac1aa71e2f4aee6e8

post.ts Ham
1import { ChatInputCommandInteraction, TextChannel, EmbedBuilder } from "discord.js";
2import { cfg } from "../../systems/config";
3import { getCurrentWeek, getWeekKey, getBringer } from "../../systems/wrank";
4import { replyAndDelete } from "../../utils";
5
6export async function handleRankPost(interaction: ChatInputCommandInteraction): Promise<void> {
7 const week = getCurrentWeek();
8 const goal = cfg("wRankGoal");
9 const weekKey = getWeekKey();
10
11 const formatNation = (nation: "capella" | "procyon"): string => {
12 const entries = [...week.entries[nation]].sort((a, b) => a.currentRank - b.currentRank);
13 if (entries.length === 0) return "—";
14 const bringer = getBringer(nation === "capella" ? "Capella" : "Procyon");
15 return entries.map((e) => {
16 const isDone = e.tgCount >= goal;
17 const delta = e.previousRank !== undefined ? e.currentRank - e.previousRank : 0;
18 const deltaStr = delta < 0 ? `${Math.abs(delta)}` : delta > 0 ? `${delta}` : "";
19 const bringerStr = bringer === e.userKey && isDone
20 ? ` · ${nation === "capella" ? "Luminous Bringer" : "Storm Bringer"}`
21 : "";
22 return `${isDone ? "🟡" : "⬜"}${e.currentRank}${deltaStr} «${e.characterName}» — ${e.weeklyPoints} pts (${e.tgCount}/${goal}${bringerStr})`;
23 }).join("\n");
24 };
25
26 const embed = new EmbedBuilder()
27 .setTitle(`⚔️ W.Rank Leaderboard — ${weekKey}`)
28 .setColor(0xe8a317)
29 .addFields(
30 { name: "🔵 Capella", value: formatNation("capella"), inline: true },
31 { name: "🔴 Procyon", value: formatNation("procyon"), inline: true },
32 )
33 .setTimestamp();
34
35 const channelId = cfg("resultsChannelId") || cfg("pollChannelId");
36 const channel = await interaction.client.channels.fetch(channelId) as TextChannel;
37 await channel.send({ embeds: [embed] });
38 return void replyAndDelete(interaction, "✅ Leaderboard posted.");
39}
40