mirror of
https://github.com/arthur-pbty/gestion.git
synced 2026-06-08 15:18:52 +02:00
change quick.db to sqlite3
This commit is contained in:
+53
-44
@@ -1,6 +1,5 @@
|
||||
const { EmbedBuilder , ButtonBuilder, ButtonStyle, ActionRowBuilder } = require('discord.js');
|
||||
const db = require('quick.db');
|
||||
const GestionDb = new db.table("gestion");
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
|
||||
module.exports = {
|
||||
name: 'helpall',
|
||||
@@ -11,83 +10,93 @@ module.exports = {
|
||||
category: 'utils',
|
||||
|
||||
async execute(message, args, client) {
|
||||
const db = new sqlite3.Database('myDatabase.db');
|
||||
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 defaultPrefix = "+";
|
||||
|
||||
const permissions = GestionDb.get(`${botId}.permissions`);
|
||||
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 = {};
|
||||
|
||||
// Parcourir les permissions et les commandes associées
|
||||
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]) => {
|
||||
|
||||
// Créer les embeds pour chaque niveau de permission avec des commandes associées
|
||||
const embeds = Object.entries(commandsByPermission).map(([permissionLevel, commands]) => {
|
||||
const commandDescriptions = commands.map(commandName => {
|
||||
const command = client.commands.get(commandName);
|
||||
if (!command) {
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
return `**${prefix}${commandName}**\n\`${command.description}\``;
|
||||
}).filter(Boolean);
|
||||
}).filter(Boolean);
|
||||
|
||||
if (commandDescriptions.length === 0) {
|
||||
return null; // Skip creating an embed if there are no commands for this permission level
|
||||
}
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle(`Commandes de niveau de permission ${permissionLevel === '10' ? 'Owner' : permissionLevel === '11' ? 'Buyer' : permissionLevel}`)
|
||||
.setColor('#0099ff');
|
||||
const embed = new EmbedBuilderon()
|
||||
.setTitle(`Commandes de niveau de permission ${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] });
|
||||
}).filter(Boolean) // Filter out any undefined embeds
|
||||
|
||||
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
|
||||
});
|
||||
|
||||
|
||||
let currentPage = 0;
|
||||
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;
|
||||
currentPage = currentPage > 0 ? --currentPage : embeds.length - 1;
|
||||
} else if (interaction.customId === 'next') {
|
||||
currentPage = currentPage + 1 < embeds.length ? ++currentPage : 0;
|
||||
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: [] }));
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
const { EmbedBuilder, } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
name: 'stat',
|
||||
|
||||
Reference in New Issue
Block a user