Update Bot
This commit is contained in:
@@ -1,119 +1,141 @@
|
||||
const { Events, ModalBuilder, TextInputBuilder, TextInputStyle, ActionRowBuilder, MessageFlags } = require('discord.js');
|
||||
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) {
|
||||
try {
|
||||
// --- 1. GESTION DES MODALS (Soumission) ---
|
||||
if (interaction.isModalSubmit()) {
|
||||
const ticketModule = require('../commands/ticket/ticket.js');
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// 1.A - Création de Ticket (Support, Plainte, etc.)
|
||||
if (interaction.customId.startsWith('ticket_create_modal_')) {
|
||||
// On récupère le type depuis l'ID (ex: ticket_create_modal_Support)
|
||||
const type = interaction.customId.replace('ticket_create_modal_', '');
|
||||
await ticketModule.handleCreate(interaction, type);
|
||||
return;
|
||||
}
|
||||
|
||||
// 1.B - Candidature Spécifique
|
||||
if (interaction.customId === 'candidature_modal') {
|
||||
await ticketModule.handleCandidatureModalSubmit(interaction);
|
||||
return;
|
||||
}
|
||||
|
||||
// 1.C - Raison Fermeture
|
||||
if (interaction.customId === 'ticket_close_reason_modal') {
|
||||
await ticketModule.handleCloseModal(interaction);
|
||||
return;
|
||||
}
|
||||
|
||||
// 1.D - Raison Réouverture
|
||||
if (interaction.customId === 'ticket_reopen_modal') {
|
||||
await ticketModule.handleReopenModal(interaction);
|
||||
return;
|
||||
}
|
||||
|
||||
// 1.E - Raison Suppression
|
||||
if (interaction.customId === 'ticket_delete_modal') {
|
||||
await ticketModule.handleDeleteModal(interaction);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// --- 2. GESTION DES BOUTONS (Ouverture des Modals) ---
|
||||
if (interaction.isButton()) {
|
||||
const ticketModule = require('../commands/ticket/ticket.js');
|
||||
|
||||
// 2.A - Bouton Création : On ouvre un MODAL pour tout le monde
|
||||
if (interaction.customId.startsWith('ticket_create_')) {
|
||||
|
||||
// Cas Spécial : Candidature (Déjà géré avec ses questions spécifiques)
|
||||
if (interaction.customId === 'ticket_create_candidature') {
|
||||
const questions = require('../commands/ticket/ticket.js').CANDIDATURE_QUESTIONS;
|
||||
const modal = new ModalBuilder().setCustomId('candidature_modal').setTitle('Recrutement Staff');
|
||||
for(let i=0; i<Math.min(questions.length,5); i++) {
|
||||
const input = new TextInputBuilder().setCustomId(`cand_q${i+1}`).setLabel(questions[i].substring(0,45)).setStyle(TextInputStyle.Paragraph).setRequired(true);
|
||||
modal.addComponents(new ActionRowBuilder().addComponents(input));
|
||||
}
|
||||
await interaction.showModal(modal);
|
||||
return;
|
||||
}
|
||||
|
||||
// Cas Général (Support, Plainte, etc.): Modal simple "Sujet"
|
||||
// On extrait le type du bouton (ex: ticket_create_support -> support)
|
||||
let typeKey = interaction.customId.replace('ticket_create_', '');
|
||||
// On remet en joli format (support -> Support, plainte_staff -> Plainte Staff)
|
||||
const typeMapping = {
|
||||
'support': 'Support',
|
||||
'plainte': 'Plainte',
|
||||
'plainte_staff': 'Plainte Staff',
|
||||
'probleme_technique': 'Problème Technique'
|
||||
};
|
||||
const prettyType = typeMapping[typeKey] || 'Support';
|
||||
|
||||
// On passe le type dans l'ID du modal pour le récupérer au submit
|
||||
const modal = new ModalBuilder()
|
||||
.setCustomId(`ticket_create_modal_${prettyType}`)
|
||||
.setTitle(`Nouveau ticket : ${prettyType}`);
|
||||
|
||||
const subjectInput = new TextInputBuilder()
|
||||
.setCustomId('ticket_subject')
|
||||
.setLabel("Sujet / Raison de la demande")
|
||||
.setStyle(TextInputStyle.Paragraph)
|
||||
.setRequired(true)
|
||||
.setMaxLength(1000)
|
||||
.setPlaceholder("Décrivez brièvement votre problème...");
|
||||
|
||||
modal.addComponents(new ActionRowBuilder().addComponents(subjectInput));
|
||||
await interaction.showModal(modal);
|
||||
return;
|
||||
}
|
||||
|
||||
// 2.B - Autres actions (Fermer, Réouvrir, etc.)
|
||||
if (interaction.customId.startsWith('ticket_close_')) return await ticketModule.handleClose(interaction);
|
||||
if (interaction.customId.startsWith('ticket_delete_')) return await ticketModule.handleDelete(interaction);
|
||||
if (interaction.customId.startsWith('ticket_reopen_')) return await ticketModule.handleReopen(interaction);
|
||||
if (interaction.customId.startsWith('ticket_claim_')) return await ticketModule.handleClaim(interaction);
|
||||
}
|
||||
|
||||
// --- 3. 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;
|
||||
}
|
||||
await command.execute(interaction);
|
||||
|
||||
} catch (error) {
|
||||
console.error(chalk.red(`Erreur lors de l'exécution d'une interaction :`), error);
|
||||
if (interaction.replied || interaction.deferred) {
|
||||
await interaction.followUp({ content: 'Une erreur est survenue lors de l\'exécution de cette interaction !', flags: MessageFlags.Ephemeral });
|
||||
} else {
|
||||
await interaction.reply({ content: 'Une erreur est survenue lors de l\'exécution de cette interaction !', flags: MessageFlags.Ephemeral });
|
||||
}
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user