Files
gestion/commands/utils/helpall.js
T
2024-02-17 13:33:46 +01:00

94 lines
3.7 KiB
JavaScript

const { EmbedBuilder , ButtonBuilder, ButtonStyle, ActionRowBuilder } = require('discord.js');
const db = require('quick.db');
const GestionDb = new db.table("gestion");
module.exports = {
name: 'helpall',
aliases: ['hall', 'aideall'],
description: 'Liste toutes les commandes disponibles par niveau de permission',
emote: '📚',
utilisation: 'helpall',
category: 'utils',
async execute(message, args, client) {
const botId = client.user.id;
const guildId = message.guild.id;
const defaultprefix = "+";
let mainPrefix = await GestionDb.get(`${botId}.prefix`);
let serverPrefix = await GestionDb.get(`${botId}.${guildId}.prefix`);
const prefix = serverPrefix !== undefined ? serverPrefix : mainPrefix !== undefined ? mainPrefix : defaultprefix;
const permissions = GestionDb.get(`${botId}.permissions`);
const commandsByPermission = {};
for (const [commandName, permissionLevel] of Object.entries(permissions)) {
if (!commandsByPermission[permissionLevel]) {
commandsByPermission[permissionLevel] = [];
}
commandsByPermission[permissionLevel].push(commandName);
}
const embeds = Object.entries(commandsByPermission).sort(([a], [b]) => a - b).map(([permissionLevel, commands]) => {
const commandDescriptions = commands.map(commandName => {
const command = client.commands.get(commandName);
if (!command) {
return null;
}
return `**${prefix}${commandName}**\n\`${command.description}\``;
}).filter(Boolean);
const embed = new EmbedBuilder()
.setTitle(`Commandes de niveau de permission ${permissionLevel === '10' ? 'Owner' : permissionLevel === '11' ? 'Buyer' : permissionLevel}`)
.setColor('#0099ff');
if (commandDescriptions.length > 0) {
embed.setDescription(commandDescriptions.join('\n'));
} else {
embed.setDescription('Aucune commande disponible pour ce niveau de permission.');
}
return embed;
});
const backButton = new ButtonBuilder()
.setCustomId('back')
.setLabel('⬅️')
.setStyle(ButtonStyle.Primary);
const nextButton = new ButtonBuilder()
.setCustomId('next')
.setLabel('➡️')
.setStyle(ButtonStyle.Primary);
// Create the action row with the buttons
const row = new ActionRowBuilder()
.addComponents(backButton, nextButton);
const msg = await message.channel.send({ embeds: [embeds[0]], components: [row] });
const collector = msg.createMessageComponentCollector({
filter: (interaction) => interaction.isButton() && interaction.user.id === message.author.id,
time: 60000
});
let currentPage = 0;
collector.on('collect', async (interaction) => {
// Acknowledge the interaction
await interaction.deferUpdate();
if (!interaction.isButton()) return;
if (interaction.customId === 'back') {
currentPage = currentPage > 0 ? --currentPage : embeds.length - 1;
} else if (interaction.customId === 'next') {
currentPage = currentPage + 1 < embeds.length ? ++currentPage : 0;
}
// Update the message with the new embed and the action row with buttons
await msg.edit({ embeds: [embeds[currentPage]], components: [row] });
});
collector.on('end', () => msg.edit({ embeds: [embeds[currentPage]], components: [] }));
},
};