lock.ts
· 871 B · TypeScript
Brut
import { ChatInputCommandInteraction, TextChannel } from "discord.js";
import { cfg } from "../../systems/config";
import { polls, updatePollMessage } from "../../systems/poll";
import { replyAndDelete } from "../../utils";
export async function handleLock(interaction: ChatInputCommandInteraction): Promise<void> {
const oneTimeMsg = interaction.options.getString("message") ?? undefined;
const slot = getActiveSlot();
if (!slot) return void replyAndDelete(interaction, "❌ No active poll found.");
const state = polls.get(slot)!;
state.locked = true;
const channel = await interaction.client.channels.fetch(cfg("pollChannelId")) as TextChannel;
await updatePollMessage(channel, slot, oneTimeMsg);
return void replyAndDelete(interaction, "🔒 Poll locked.");
}
function getActiveSlot(): number | undefined {
return [...polls.keys()][0];
}
| 1 | import { ChatInputCommandInteraction, TextChannel } from "discord.js"; |
| 2 | import { cfg } from "../../systems/config"; |
| 3 | import { polls, updatePollMessage } from "../../systems/poll"; |
| 4 | import { replyAndDelete } from "../../utils"; |
| 5 | |
| 6 | export 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 | |
| 19 | function getActiveSlot(): number | undefined { |
| 20 | return [...polls.keys()][0]; |
| 21 | } |
| 22 |