Ultima attività 1 month ago

Revisione e252de9673a7ddad8f17da2b035bd6f8aedafcaa

lock.ts Raw
1import { ChatInputCommandInteraction, TextChannel } from "discord.js";
2import { cfg } from "../../systems/config";
3import { polls, updatePollMessage } from "../../systems/poll";
4import { replyAndDelete } from "../../utils";
5
6export async function handleLock(interaction: ChatInputCommandInteraction): Promise<void> {
7 const oneTimeMsg = interaction.options.getString("message") ?? undefined;
8 const slot = getActiveSlot();
9 if (!slot) return void replyAndDelete(interaction, "❌ No active poll found.");
10
11 const state = polls.get(slot)!;
12 state.locked = true;
13
14 const channel = await interaction.client.channels.fetch(cfg("pollChannelId")) as TextChannel;
15 await updatePollMessage(channel, slot, oneTimeMsg);
16 return void replyAndDelete(interaction, "🔒 Poll locked.");
17}
18
19function getActiveSlot(): number | undefined {
20 return [...polls.keys()][0];
21}
22