diff --git a/commands/botcontrol/leave.js b/commands/botcontrol/leave.js index 98440fc..3ae6341 100644 --- a/commands/botcontrol/leave.js +++ b/commands/botcontrol/leave.js @@ -3,7 +3,7 @@ const path = require('path'); module.exports = { name: 'leave', - description: 'Faire quitter le bot d\`un serveur', + description: "Faire quitter le bot un serveur", emote: '🚪', utilisation: 'leave [guildId]', category: 'botcontrol', diff --git a/commands/gestion/change.js b/commands/gestion/change.js index 4fc9892..35fe32c 100644 --- a/commands/gestion/change.js +++ b/commands/gestion/change.js @@ -5,6 +5,9 @@ const GestionDb = new db.table("gestion"); module.exports = { name: 'change', description: 'Change le niveau de permission d\'une commande', + emote: '🔄', + utilisation: 'change ', + category: 'botcontrol', async execute(message, args, client) { const botId = client.user.id; const unchangeableCommands = ['owner', 'unowner','buyer']; diff --git a/commands/gestion/delperm.js b/commands/gestion/delperm.js index dc1952d..92ae1fc 100644 --- a/commands/gestion/delperm.js +++ b/commands/gestion/delperm.js @@ -4,23 +4,20 @@ const GestionDb = new db.table("gestion"); module.exports = { name: 'delperm', description: 'Supprime un rôle d\'un niveau de permission ou d\'une commande', + emote: '❌', + utilisation: 'delperm @role', + category: 'gestion', async execute(message, args, client) { const botId = client.user.id; - // Récupère le niveau de permission/la commande et le rôle const permissionOrCommand = args[0].toLowerCase(); const role = message.mentions.roles.first(); - // Vérifie si le rôle est valide if (!role) { return message.reply('Veuillez mentionner un rôle valide.'); } - - // Vérifie si c'est un niveau de permission ou une commande if (['1', '2', '3', '4', '5', '6', '7', '8', '9'].includes(permissionOrCommand)) { - // C'est un niveau de permission let roleIds = await GestionDb.get(`${botId}.${message.guild.id}.p${permissionOrCommand}`); if (roleIds) { - // Si roleIds n'est pas un tableau, le convertir en tableau if (!Array.isArray(roleIds)) { roleIds = [roleIds]; } @@ -32,10 +29,8 @@ module.exports = { } message.reply(`Le rôle pour ${permissionOrCommand} a été supprimé.`); } else { - // C'est une commande let roleIds = await GestionDb.get(`${botId}.${message.guild.id}.c${permissionOrCommand}`); if (roleIds) { - // Si roleIds n'est pas un tableau, le convertir en tableau if (!Array.isArray(roleIds)) { roleIds = [roleIds]; } diff --git a/commands/gestion/perm.js b/commands/gestion/perm.js index 7e0353a..ab2e2a6 100644 --- a/commands/gestion/perm.js +++ b/commands/gestion/perm.js @@ -4,9 +4,9 @@ const { EmbedBuilder } = require('discord.js'); module.exports = { name: 'perm', description: 'Affiche les rôles pour chaque niveau de permission et commande', - emote: '🛡️', + emote: '🛡️', utilisation: 'perm', - category: 'botcontrol', + category: 'gestion', async execute(message, client) { const botId = message.client.user.id; const embed = new EmbedBuilder() diff --git a/commands/gestion/prefix.js b/commands/gestion/prefix.js new file mode 100644 index 0000000..0218cc2 --- /dev/null +++ b/commands/gestion/prefix.js @@ -0,0 +1,27 @@ +const db = require('quick.db'); +const GestionDb = new db.table("gestion"); + +module.exports = { + name: 'prefix', + description: 'Change le préfixe du bot ', + emote: '🔧', + utilisation: 'prefix ', + category: 'botcontrol', + async execute(message, args, client) { + const botId = client.user.id; + const guildId = message.guild.id; + + if (args.length < 1) { + return message.reply('Veuillez spécifier un nouveau préfixe.'); + } + if (args[0] === "main") { + const newPrefix = args[1]; + await GestionDb.set(`${botId}.prefix`, newPrefix); + message.reply(`Le main préfixe a été changé à ${newPrefix}.`); + }else { + const newPrefix = args[0]; + await GestionDb.set(`${botId}.${guildId}.prefix`, newPrefix); + message.reply(`Le préfixe a été changé à ${newPrefix}.`); + } + }, +}; \ No newline at end of file diff --git a/commands/gestion/renew.js b/commands/gestion/renew.js index e2c5cb2..81e2b27 100644 --- a/commands/gestion/renew.js +++ b/commands/gestion/renew.js @@ -5,7 +5,6 @@ module.exports = { emote: '🔄', utilisation: 'renew', category: 'gestion', - async execute(message, args, client) { const guild = message.guild; const channel = message.mentions.channels.first() || message.channel; diff --git a/commands/gestion/setperm.js b/commands/gestion/setperm.js index af605db..5f4c5ca 100644 --- a/commands/gestion/setperm.js +++ b/commands/gestion/setperm.js @@ -3,24 +3,22 @@ const GestionDb = new db.table("gestion"); module.exports = { name: 'setperm', description: 'Définit un rôle pour un niveau de permission ou une commande', + emote: '🔑', + utilisation: 'setperm @role', + category: 'gestion', async execute(message, args, client) { const botId = message.client.user.id; - // Récupère le niveau de permission/la commande et le rôle const permissionOrCommand = args[0].toLowerCase(); const role = message.mentions.roles.first(); - // Vérifie si le rôle est valide if (!role) { return message.reply('Veuillez mentionner un rôle valide.'); } - // Vérifie si c'est un niveau de permission ou une commande if (['1', '2', '3', '4', '5', '6', '7', '8', '9'].includes(permissionOrCommand)) { - // C'est un niveau de permission for (let i = 1; i <= 9; i++) { let oldRoleIds = await GestionDb.get(`${botId}.${message.guild.id}.p${i}`); if (oldRoleIds) { - // Si oldRoleIds n'est pas un tableau, le convertir en tableau if (!Array.isArray(oldRoleIds)) { oldRoleIds = [oldRoleIds]; } @@ -41,7 +39,6 @@ module.exports = { await GestionDb.set(`${botId}.${message.guild.id}.p${permissionOrCommand}`, roleIds); message.reply(`La permission ${permissionOrCommand} a été défini sur ${role.name}.`); } else { - // C'est une commande if (!client.commands.has(permissionOrCommand)) { return message.reply('Cette commande n\'existe pas.'); } diff --git a/commands/utils/help.js b/commands/utils/help.js index 12cba2a..3833e91 100644 --- a/commands/utils/help.js +++ b/commands/utils/help.js @@ -1,4 +1,6 @@ const { EmbedBuilder, StringSelectMenuBuilder, ActionRowBuilder } = require("discord.js") +const db = require('quick.db'); +const GestionDb = new db.table("gestion"); module.exports = { name: 'help', description: 'Affiche la liste des commandes', @@ -6,18 +8,24 @@ module.exports = { emote: '📚', utilisation: 'help [commande]', async execute(message, args, client) { + const defaultprefix = "+"; + const botId = client.user.id; + const guildId = message.guild.id; + let mainPrefix = await GestionDb.get(`${botId}.prefix`); + let serverPrefix = await GestionDb.get(`${botId}.${guildId}.prefix`); + const prefix = serverPrefix !== undefined ? serverPrefix : mainPrefix !== undefined ? mainPrefix : defaultprefix; if (args[0]) { const command = client.commands.get(args[0]); if (!command) { return message.reply(`Je n'ai pas trouvé de commande nommée "${args[0]}".`); } - + const embed_command = new EmbedBuilder() .setColor('#0099ff') .setTitle(`Aide pour la commande ${command.emote ? ` ${command.emote}` : '🔧'} ${command.name}`) .setDescription(command.description) .addFields( - { name: 'Utilisation', value: `\`+${command.utilisation ? ` **${command.utilisation}**` : ''}\``, inline: true }, + { name: 'Utilisation', value: `\`${prefix}${command.utilisation ? ` **${command.utilisation}**` : ''}\``, inline: true }, { name: 'Catégorie', value: command.category || 'Non spécifiée', inline: true } ); @@ -59,7 +67,7 @@ module.exports = { for (const [category, commands] of Object.entries(categories)) { let description; if (commands.length > 0) { - description = commands.map(command => `${command.emote ? ` ${command.emote}` : '🔧'} **+${command.utilisation ? ` ${command.utilisation}` : ''}**\n \`${command.description}\``).join('\n'); + description = commands.map(command => `${command.emote ? ` ${command.emote}` : '🔧'} **${prefix}${command.utilisation ? ` ${command.utilisation}` : ''}**\n \`${command.description}\``).join('\n'); } else { description = 'Aucune commande dans cette catégorie.'; } diff --git a/loaders/loadCommands.js b/loaders/loadCommands.js index 9669f81..089854f 100644 --- a/loaders/loadCommands.js +++ b/loaders/loadCommands.js @@ -56,8 +56,11 @@ module.exports = (client) => { const guildId = message.guild.id; const botInfo = GestionDb.get(botId); const permissions = botInfo.permissions; - //const prefix = botTokens.coins[botId].prefix; - const prefix = '+'; + 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; + if (!message.content.startsWith(prefix) || message.author.bot) return; const args = message.content.slice(prefix.length).trim().split(/ +/);