mirror of
https://github.com/arthur-pbty/gestion.git
synced 2026-06-03 15:07:26 +02:00
9bd39c69ca
sinon il y a pleins de truc comme les anti raid , des coorectif ect
119 lines
4.9 KiB
JavaScript
119 lines
4.9 KiB
JavaScript
const { EmbedBuilder , ButtonBuilder, ButtonStyle, ActionRowBuilder } = require('discord.js');
|
|
const sqlite3 = require('sqlite3').verbose();
|
|
const db = new sqlite3.Database('myDatabase.db');
|
|
const { getPermissionLevel } = require('../../fonction/getPermissionLevel');
|
|
module.exports = {
|
|
name: 'helpall',
|
|
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 = "+";
|
|
try {
|
|
let data = await new Promise((resolve, reject) => {
|
|
db.get('SELECT value FROM gestion WHERE id = ?', [botId], (err, row) => {
|
|
if (err) {
|
|
console.error(err.message);
|
|
reject(err);
|
|
}
|
|
resolve(row ? JSON.parse(row.value) : {});
|
|
});
|
|
});
|
|
|
|
const permissions = data.permissions || {};
|
|
const prefix = data.prefix || defaultPrefix;
|
|
|
|
const commandsByPermission = {};
|
|
|
|
for (const [commandName, permissionLevel] of Object.entries(permissions)) {
|
|
if (!commandsByPermission[permissionLevel]) {
|
|
commandsByPermission[permissionLevel] = [];
|
|
}
|
|
commandsByPermission[permissionLevel].push(commandName);
|
|
}
|
|
|
|
|
|
const embeds = Object.entries(commandsByPermission).map(([permissionLevel, commands]) => {
|
|
const commandDescriptions = commands.map(commandName => {
|
|
const command = client.commands.get(commandName);
|
|
if (!command || permissions[command.name] === "off") {
|
|
return null;
|
|
}
|
|
return `* \`${prefix}${command.utilisation}\``;
|
|
}).filter(Boolean);
|
|
|
|
if (commandDescriptions.length === 0) {
|
|
return null;
|
|
}
|
|
|
|
const embedsForPermissionLevel = [];
|
|
let currentEmbedDescription = '';
|
|
commandDescriptions.forEach(description => {
|
|
if ((currentEmbedDescription + description).length <= 4096) {
|
|
currentEmbedDescription += description + '\n';
|
|
} else {
|
|
embedsForPermissionLevel.push(currentEmbedDescription);
|
|
currentEmbedDescription = description + '\n';
|
|
}
|
|
});
|
|
if (currentEmbedDescription) {
|
|
embedsForPermissionLevel.push(currentEmbedDescription);
|
|
}
|
|
|
|
return embedsForPermissionLevel.map(description => {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle(`Commandes de niveau de permission ${permissionLevel === '0' ? "public" : permissionLevel === '10' ? "owner" : permissionLevel === '11' ? "buyer" : permissionLevel}`)
|
|
.setColor('#0099ff');
|
|
embed.setDescription(description);
|
|
embed.permissionLevel = permissionLevel
|
|
return embed;
|
|
});
|
|
}).flat().filter(Boolean);
|
|
|
|
if (embeds.length === 0) {
|
|
return message.reply("Aucune commande disponible pour ce serveur.");
|
|
}
|
|
|
|
|
|
const backButton = new ButtonBuilder()
|
|
.setCustomId('back')
|
|
.setLabel('⬅️')
|
|
.setStyle(ButtonStyle.Primary);
|
|
|
|
const nextButton = new ButtonBuilder()
|
|
.setCustomId('next')
|
|
.setLabel('➡️')
|
|
.setStyle(ButtonStyle.Primary);
|
|
|
|
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
|
|
});
|
|
const userPermissionLevel = await getPermissionLevel(message.member, client);
|
|
let currentPage = 0;
|
|
collector.on('collect', async (interaction) => {
|
|
await interaction.deferUpdate();
|
|
if (interaction.customId === 'back') {
|
|
currentPage = currentPage > 0 ? --currentPage : 0;
|
|
} else if (interaction.customId === 'next') {
|
|
currentPage = currentPage + 1 < embeds.length && embeds[currentPage + 1].permissionLevel <= userPermissionLevel ? ++currentPage : 0;
|
|
}
|
|
await msg.edit({ embeds: [embeds[currentPage]], components: [row] });
|
|
});
|
|
|
|
collector.on('end', () => msg.edit({ embeds: [embeds[currentPage]], components: [] }));
|
|
}catch (error) {
|
|
console.log(error);
|
|
return message.reply("Veuillez changer des commandes de permission pour avoir accès au helpall.");
|
|
}
|
|
},
|
|
}; |