feat(tickets): implement the ticket service, command and channel controls

Each ticket category is visible to a different set of staff roles, and the claim and close actions must also be reachable from the channel itself, so the buttons live in the ticket and share the service checks.
This commit is contained in:
BlackAngelTV committed 2026-09-15 14:50:47 +02:00
1 parent a5280ce205
commit e8c95b2ba3
3 files changed
+353 -18

No files matched your search

+31 -6
View File
@@ -1,6 +1,12 @@
import { SlashCommandBuilder } from 'discord.js';
import { MessageFlags, SlashCommandBuilder } from 'discord.js';
import { ACCESS_LEVELS, TICKET_CATEGORIES } from '../../config/constants.js';
import { notImplementedEmbed } from '../../ui/embeds.js';
import {
addParticipant,
claimTicket,
closeTicket,
createTicket,
} from '../../services/tickets/ticket-service.js';
import { successEmbed } from '../../ui/embeds.js';
export const access = ACCESS_LEVELS.USER;
// `close` is also allowed for the ticket author: checked in the ticket service.
@@ -35,9 +41,28 @@ export const data = new SlashCommandBuilder()
.addUserOption((option) => option.setName('user').setDescription('Membre à ajouter').setRequired(true)),
);
// TODO(M6-T03..T09): implement with a ticket service backed by the tickets table.
/** Ticket lifecycle: each subcommand acts on a private channel (M6-T03..T09). */
export async function execute(interaction) {
await interaction.reply({
embeds: [notImplementedEmbed(`/ticket ${interaction.options.getSubcommand()}`)],
});
switch (interaction.options.getSubcommand()) {
case 'create': {
const categoryId = interaction.options.getString('category', true);
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
const channel = await createTicket(interaction, categoryId);
await interaction.editReply({
embeds: [successEmbed(`Ton ticket est ouvert : <#${channel.id}>`)],
});
return;
}
case 'close':
await closeTicket(interaction, interaction.options.getString('reason'));
return;
case 'claim':
await claimTicket(interaction);
return;
case 'add':
await addParticipant(interaction, interaction.options.getUser('user', true).id);
return;
default:
return;
}
}