From 207f8ab6b506a2569ada47640e2a2c60e01bebd7 Mon Sep 17 00:00:00 2001 From: KwikKill Date: Thu, 12 Sep 2024 09:17:23 +0200 Subject: [PATCH] Fix deploy command --- commands/adminlol.js | 73 +++++++------- commands/deploy.js | 52 ++++++---- commands/eval.js | 5 +- commands/help.js | 10 +- commands/info.js | 2 +- commands/lol.js | 162 +++++++++++++++++--------------- commands/restart.js | 4 +- index.js | 17 ++-- listeners/commandInteraction.js | 2 +- 9 files changed, 179 insertions(+), 148 deletions(-) diff --git a/commands/adminlol.js b/commands/adminlol.js index 58bdfb1..c16cdd1 100644 --- a/commands/adminlol.js +++ b/commands/adminlol.js @@ -1,28 +1,29 @@ -//const { EmbedBuilder } = require('discord.js'); +const { PermissionsBitField, ApplicationCommandOptionType } = require('discord.js'); const parse = require('node-html-parser'); module.exports = { name: 'adminlol', group: 'lol', description: "admin league of legends related commands", - permission: "none", + permission: PermissionsBitField.Flags.ManageMessages, + owner: true, serverid: ["513776796211085342"], hidden: false, options: [ { name: 'update', description: 'update all lol accounts', - type: 'SUB_COMMAND_GROUP', + type: ApplicationCommandOptionType.SubcommandGroup, options: [ { name: 'all', description: 'update all lol accounts', - type: 'SUB_COMMAND', + type: ApplicationCommandOptionType.Subcommand, options: [ { name: 'first', description: 'first', - type: 'BOOLEAN', + type: ApplicationCommandOptionType.Boolean, required: true } ] @@ -30,33 +31,33 @@ module.exports = { { name: 'swain', description: 'add swain main summoners to the database', - type: 'SUB_COMMAND' + type: ApplicationCommandOptionType.Subcommand, }, { name: 'add', description: 'add more summoners to the database', - type: 'SUB_COMMAND' + type: ApplicationCommandOptionType.Subcommand, }, { name: 'transition', description: 'transition to the new database', - type: 'SUB_COMMAND' + type: ApplicationCommandOptionType.Subcommand, }, { name: 'populate', description: 'populate the database', - type: 'SUB_COMMAND', + type: ApplicationCommandOptionType.Subcommand, options: [ { name: 'limit', description: 'limit', - type: 'INTEGER', + type: ApplicationCommandOptionType.Integer, required: true }, { name: 'account', description: 'account', - type: 'BOOLEAN', + type: ApplicationCommandOptionType.Boolean, required: true } ] @@ -66,71 +67,71 @@ module.exports = { { name: 'analyze', description: 'analyze a game comp post launch', - type: 'SUB_COMMAND_GROUP', + type: ApplicationCommandOptionType.SubcommandGroup, options: [ { name: 'test', description: 'update all lol accounts', - type: 'SUB_COMMAND', + type: ApplicationCommandOptionType.Subcommand, options: [ { name: 'top', description: 'allied TOP laner', - type: 'STRING', + type: ApplicationCommandOptionType.String, autocomplete: true, }, { name: 'jungle', description: 'allied JUNGLE laner', - type: 'STRING', + type: ApplicationCommandOptionType.String, autocomplete: true, }, { name: 'mid', description: 'allied MID laner', - type: 'STRING', + type: ApplicationCommandOptionType.String, autocomplete: true, }, { name: 'adc', description: 'allied ADC laner', - type: 'STRING', + type: ApplicationCommandOptionType.String, autocomplete: true, }, { name: 'supp', description: 'allied SUPPORT laner', - type: 'STRING', + type: ApplicationCommandOptionType.String, autocomplete: true, }, { name: 'entop', description: 'enemy TOP laner', - type: 'STRING', + type: ApplicationCommandOptionType.String, autocomplete: true, }, { name: 'enjungle', description: 'enemy JUNGLE laner', - type: 'STRING', + type: ApplicationCommandOptionType.String, autocomplete: true, }, { name: 'enmid', description: 'enemy MID laner', - type: 'STRING', + type: ApplicationCommandOptionType.String, autocomplete: true, }, { name: 'enadc', description: 'enemy ADC laner', - type: 'STRING', + type: ApplicationCommandOptionType.String, autocomplete: true, }, { name: 'ensupp', description: 'enemy SUPPORT laner', - type: 'STRING', + type: ApplicationCommandOptionType.String, autocomplete: true, } ] @@ -140,23 +141,23 @@ module.exports = { { name: 'add', description: 'add a summoner to the database', - type: 'SUB_COMMAND_GROUP', + type: ApplicationCommandOptionType.SubcommandGroup, options: [ { name: 'summoner', description: 'add a summoner to the database', - type: 'SUB_COMMAND', + type: ApplicationCommandOptionType.Subcommand, options: [ { name: 'summonerid', description: 'summoner id', - type: 'STRING', + type: ApplicationCommandOptionType.String, required: true, }, { name: 'region', description: 'region', - type: 'STRING', + type: ApplicationCommandOptionType.String, required: true, choices: [ { @@ -208,13 +209,13 @@ module.exports = { { name: 'discordid', description: 'discord id', - type: 'STRING', + type: ApplicationCommandOptionType.String, required: true, }, { name: 'priority', description: 'priority', - type: 'INTEGER', + type: ApplicationCommandOptionType.Integer, required: true, } ] @@ -222,18 +223,18 @@ module.exports = { { name: 'game', description: 'add a game to the database', - type: 'SUB_COMMAND', + type: ApplicationCommandOptionType.Subcommand, options: [ { name: 'gameid', description: 'game id', - type: 'STRING', + type: ApplicationCommandOptionType.String, required: true, }, { name: 'region', description: 'region', - type: 'STRING', + type: ApplicationCommandOptionType.String, required: true, choices: [ { @@ -285,7 +286,7 @@ module.exports = { { name: 'debug', description: 'debug', - type: 'BOOLEAN', + type: ApplicationCommandOptionType.Boolean, required: true } ] @@ -295,17 +296,17 @@ module.exports = { { name: 'status', description: 'check the status of the bot', - type: 'SUB_COMMAND_GROUP', + type: ApplicationCommandOptionType.SubcommandGroup, options: [ { name: 'summarized', description: 'summarized status', - type: 'SUB_COMMAND', + type: ApplicationCommandOptionType.Subcommand, }, { name: 'maintenance', description: 'send a maintenance message', - type: 'SUB_COMMAND', + type: ApplicationCommandOptionType.Subcommand, }, ] } diff --git a/commands/deploy.js b/commands/deploy.js index 134f020..af1329e 100644 --- a/commands/deploy.js +++ b/commands/deploy.js @@ -1,21 +1,38 @@ +const { PermissionsBitField, ApplicationCommandOptionType } = require("discord.js"); + module.exports = { name: 'deploy', group: 'moderation', description: "Allow to redeploy commands and context menus.", - permission: "owner", + permission: PermissionsBitField.Flags.Administrator, + owner: true, hidden: false, place: "guild", - options: undefined, + options: [ + { + name: "global", + description: "Deploy global commands", + type: ApplicationCommandOptionType.Boolean, + required: false + } + ], commande_channel: true, serverid: ["513776796211085342", "890915473363980308", "962329252550807592"], async run(message, client, interaction = undefined, mssg = true) { let number; - if (interaction === undefined) { - number = await deploy(client, message.guild); + if (interaction !== undefined && interaction.options.getBoolean("global") === true) { + + number = await deploy_global(client); + } else { - number = await deploy(client, interaction.guild); + + if (interaction === undefined) { + number += await deploy(client, message.guild); + } else { + number += await deploy(client, interaction.guild); + } } if (interaction === undefined) { @@ -42,7 +59,7 @@ async function auto_deploy(client) { console.log("- auto-deploy for guild " + guild.id + " : " + number); } } - deploy_global(client); + return deploy_global(client); } async function deploy(client, guild) { @@ -69,7 +86,7 @@ async function deploy(client, guild) { name: item.name, description: item.description, options: item.options, - defaultMemberPermissions: item.permission === "none", + defaultMemberPermissions: item.permission, }); } else { if (item.options !== undefined) { @@ -77,13 +94,13 @@ async function deploy(client, guild) { name: item.name, description: item.description, options: item.options, - defaultMemberPermissions: item.permission === "none", + defaultMemberPermissions: item.permission, }); } else { commands.push({ name: item.name, description: item.description, - defaultMemberPermissions: item.permission === "none", + defaultMemberPermissions: item.permission, }); } } @@ -95,13 +112,13 @@ async function deploy(client, guild) { commands.push({ name: item.name, type: item.type, - defaultMemberPermissions: item.permission === "none", + defaultMemberPermissions: item.permission, }); } }); await guild.commands.set(commands); - return commands.length.toString(); + return commands.length; /* command.forEach((commande) => { @@ -210,7 +227,8 @@ async function deploy_global(client) { name: item.name, description: item.description, options: item.options, - defaultMemberPermissions: item.permission === "none", + defaultMemberPermissions: item.permission, + integration_types: item.integration_types || [0], }); } else { if (item.options !== undefined) { @@ -218,13 +236,15 @@ async function deploy_global(client) { name: item.name, description: item.description, options: item.options, - defaultMemberPermissions: item.permission === "none", + defaultMemberPermissions: item.permission, + integration_types: item.integration_types || [0], }); } else { commands.push({ name: item.name, description: item.description, - defaultMemberPermissions: item.permission === "none", + defaultMemberPermissions: item.permission, + integration_types: item.integration_types || [0], }); } } @@ -236,11 +256,11 @@ async function deploy_global(client) { commands.push({ name: item.name, type: item.type, - defaultMemberPermissions: item.permission === "none", + defaultMemberPermissions: item.permission, }); } }); await client.application.commands.set(commands); - return commands.length.toString(); + return commands.length; } \ No newline at end of file diff --git a/commands/eval.js b/commands/eval.js index 42805b0..5b62306 100644 --- a/commands/eval.js +++ b/commands/eval.js @@ -1,6 +1,6 @@ const fs = require("fs"); const path = require('path'); -const { Util } = require('discord.js'); +const { Util, PermissionsBitField } = require('discord.js'); const util = require('util'); const tags = require('common-tags'); const { escapeRegex, splitMessage } = require('../util/util'); @@ -14,7 +14,8 @@ module.exports = { name: 'eval', group: 'moderation', description: "Permet d'éxecuter du code js.", - permission: "owner", + permission: PermissionsBitField.Flags.ManageMessages, + owner: true, hidden: false, deploy: false, place: "dm", diff --git a/commands/help.js b/commands/help.js index 7869d4c..5e51699 100644 --- a/commands/help.js +++ b/commands/help.js @@ -1,21 +1,21 @@ -const { EmbedBuilder } = require('discord.js'); +const { EmbedBuilder, ApplicationCommandOptionType, PermissionsBitField } = require('discord.js'); module.exports = { name: 'help', group: 'help', description: "Provides list of commands and corresponding help", - permission: "none", hidden: false, place: "both", options: [ { name: 'commande', description: 'Provides list of commands and corresponding help', - type: 'STRING', + type: ApplicationCommandOptionType.String, required: false, autocomplete: true }, ], + integration_types: [0, 1], async run(message, client, interaction = undefined) { if ((interaction === undefined && message.args[1] === undefined) || (interaction === undefined && message.args[1] === "help") || (interaction.options.getString('commande') === null) || (interaction.options.getString('commande') === "help")) { @@ -40,7 +40,7 @@ module.exports = { let commands = ""; //if(group.guarded === false) { group.commands.each(cmd => { - if (cmd.permission !== "owner") { + if (cmd.owner !== true) { if (client.canRunCommande(undefined, cmd, interaction) && (cmd.serverid === undefined || (interaction.guild && cmd.serverid?.includes(interaction.guild.id)))) { if (commands !== "") { commands = commands + ", "; @@ -158,7 +158,7 @@ module.exports = { let cmds = []; // if the interaction is not in a guild, we return only the global commands if (interaction.guild === null) { - client.commands.filter(cmd => cmd.name.startsWith(focusedValue) && (cmd.place === "dm" || cmd.place === "both") && (!cmd.serverid) && cmd.permission === "none").forEach(cmd => { + client.commands.filter(cmd => cmd.name.startsWith(focusedValue) && (cmd.place === "dm" || cmd.place === "both") && (!cmd.serverid) && cmd.permission === PermissionsBitField.Flags.SendMessages).forEach(cmd => { cmds.push({ name: cmd.name, value: cmd.name }); }); } else { diff --git a/commands/info.js b/commands/info.js index 6902814..5aa1663 100644 --- a/commands/info.js +++ b/commands/info.js @@ -4,9 +4,9 @@ module.exports = { name: 'info', group: 'help', description: "Gives information about the bot", - permission: "none", hidden: false, place: "both", + integration_types: [0, 1], async run(message, client, interaction = undefined) { client.pg.query({ name: "insert-logs", diff --git a/commands/lol.js b/commands/lol.js index 16564c6..68b29f5 100644 --- a/commands/lol.js +++ b/commands/lol.js @@ -1,4 +1,4 @@ -const { EmbedBuilder, AttachmentBuilder, PermissionsBitField } = require('discord.js'); +const { EmbedBuilder, AttachmentBuilder, PermissionsBitField, ApplicationCommandOptionType, ChannelType } = require('discord.js'); const { ChartJSNodeCanvas } = require('chartjs-node-canvas'); const logger = require('../util/logger'); @@ -10,36 +10,35 @@ module.exports = { name: 'lol', group: 'lol', description: "league of legends related commands", - permission: "none", hidden: false, place: "both", options: [ { name: 'account', description: 'Manage your lol accounts', - type: 'SUB_COMMAND_GROUP', + type: ApplicationCommandOptionType.SubcommandGroup, options: [ { name: 'add', description: 'link a lol pseudo to your discord account', - type: 'SUB_COMMAND', + type: ApplicationCommandOptionType.Subcommand, options: [ { name: 'gamename', description: 'GameName of the account', - type: 'STRING', + type: ApplicationCommandOptionType.String, required: true, }, { name: 'tagline', description: 'TagLine of the account', - type: 'STRING', + type: ApplicationCommandOptionType.String, required: true, }, { name: 'region', description: 'Region of the account', - type: 'STRING', + type: ApplicationCommandOptionType.String, required: true, choices: [ { @@ -93,18 +92,18 @@ module.exports = { { name: 'remove', description: 'Remove a lol account', - type: 'SUB_COMMAND', + type: ApplicationCommandOptionType.Subcommand, options: [ { name: 'gamename', description: 'GameName of the account', - type: 'STRING', + type: ApplicationCommandOptionType.String, required: true, }, { name: 'tagline', description: 'TagLine of the account', - type: 'STRING', + type: ApplicationCommandOptionType.String, required: true, }, ] @@ -112,7 +111,7 @@ module.exports = { { name: 'list', description: 'List lol accounts', - type: 'SUB_COMMAND', + type: ApplicationCommandOptionType.Subcommand, }, ] }, @@ -131,28 +130,28 @@ module.exports = { { name: 'stats', description: 'lol stat commands', - type: 'SUB_COMMAND_GROUP', + type: ApplicationCommandOptionType.SubcommandGroup, options: [ { name: 'summarized', description: 'See summarized stats', - type: 'SUB_COMMAND', + type: ApplicationCommandOptionType.Subcommand, options: [ { name: 'discordaccount', description: 'Discord account', - type: 'USER', + type: ApplicationCommandOptionType.User, }, { name: 'champion', description: 'Champion', - type: 'STRING', + type: ApplicationCommandOptionType.String, autocomplete: true, }, { name: 'lane', description: 'Lane', - type: 'STRING', + type: ApplicationCommandOptionType.String, choices: [ { name: 'Top', @@ -179,7 +178,7 @@ module.exports = { { name: 'gamemode', description: 'GameMode', - type: 'STRING', + type: ApplicationCommandOptionType.String, choices: [ { name: 'normal', @@ -214,47 +213,47 @@ module.exports = { { name: 'account', description: 'account (gamename#tagline)', - type: 'STRING' + type: ApplicationCommandOptionType.String }, { name: 'season', description: 'Season', - type: 'STRING', + type: ApplicationCommandOptionType.String, } ] }, { name: 'profile', description: 'See profile stats', - type: 'SUB_COMMAND', + type: ApplicationCommandOptionType.Subcommand, options: [ { name: 'discordaccount', description: 'Discord account', - type: 'USER', + type: ApplicationCommandOptionType.User, } ] }, /*{ name: 'friends', description: 'See friends stats', - type: 'SUB_COMMAND', + type: ApplicationCommandOptionType.Subcommand, options: [ { name: 'discordaccount', description: 'Discord account', - type: 'USER', + type: ApplicationCommandOptionType.User, }, { name: 'champion', description: 'Champion', - type: 'STRING', + type: ApplicationCommandOptionType.String, autocomplete: true, }, { name: 'lane', description: 'Lane', - type: 'STRING', + type: ApplicationCommandOptionType.String, choices: [ { name: 'Top', @@ -281,7 +280,7 @@ module.exports = { { name: 'gamemode', description: 'GameMode', - type: 'STRING', + type: ApplicationCommandOptionType.String, choices: [ { name: 'normal', @@ -316,30 +315,30 @@ module.exports = { { name: 'account', description: 'account', - type: 'STRING' + type: ApplicationCommandOptionType.String }, ] },*/ { name: 'matchups', description: 'See matchups stats', - type: 'SUB_COMMAND', + type: ApplicationCommandOptionType.Subcommand, options: [ { name: 'discordaccount', description: 'Discord account', - type: 'USER', + type: ApplicationCommandOptionType.User, }, { name: 'champion', description: 'Champion', - type: 'STRING', + type: ApplicationCommandOptionType.String, autocomplete: true, }, { name: 'lane', description: 'Lane', - type: 'STRING', + type: ApplicationCommandOptionType.String, choices: [ { name: 'Top', @@ -366,7 +365,7 @@ module.exports = { { name: 'gamemode', description: 'GameMode', - type: 'STRING', + type: ApplicationCommandOptionType.String, choices: [ { name: 'normal', @@ -401,29 +400,29 @@ module.exports = { { name: 'account', description: 'account (gamename#tagline)', - type: 'STRING' + type: ApplicationCommandOptionType.String }, { name: 'season', description: 'Season', - type: 'STRING', + type: ApplicationCommandOptionType.String, } ] }, { name: 'champions', description: 'See champions stats', - type: 'SUB_COMMAND', + type: ApplicationCommandOptionType.Subcommand, options: [ { name: 'discordaccount', description: 'Discord account', - type: 'USER', + type: ApplicationCommandOptionType.User, }, { name: 'lane', description: 'Lane', - type: 'STRING', + type: ApplicationCommandOptionType.String, choices: [ { name: 'Top', @@ -450,7 +449,7 @@ module.exports = { { name: 'gamemode', description: 'GameMode', - type: 'STRING', + type: ApplicationCommandOptionType.String, choices: [ { name: 'normal', @@ -485,36 +484,36 @@ module.exports = { { name: 'account', description: 'account (gamename#tagline)', - type: 'STRING' + type: ApplicationCommandOptionType.String }, { name: 'season', description: 'Season', - type: 'STRING', + type: ApplicationCommandOptionType.String, } ] }, { name: 'compare', description: 'compare your stats to another player', - type: 'SUB_COMMAND', + type: ApplicationCommandOptionType.Subcommand, options: [ { name: 'discordaccount', description: 'Discord account', - type: 'USER', + type: ApplicationCommandOptionType.User, required: true }, { name: 'champion', description: 'Champion', - type: 'STRING', + type: ApplicationCommandOptionType.String, autocomplete: true, }, { name: 'lane', description: 'Lane', - type: 'STRING', + type: ApplicationCommandOptionType.String, choices: [ { name: 'Top', @@ -541,7 +540,7 @@ module.exports = { { name: 'gamemode', description: 'GameMode', - type: 'STRING', + type: ApplicationCommandOptionType.String, choices: [ { name: 'normal', @@ -576,30 +575,30 @@ module.exports = { { name: 'season', description: 'Season', - type: 'STRING', + type: ApplicationCommandOptionType.String, } ] }, { name: 'evolution', description: 'See evolution graphs', - type: 'SUB_COMMAND', + type: ApplicationCommandOptionType.Subcommand, options: [ { name: 'discordaccount', description: 'Discord account', - type: 'USER', + type: ApplicationCommandOptionType.User, }, { name: 'champion', description: 'Champion', - type: 'STRING', + type: ApplicationCommandOptionType.String, autocomplete: true, }, { name: 'lane', description: 'Lane', - type: 'STRING', + type: ApplicationCommandOptionType.String, choices: [ { name: 'Top', @@ -626,7 +625,7 @@ module.exports = { { name: 'gamemode', description: 'GameMode', - type: 'STRING', + type: ApplicationCommandOptionType.String, choices: [ { name: 'normal', @@ -661,34 +660,34 @@ module.exports = { { name: 'account', description: 'account (gamename#tagline)', - type: 'STRING' + type: ApplicationCommandOptionType.String }, { name: 'season', description: 'Season', - type: 'STRING', + type: ApplicationCommandOptionType.String, } ] }, /*{ name: 'match', description: 'See matchs stats', - type: 'SUB_COMMAND', + type: ApplicationCommandOptionType.Subcommand, options: [ { name: 'id', description: 'Game\'s ID', - type: 'STRING' + type: ApplicationCommandOptionType.String }, { name: 'account', description: 'account', - type: 'STRING' + type: ApplicationCommandOptionType.String }, { name: 'gamemode', description: 'GameMode', - type: 'STRING', + type: ApplicationCommandOptionType.String, choices: [ { name: 'normal', @@ -723,13 +722,13 @@ module.exports = { { name: 'champion', description: 'Champion', - type: 'STRING', + type: ApplicationCommandOptionType.String, autocomplete: true, }, { name: 'lane', description: 'Lane', - type: 'STRING', + type: ApplicationCommandOptionType.String, choices: [ { name: 'Top', @@ -760,23 +759,23 @@ module.exports = { { name: 'top', description: 'ranking commands', - type: 'SUB_COMMAND_GROUP', + type: ApplicationCommandOptionType.SubcommandGroup, options: [ { name: 'carry', description: 'ranking carry commands', - type: 'SUB_COMMAND', + type: ApplicationCommandOptionType.Subcommand, options: [ { name: 'champion', description: 'Champion', - type: 'STRING', + type: ApplicationCommandOptionType.String, autocomplete: true, }, { name: 'lane', description: 'Lane', - type: 'STRING', + type: ApplicationCommandOptionType.String, choices: [ { name: 'Top', @@ -803,30 +802,30 @@ module.exports = { { name: 'all', description: 'All', - type: 'BOOLEAN' + type: ApplicationCommandOptionType.Boolean }, { name: 'season', description: 'Season', - type: 'STRING', + type: ApplicationCommandOptionType.String, } ] }, { name: 'kwikscore', description: 'ranking kwikscore commands', - type: 'SUB_COMMAND', + type: ApplicationCommandOptionType.Subcommand, options: [ { name: 'champion', description: 'Champion', - type: 'STRING', + type: ApplicationCommandOptionType.String, autocomplete: true, }, { name: 'lane', description: 'Lane', - type: 'STRING', + type: ApplicationCommandOptionType.String, choices: [ { name: 'Top', @@ -853,12 +852,12 @@ module.exports = { { name: 'all', description: 'All', - type: 'BOOLEAN' + type: ApplicationCommandOptionType.Boolean }, { name: 'season', description: 'Season', - type: 'STRING', + type: ApplicationCommandOptionType.String, } ] } @@ -867,17 +866,17 @@ module.exports = { { name: 'tracker', description: 'tracker command', - type: 'SUB_COMMAND_GROUP', + type: ApplicationCommandOptionType.SubcommandGroup, options: [ { name: 'add', description: 'add a tracker channel', - type: 'SUB_COMMAND', + type: ApplicationCommandOptionType.Subcommand, options: [ { name: 'channel', description: 'Channel', - type: 'CHANNEL', + type: ApplicationCommandOptionType.Channel, required: true } ] @@ -885,12 +884,12 @@ module.exports = { { name: 'remove', description: 'add a tracker channel', - type: 'SUB_COMMAND', + type: ApplicationCommandOptionType.Subcommand, options: [ { name: 'channel', description: 'Channel', - type: 'CHANNEL', + type: ApplicationCommandOptionType.Channel, required: true } ] @@ -898,6 +897,7 @@ module.exports = { ] } ], + integration_types: [0, 1], commande_channel: true, async run(message, client, interaction = undefined) { if (interaction === undefined) { @@ -957,10 +957,22 @@ module.exports = { top_kwikscore(client, interaction, champion, role, account, season, gamemode); } } else if (interaction.options.getSubcommandGroup() === "tracker") { + // If the interaction is a user installed command + if (!interaction.guild) { + return await interaction.editReply("This command can only be used in a server.\n If you use it in a DM or with the user installed command, please install the app in a server."); + } // If the user has Manage channel permission or administrator permission if (!interaction.member.permissions.has(PermissionsBitField.Flags.ManageChannels) && !interaction.member.permissions.has(PermissionsBitField.Flags.Administrator)) { return await interaction.editReply("You don't have the permission to use this command !"); } + // If the channel provided is not a text channel + if (interaction.options.getChannel("channel").type !== ChannelType.GuildText) { + return await interaction.editReply("Please provide a valid text channel !"); + } + // If the channel does not belong to the server + if (interaction.options.getChannel("channel").guild.id !== interaction.guild.id) { + return await interaction.editReply("Please provide a valid text channel in this server !"); + } if (interaction.options.getSubcommand() === "add") { tracker_add(client, interaction); } else if (interaction.options.getSubcommand() === "remove") { diff --git a/commands/restart.js b/commands/restart.js index f55b53c..52cdcde 100644 --- a/commands/restart.js +++ b/commands/restart.js @@ -1,11 +1,13 @@ const child_process = require('child_process'); +const { PermissionsBitField } = require('discord.js'); module.exports = { name: 'restart', group: 'moderation', deploy: false, description: "Commande de restart du bot", - permission: "owner", + permission: PermissionsBitField.Flags.Administrator, + owner: true, hidden: false, place: "dm", options: undefined, diff --git a/index.js b/index.js index 57d91ce..d6b8c8f 100644 --- a/index.js +++ b/index.js @@ -119,13 +119,13 @@ client.listeners.forEach((item) => { client.canRunCommande = function (message, commande, interaction = undefined) { if (interaction === undefined) { //if(commande.commande_channel === true && !message.channel.name.toLowerCase().includes("commande")) return false - if (!checkpermission(message, commande.permission)) { return "perm"; } + if (!checkpermission(message, commande.owner, commande.permission)) { return "perm"; } if (commande.place === "dm" && message.channel.type !== ChannelType.DM) { return false; } if (commande.place === "guild" && message.channel.type !== ChannelType.GuildText) { return false; } return true; } //if(commande.commande_channel === true && !interaction.channel.name.toLowerCase().includes("commande")) return false; - if (!checkpermission(interaction, commande.permission)) { return "perm"; } + if (!checkpermission(interaction, commande.owner, commande.permission)) { return "perm"; } return true; }; @@ -137,20 +137,15 @@ client.canRunCommande = function (message, commande, interaction = undefined) { * @param {*} perm permission to check * @returns {Boolean} return true if the user has the permission */ -function checkpermission(message, perm) { +function checkpermission(message, owner, perm) { const id = message.author !== undefined ? message.author.id : message.user.id; if (client.owners.includes(id)) { return true; } - if (perm === "none") { - return true; - } if (perm === "modo") { - if (message.member.permissions.has(PermissionsBitField.Flags.ManageMessages)) { - return true; - } + if (owner === true) { + return false; } - return false; - + return message.member.permissions.has(perm); } // -------------- Index2 ----------------- diff --git a/listeners/commandInteraction.js b/listeners/commandInteraction.js index 2b6b117..7b7c9dd 100644 --- a/listeners/commandInteraction.js +++ b/listeners/commandInteraction.js @@ -11,7 +11,7 @@ module.exports = { // softban mean 4/5 commands are blocked const random = Math.floor(Math.random() * 5); if (random !== 0) { - logger.info(`softban ${interaction.user.id} on command ${interaction.commandName}`); + logger.log(`softban ${interaction.user.id} on command ${interaction.commandName}`); return; } }