import { ChatInputCommandInteraction, TextChannel } from "discord.js"; import { Config } from "@systems/config"; import { polls, updatePollMessage } from "@systems/poll"; import { persist } from "@systems/pollPersistence"; import { hasOfficerRole } from "@systems/users"; import { Discord } from "@discord"; import { replyAndDelete } from "@utils"; export async function handleCall(interaction: ChatInputCommandInteraction): Promise { const member = await interaction.guild!.members.fetch(interaction.user.id); const callRoles = Config.get({ section: "roles", key: "callGame" }); if (!hasOfficerRole(member, callRoles)) { return void replyAndDelete(interaction, "❌ You don't have permission to call TG.", true); } const opts = Discord.Interaction.options(interaction); const slot = opts.integer({ key: "slot", required: true })!; const state = polls.get(slot); if (!state) { return void replyAndDelete(interaction, `❌ No active poll for ${slot}:00.`, true); } if (!state.locked) { return void replyAndDelete(interaction, "❌ Poll must be locked before calling TG.", true); } state.called = true; state.calledAt = new Date().toISOString(); // Calling TG ends it immediately — open score submission the same way the // scheduled tgHour+closesAfter close normally does. state.scoreSubmitOpen = true; persist.save(polls); const channel = interaction.channel as TextChannel; await updatePollMessage(channel, slot, undefined, true); return void replyAndDelete(interaction, `✅ TG at ${slot}:00 has been called — Submit Score is now open.`, true); } export const CallCommands = { call: handleCall, };