141 lines
4.9 KiB
JavaScript
141 lines
4.9 KiB
JavaScript
const { Events, EmbedBuilder, PermissionFlagsBits } = require('discord.js');
|
|
const chalk = require('chalk');
|
|
const db = require('../functions/database/db.js');
|
|
const { colors } = require('../utils/constants');
|
|
|
|
module.exports = {
|
|
name: Events.InteractionCreate,
|
|
async execute(interaction) {
|
|
// Gérer la soumission des modals (ex: candidature staff)
|
|
if (interaction.isModalSubmit()) {
|
|
const ticketModule = require('../commands/ticket/ticket.js');
|
|
if (interaction.customId === 'candidature_modal') {
|
|
await ticketModule.handleCandidatureModalSubmit(interaction);
|
|
return;
|
|
}
|
|
}
|
|
|
|
// Gérer les boutons
|
|
if (interaction.isButton()) {
|
|
// Création de ticket via bouton
|
|
if (interaction.customId === 'ticket_create_candidature') {
|
|
// Sur clic, montrer le modal candidature, sans ticket encore
|
|
const { ModalBuilder, TextInputBuilder, TextInputStyle, ActionRowBuilder } = require('discord.js');
|
|
const questions = require('../commands/ticket/ticket.js').CANDIDATURE_QUESTIONS;
|
|
const modal = new ModalBuilder()
|
|
.setCustomId('candidature_modal')
|
|
.setTitle('Candidature Staff (5 max)');
|
|
for(let i = 0; i < Math.min(questions.length,5); i++) {
|
|
const input = new TextInputBuilder()
|
|
.setCustomId(`cand_q${i+1}`)
|
|
.setLabel(questions[i].slice(0, 45))
|
|
.setStyle(TextInputStyle.Paragraph)
|
|
.setRequired(true)
|
|
.setMaxLength(1000);
|
|
modal.addComponents(new ActionRowBuilder().addComponents(input));
|
|
}
|
|
await interaction.showModal(modal);
|
|
return;
|
|
}
|
|
if (interaction.customId.startsWith('ticket_create_')) {
|
|
const ticketCommand = interaction.client.commands.get('ticket');
|
|
if (ticketCommand) {
|
|
const ticketModule = require('../commands/ticket/ticket.js');
|
|
await ticketModule.handleCreate(interaction);
|
|
}
|
|
return;
|
|
}
|
|
|
|
// Fermeture de ticket via bouton
|
|
if (interaction.customId.startsWith('ticket_close_')) {
|
|
try {
|
|
const ticketModule = require('../commands/ticket/ticket.js');
|
|
await ticketModule.handleClose(interaction);
|
|
|
|
// Désactiver le bouton après la fermeture
|
|
try {
|
|
const { ActionRowBuilder, ButtonBuilder } = require('discord.js');
|
|
const oldRow = interaction.message.components[0];
|
|
if (oldRow && oldRow.components.length > 0) {
|
|
const newRow = new ActionRowBuilder();
|
|
for (const component of oldRow.components) {
|
|
if (component.customId === interaction.customId) {
|
|
newRow.addComponents(
|
|
ButtonBuilder.from(component).setDisabled(true)
|
|
);
|
|
} else {
|
|
newRow.addComponents(component);
|
|
}
|
|
}
|
|
await interaction.message.edit({ components: [newRow] });
|
|
}
|
|
} catch (buttonErr) {
|
|
console.error('⚠️ Erreur lors de la désactivation du bouton:', buttonErr);
|
|
}
|
|
} catch (err) {
|
|
console.error('Erreur lors de la fermeture du ticket via bouton:', err);
|
|
if (!interaction.replied && !interaction.deferred) {
|
|
await interaction.reply({
|
|
content: '❌ Erreur lors de la fermeture du ticket.',
|
|
ephemeral: true
|
|
});
|
|
} else {
|
|
await interaction.editReply({
|
|
content: '❌ Erreur lors de la fermeture du ticket.'
|
|
});
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
|
|
// Suppression de ticket via bouton
|
|
if (interaction.customId.startsWith('ticket_delete_')) {
|
|
try {
|
|
const ticketModule = require('../commands/ticket/ticket.js');
|
|
await ticketModule.handleDelete(interaction);
|
|
} catch (err) {
|
|
console.error('Erreur lors de la suppression du ticket via bouton:', err);
|
|
if (!interaction.replied && !interaction.deferred) {
|
|
await interaction.reply({
|
|
content: '❌ Erreur lors de la suppression du ticket.',
|
|
ephemeral: true
|
|
});
|
|
} else {
|
|
await interaction.editReply({
|
|
content: '❌ Erreur lors de la suppression du ticket.'
|
|
});
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
|
|
// Gérer les commandes slash
|
|
if (!interaction.isChatInputCommand()) return;
|
|
|
|
const command = interaction.client.commands.get(interaction.commandName);
|
|
|
|
if (!command) {
|
|
console.error(chalk.red(`❌ Aucune commande correspondant à ${interaction.commandName} n'a été trouvée.`));
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await command.execute(interaction);
|
|
console.log(chalk.green(`✅ ${interaction.user.tag} a utilisé la commande /${interaction.commandName}`));
|
|
} catch (error) {
|
|
console.error(chalk.red(`❌ Erreur lors de l'exécution de la commande ${interaction.commandName}:`), error);
|
|
|
|
const errorMessage = {
|
|
content: '❌ Une erreur est survenue lors de l\'exécution de cette commande !',
|
|
ephemeral: true
|
|
};
|
|
|
|
if (interaction.replied || interaction.deferred) {
|
|
await interaction.followUp(errorMessage).catch(() => null);
|
|
} else {
|
|
await interaction.reply(errorMessage).catch(() => null);
|
|
}
|
|
}
|
|
},
|
|
}; |