gistfile1.txt
· 2.7 KiB · Text
Raw
export async function handleRankPost(interaction: ChatInputCommandInteraction): Promise<void> {
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" ? Nation.Capella : Nation.Procyon);
return entries.map((e) => {
const isDone = e.tgCount >= goal;
// ── Character indicator ───────────────────────────────────────────────────
const char = CharacterRegistry.find(e.characterName);
console.log(`[rank/post.ts:] char: ${char}`);
const charStr = char ? format.char(char) : `${e.class} ${e.characterName}`;
// const charStr = format.char({ class: e.class, level: 78, name: e.characterName });
// ── Rank indicator ───────────────────────────────────────────────────
const rankStr = format.wrank.rank(e, goal);
const deltaStr = format.wrank.delta(e, { brackets: false });
// ── Bringer label ────────────────────────────────────────────────────
const bringerStr = bringer === e.userKey && isDone
? ` · ${nation === "capella" ? "Luminous Bringer" : "Storm Bringer"}`
: "";
// ── Score indicator ───────────────────────────────────────────────────
const scoreStr = format.score(e.weeklyPoints);
return `${rankStr}(${deltaStr}) ${charStr} — ${scoreStr} ${bringerStr}`;
}).join("\n");
// return `${rankStr}(${deltaStr}) ${e.characterName} — ${e.weeklyPoints} pts (${e.tgCount}/${goal}${bringerStr})`;
// }).join("\n");
};
const embed = new EmbedBuilder()
.setTitle(`⚔️ TG Leaderboard — ${weekKey}`)
.setColor(0xe8a317)
.addFields(
{ name: format.nation("Capella"), value: formatNation("capella"), inline: true },
{ name: format.nation("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.");
}
| 1 | export 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 | } |