Última actividad 3 weeks ago

gistfile1.txt Sin formato
1export async function handleResultPost(interaction: ChatInputCommandInteraction): Promise<void> {
2 const slotArg = interaction.options.getString("slot");
3
4 let slot: number | null = null;
5 if (slotArg) {
6 slot = normalizeSlot(slotArg);
7 if (slot === null) return void replyAndDelete(interaction, `❌ Could not parse slot "${slotArg}".`);
8 } else {
9 slot = detectSlot() ?? cfg("slots")[0]?.tgHour ?? 20;
10 }
11
12 const result = loadResult(todayString(), slot);
13 if (!result) return void replyAndDelete(interaction, `❌ No result found for ${slot}:00 TG.`);
14
15 const kd = result.nationKD;
16
17 const formatScores = (nation: "Capella" | "Procyon"): string => {
18 const scores = result.scores.filter((s) => s.nation === nation);
19 if (scores.length === 0) return "—";
20 return scores
21 .sort((a, b) => b.pts - a.pts)
22 .map((s) => `**${s.characterName}** (${s.class}) — ${s.pts} pts`)
23 .join("\n");
24 };
25
26 const embed = new EmbedBuilder()
27 .setTitle(`⚔️ TG Results — ${result.date} ${slot}:00`)
28 .setColor(0xe8a317)
29 .addFields(
30 { name: "🔵 Capella", value: `${kd.capella.k}K / ${kd.capella.d}D\n${formatScores("Capella")}`, inline: true },
31 { name: "🔴 Procyon", value: `${kd.procyon.k}K / ${kd.procyon.d}D\n${formatScores("Procyon")}`, inline: true },
32 )
33 .setFooter({ text: `Source of truth: ${kd.source}` })
34 .setTimestamp();
35
36 const channelId = cfg("resultsChannelId") || cfg("pollChannelId");
37 const channel = await interaction.client.channels.fetch(channelId) as TextChannel;
38 await channel.send({ embeds: [embed] });
39 return void replyAndDelete(interaction, "✅ Results posted.");
40}