30 lines
No EOL
1.3 KiB
TypeScript
30 lines
No EOL
1.3 KiB
TypeScript
import { ChatInputCommandInteraction, TextChannel } from "discord.js";
|
|
import { cfg } from "@systems/config";
|
|
import { polls, lockPoll, updatePollMessage } from "@systems/poll";
|
|
import { replyAndDelete } from "@utils";
|
|
|
|
export async function handleLock(interaction: ChatInputCommandInteraction): Promise<void> {
|
|
const oneTimeMsg = interaction.options.getString("message") ?? undefined;
|
|
const simulateClose = interaction.options.getBoolean("simulate_close") ?? false;
|
|
const slot = getActiveSlot();
|
|
if (slot === undefined) return void replyAndDelete(interaction, "❌ No active poll found.");
|
|
|
|
// Use lockPoll() so lockedYesKeys gets snapshotted — same path as the cron
|
|
lockPoll(slot);
|
|
|
|
const channel = await interaction.client.channels.fetch(cfg("pollChannelId")) as TextChannel;
|
|
|
|
if (simulateClose) {
|
|
// Simulate TG end: show Submit Score button (same path as onPollClose cron)
|
|
await updatePollMessage(channel, slot, oneTimeMsg, true);
|
|
return void replyAndDelete(interaction, "🔒 Poll locked + 📊 Submit Score button shown (simulate close).");
|
|
}
|
|
|
|
// Normal lock: voting closes, no submit button yet
|
|
await updatePollMessage(channel, slot, oneTimeMsg);
|
|
return void replyAndDelete(interaction, "🔒 Poll locked.");
|
|
}
|
|
|
|
function getActiveSlot(): number | undefined {
|
|
return [...polls.keys()][0];
|
|
} |