From 5859c07571a41f97a9e88b7f6cc5be66162dd944 Mon Sep 17 00:00:00 2001 From: SowinskiBraeden Date: Sun, 10 Nov 2024 18:35:48 -0800 Subject: [PATCH] update/view bot admin roles via config --- commands/config.js | 76 +++++++++++++++++++++++++++++++++----------- commands/excluded.js | 2 +- package.json | 2 +- 3 files changed, 60 insertions(+), 20 deletions(-) diff --git a/commands/config.js b/commands/config.js index 67539b4..f298311 100644 --- a/commands/config.js +++ b/commands/config.js @@ -105,7 +105,7 @@ module.exports = { name: "view", description: "View configured allowed channels", value: "view", - type: CommandOptionTypes.SubCommand, + type: CommandOptions.SubCommand, } ] }, @@ -166,25 +166,40 @@ module.exports = { name: "bot_admin_role", description: "Set/remove bot admin role", value: "bot_admin_role", - type: CommandOptions.SubCommand, + type: CommandOptions.SubCommandGroup, options: [ { - name: "action", - description: "Set or remove a role to be a bot administrator", - value: "action", - type: CommandOptions.String, - choices: [ - { name: 'add', value: 'add' }, { name: 'remove', value: 'remove' }, - ], - required: true, + name: "add", + description: "Configure role to be bot admin", + value: "add", + type: CommandOptions.SubCommand, + options: [{ + name: "role", + description: "Role to confiure", + value: "role", + type: CommandOptions.Role, + required: true, + }] }, { - name: "role", - description: "Role to configure", - value: "role", - type: CommandOptions.Role, - required: true, + name: "remove", + description: "Remove configured role as bot admin", + value: "remove", + type: CommandOptions.SubCommand, + options: [{ + name: "role", + description: "Role to remove", + value: "role", + type: CommandOptions.Role, + required: true, + }] }, + { + name: "view", + description: "View the configured bot admin roles", + value: "view", + type: CommandOptions.SubCommand, + } ] }, { @@ -511,8 +526,9 @@ module.exports = { } case 'bot_admin_role': - if (args[0].options[0].value == 'add') { - const botAdminRoleId = args[0].options[1].value; + const bot_admin_config = args[0].options[0].name; + const botAdminRoleId = ['add', 'remove'].includes(bot_admin_config) ? args[0].options[0].options[0].value : null; + if (bot_admin_config == 'add') { client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$push: {"server.botAdminRoles": botAdminRoleId}}, (err, res) => { if (err) return client.sendInternalError(interaction, err); @@ -524,7 +540,7 @@ module.exports = { return interaction.send({ embeds: [successSetBotAdminRoleEmbed] }); - } else if (args[0].options[0].value== 'remove') { + } else if (bot_admin_config == 'remove') { if (!GuildDB.botAdminRoles.includes(botAdminRoleId)) { const nonAdminRoleEmbed = new EmbedBuilder() @@ -551,6 +567,30 @@ module.exports = { ) return interaction.send({ embeds: [promptRemoveAdminRole], components: [optRemoveAdminRole], flags: (1 << 6) }); + + } else if (bot_admin_config == 'view') { + + if (GuildDB.botAdminRoles.length == 0) { + const noBotAdminRoles = new EmbedBuilder() + .setColor(client.config.Colors.Default) + .setTitle('Admin Roles') + .setDescription('> There have been no configured admin roles'); + + return interaction.send({ embeds: [noBotAdminRoles] }); + } + + const botAdminRolesEmbed = new EmbedBuilder() + .setColor(client.config.Colors.Default) + .setTitle('Admin Roles') + + let des = ''; + for (let i = 0; i < GuildDB.botAdminRoles.length; i++) { + des += `\n> <@&${GuildDB.botAdminRoles[i]}>`; + } + botAdminRolesEmbed.setDescription(des); + + return interaction.send({ embeds: [botAdminRolesEmbed] }); + } case 'admin_role': diff --git a/commands/excluded.js b/commands/excluded.js index 8b39d72..2e8ebbf 100644 --- a/commands/excluded.js +++ b/commands/excluded.js @@ -24,7 +24,7 @@ module.exports = { let noExcludes = new EmbedBuilder() .setColor(client.config.Colors.Default) .setTitle('Excluded Roles') - .setDescription('> There have been no configured channels'); + .setDescription('> There have been no excluded roles'); return interaction.send({ embeds: [noExcludes] }); } diff --git a/package.json b/package.json index 6bd6974..0ac7804 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dayzr-bot", - "version": "13.3.8", + "version": "13.3.9", "description": "A General Purpose Discord Bot for DayZ Nitrado Servers.", "main": "index.js", "nodemonConfig": {