31 lines
1.3 KiB
TypeScript
31 lines
1.3 KiB
TypeScript
import { ChatInputCommandInteraction } from "discord.js";
|
|
import { Config } from "../../systems/config";
|
|
import { loadResult, todayString } from "../../systems/history";
|
|
import { normalizeSlot, detectSlot } from "../../systems/scores";
|
|
import { replyAndDelete } from "../../utils";
|
|
|
|
export async function handleResultView(interaction: ChatInputCommandInteraction): Promise<void> {
|
|
const slotArg = interaction.options.getString("slot");
|
|
|
|
let slot: number | null = null;
|
|
if (slotArg) {
|
|
slot = normalizeSlot(slotArg);
|
|
if (slot === null) return void replyAndDelete(interaction, `❌ Could not parse slot "${slotArg}".`);
|
|
} else {
|
|
slot = detectSlot() ?? Config.get({ section: "poll", key: "slots" })[0]?.tgHour ?? 20;
|
|
}
|
|
|
|
const result = loadResult(todayString(), slot);
|
|
if (!result) return void replyAndDelete(interaction, `❌ No result found for ${slot}:00 TG today.`);
|
|
|
|
const kd = result.nationKD;
|
|
const lines = [
|
|
`**TG ${slot}:00 — ${result.date}**`,
|
|
`**Capella:** ${kd.capella.k}K / ${kd.capella.d}D`,
|
|
`**Procyon:** ${kd.procyon.k}K / ${kd.procyon.d}D`,
|
|
`**Scores submitted:** ${result.scores.length}`,
|
|
result.scores.map((s) => `• ${s.characterName} (${s.class}) — ${s.pts} pts`).join("\n"),
|
|
].join("\n");
|
|
|
|
return void replyAndDelete(interaction, lines);
|
|
}
|