From 8de41e806c3db23cf0f809e33ca041249c958551 Mon Sep 17 00:00:00 2001 From: VALOU3336 Date: Fri, 16 Feb 2024 23:47:07 +0100 Subject: [PATCH] add util commande --- commands/utils/channel.js | 25 +++++++++++ commands/utils/help.js | 2 +- commands/utils/helpall.js | 89 ++++++++++++++++++++++++++++++++++++++ commands/utils/roleinfo.js | 40 +++++++++++++++++ 4 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 commands/utils/channel.js create mode 100644 commands/utils/helpall.js create mode 100644 commands/utils/roleinfo.js diff --git a/commands/utils/channel.js b/commands/utils/channel.js new file mode 100644 index 0000000..5c2d0c9 --- /dev/null +++ b/commands/utils/channel.js @@ -0,0 +1,25 @@ +const { EmbedBuilder } = require('discord.js'); + +module.exports = { + name: 'channel', + description: 'Affiche les informations sur un salon', + async execute(message) { + const channel = message.mentions.channels.first() || message.channel; + + if (!channel || !channel.viewable) { + return message.reply('Je ne peux pas accéder à ce salon.'); + } + const embed = new EmbedBuilder() + .setTitle(`Informations sur le salon **${channel.name}**`) + .addFields( + { name: '**Nom**', value: `<#${channel.id}>`, inline: true }, + { name: '**ID**', value: channel.id, inline: true }, + { name: '**NSFW**', value: channel.nsfw ? '✅' : '❌', inline: true }, + { name: '**Mode Lent**', value: channel.rateLimitPerUser ? `${channel.rateLimitPerUser} secondes` : '❌', inline: true }, + { name: '**Créé le**', value: ``, inline: true } + ) + .setColor('#0099ff'); + + message.channel.send({ embeds: [embed] }); + }, +}; \ No newline at end of file diff --git a/commands/utils/help.js b/commands/utils/help.js index aebb9c8..1a0da5e 100644 --- a/commands/utils/help.js +++ b/commands/utils/help.js @@ -8,9 +8,9 @@ module.exports = { emote: '📚', utilisation: 'help [commande]', async execute(message, args, client) { - const defaultprefix = "+"; 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; diff --git a/commands/utils/helpall.js b/commands/utils/helpall.js new file mode 100644 index 0000000..e1320c9 --- /dev/null +++ b/commands/utils/helpall.js @@ -0,0 +1,89 @@ +const { EmbedBuilder , ButtonBuilder, ButtonStyle, ActionRowBuilder } = require('discord.js'); +const db = require('quick.db'); +const GestionDb = new db.table("gestion"); + +module.exports = { + name: 'helpall', + description: 'Liste toutes les commandes disponibles par niveau de permission', + 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: [] })); + }, +}; \ No newline at end of file diff --git a/commands/utils/roleinfo.js b/commands/utils/roleinfo.js new file mode 100644 index 0000000..4e63e72 --- /dev/null +++ b/commands/utils/roleinfo.js @@ -0,0 +1,40 @@ +const { EmbedBuilder, PermissionsBitField } = require('discord.js'); + +module.exports = { + name: 'roleinfo', + description: 'Affiche les informations sur un rôle', + async execute(message, args) { + if (args.length === 0) { + return message.reply('Veuillez mentionner un rôle.'); + } + + const role = message.mentions.roles.first(); + if (!role) { + return message.reply('Veuillez mentionner un rôle valide.'); + } + + const embed = new EmbedBuilder() + .setTitle(`Informations sur le rôle ${role.name}`) + .addFields( + { name: 'ID', value: role.id, inline: true }, + { name: 'Nom', value: role.name, inline: true }, + { name: 'Couleur', value: role.hexColor, inline: true }, + { name: 'Membres', value: role.members.size.toString(), inline: true }, + { name: 'Position', value: role.position.toString(), inline: true }, + { name: 'Mentionnable', value: role.mentionable ? 'Oui' : 'Non', inline: true }, + { name: 'Géré par une intégration', value: role.managed ? 'Oui' : 'Non', inline: true } + ) + .setColor(role.hexColor); + + if (role.permissions.has(PermissionsBitField.Flags.Administrator)) { + embed.addFields({ name: 'Permissions', value: 'Administrateur', inline: true }); + } else { + const permissions = role.permissions.toArray(); + if (permissions.length > 0) { + embed.addFields({ name: 'Permissions', value: permissions.join(', '), inline: true }); + } + } + + message.channel.send({ embeds: [embed] }); + }, +}; \ No newline at end of file