feat(polls): implement polls, fun and statistics commands

A poll must end even when nobody is there to close it, so a scheduler reads the stored end dates and finalises the results at startup and while running.
This commit is contained in:
BlackAngelTV committed 2026-09-15 14:50:54 +02:00
1 parent f29c09577a
commit ef1bedbc65
6 files changed
+514 -14

No files matched your search

+19 -4
View File
@@ -1,6 +1,7 @@
import { SlashCommandBuilder } from 'discord.js';
import { MessageFlags, SlashCommandBuilder } from 'discord.js';
import { ACCESS_LEVELS } from '../../config/constants.js';
import { notImplementedEmbed } from '../../ui/embeds.js';
import { buildPollEmbed, closePollById, createPoll } from '../../services/polls/poll-service.js';
import { successEmbed } from '../../ui/embeds.js';
export const access = ACCESS_LEVELS.STAFF;
@@ -28,7 +29,21 @@ export const data = new SlashCommandBuilder()
.addIntegerOption((option) => option.setName('id').setDescription('ID du sondage').setRequired(true)),
);
// TODO(M10-T01..T06): implement with polls / poll_votes tables.
/** Polls are published in the current channel and voted with buttons (M10). */
export async function execute(interaction) {
await interaction.reply({ embeds: [notImplementedEmbed(`/poll ${interaction.options.getSubcommand()}`)] });
if (interaction.options.getSubcommand() === 'close') {
const poll = await closePollById(interaction.client, interaction.options.getInteger('id', true));
await interaction.reply({ embeds: [buildPollEmbed(poll)] });
return;
}
const question = interaction.options.getString('question', true);
const choicesInput = interaction.options.getString('choices', true);
const minutes = interaction.options.getInteger('minutes');
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
const pollId = await createPoll(interaction, { question, choicesInput, minutes });
await interaction.editReply({
embeds: [successEmbed(`Sondage **#${pollId}** publié dans <#${interaction.channelId}>.`)],
});
}