mirror of
https://github.com/arthur-pbty/gestion.git
synced 2026-06-06 06:10:39 +02:00
57 lines
2.5 KiB
JavaScript
57 lines
2.5 KiB
JavaScript
const db = require('quick.db');
|
|
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 <perm/commande> @role',
|
|
category: 'gestion',
|
|
async execute(message, args, client) {
|
|
const botId = message.client.user.id;
|
|
const permissionOrCommand = args[0].toLowerCase();
|
|
const role = message.mentions.roles.first();
|
|
|
|
if (!role) {
|
|
return message.reply('Veuillez mentionner un rôle valide.');
|
|
}
|
|
|
|
if (['1', '2', '3', '4', '5', '6', '7', '8', '9'].includes(permissionOrCommand)) {
|
|
for (let i = 1; i <= 9; i++) {
|
|
let oldRoleIds = await GestionDb.get(`${botId}.${message.guild.id}.p${i}`);
|
|
if (oldRoleIds) {
|
|
if (!Array.isArray(oldRoleIds)) {
|
|
oldRoleIds = [oldRoleIds];
|
|
}
|
|
const index = oldRoleIds.indexOf(role.id);
|
|
if (index !== -1) {
|
|
oldRoleIds.splice(index, 1);
|
|
await GestionDb.set(`${botId}.${message.guild.id}.p${i}`, oldRoleIds);
|
|
}
|
|
}
|
|
}
|
|
let roleIds = await GestionDb.get(`${botId}.${message.guild.id}.p${permissionOrCommand}`);
|
|
if (!roleIds) {
|
|
roleIds = [];
|
|
} else if (!Array.isArray(roleIds)) {
|
|
roleIds = [roleIds];
|
|
}
|
|
roleIds.push(role.id);
|
|
await GestionDb.set(`${botId}.${message.guild.id}.p${permissionOrCommand}`, roleIds);
|
|
message.reply(`La permission ${permissionOrCommand} a été défini sur ${role.name}.`);
|
|
} else {
|
|
if (!client.commands.has(permissionOrCommand)) {
|
|
return message.reply('Cette commande n\'existe pas.');
|
|
}
|
|
let roleIds = await GestionDb.get(`${botId}.${message.guild.id}.c${permissionOrCommand}`);
|
|
if (!roleIds) {
|
|
roleIds = [];
|
|
} else if (!Array.isArray(roleIds)) {
|
|
roleIds = [roleIds];
|
|
}
|
|
roleIds.push(role.id);
|
|
await GestionDb.set(`${botId}.${message.guild.id}.c${permissionOrCommand}`, roleIds);
|
|
GestionDb.push(`${botId}.${message.guild.id}.commandNames`, permissionOrCommand);
|
|
message.reply(`La role ${role.name} a maintenant accée a la commande ${permissionOrCommand} .`);
|
|
}
|
|
},
|
|
}; |