From 5dd6a5059aa73a9a741ca764db4852fdea9a6d7b Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Sun, 21 Aug 2022 18:36:52 -0700 Subject: [PATCH] bot admin --- commands/money.js | 7 +++ commands/settings.js | 124 +++++++++++++++++++++++++++++++++++----- structures/QuarksBot.js | 2 + 3 files changed, 118 insertions(+), 15 deletions(-) diff --git a/commands/money.js b/commands/money.js index e909630..b3bb5d3 100644 --- a/commands/money.js +++ b/commands/money.js @@ -68,6 +68,13 @@ module.exports = { return interaction.send(`You are not allowed to use the bot in this channel.`); } + const permissions = bitfieldCalculator.permissions(interaction.member.permissions); + let canUseCommand = false; + + if (permissions.includes("MANAGE_GUILD")) canUseCommand = true; + if (client.exists(GuildDB.botAdmin) && interaction.member.roles.includes(GuildDB.botAdmin)) canUseCommand = true; + if (!canUseCommand) return interaction.send('You don\'t have the permissions to use this command.'); + let targetUserID = args[0].options[0].value.replace('<@!', '').replace('>', ''); let banking = await client.dbo.collection("banks").findOne({"account.userID": targetUserID}).then(banking => banking); diff --git a/commands/settings.js b/commands/settings.js index 7a05a70..4df30a3 100644 --- a/commands/settings.js +++ b/commands/settings.js @@ -210,6 +210,33 @@ module.exports = { }, ], }, + { + name: "bot_admin_role", + description: "Set/remove bot admin role", + value: "bot_admin_role", + type: 2, + options: [ + { + name: "set", + description: "Set role", + value: "role", + type: 8, + options: [{ + name: "role", + description: "Role to set", + value: "role", + type: 8, + required: true, + }] + }, + { + name: "remove", + description: "Remove role", + value: "remove", + type: 1, + }, + ] + }, { name: "commercial_role", description: "Set/remove commercial role", @@ -324,20 +351,11 @@ module.exports = { } const permissions = bitfieldCalculator.permissions(interaction.member.permissions); - let canUseCommand = false; - if (permissions.includes("MANAGE_GUILD")) { - canUseCommand = true; - } - - if (client.exists(GuildDB.botAdmin) && interaction.member.roles.includes(GuildDB.botAdmin)) { - canUseCommand = true; - } - - if (!canUseCommand) { - return interaction.send('You don\'t have the permissions to use this command.'); - } + if (permissions.includes("MANAGE_GUILD")) canUseCommand = true; + if (client.exists(GuildDB.botAdmin) && interaction.member.roles.includes(GuildDB.botAdmin)) canUseCommand = true; + if (!canUseCommand) return interaction.send('You don\'t have the permissions to use this command.'); if (args[0].name == 'allowed_channels') { const channelid = args[0].options[0].options[0].value; @@ -1037,7 +1055,7 @@ module.exports = { .setColor('GREEN'); return interaction.send({ embeds: [successEmbed] }); - + } else if (args[0].options[0].name== 'remove') { const prompt = new MessageEmbed() .setTitle(`Are you sure you want to remove this role as dispatcher role?`) @@ -1087,9 +1105,82 @@ module.exports = { return ButtonInteraction.update({ content: '', embeds: [successEmbed], components: [] }); }); - return; } + return; + } else if (args[0].name == 'bot_admin_role') { + + if (args[0].options[0].name == 'set') { + const roleId = args[0].options[0].options[0].value; + + client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$set:{"server.botAdmin": roleId}}, function(err, res) { + if (err) { + client.log(err); + const embed = new MessageEmbed() + .setDescriptions(`**Internal Error:** ${err}\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`) + .setColor("RED") + + return interaction.send({ embeds: [embed] }); + } + }); + + const successEmbed = new MessageEmbed() + .setDescription(`Successfully set <@&${roleId}> as a bot admin role.\nUsers with this role can use restricted commands.`) + .setColor('GREEN'); + + return interaction.send({ embeds: [successEmbed] }); + + } else if (args[0].options[0].name== 'remove') { + const prompt = new MessageEmbed() + .setTitle(`Are you sure you want to remove this role as a bot admin?`) + .setColor(client.config.EmbedColor) + + const opt = new MessageActionRow() + .addComponents( + new MessageButton() + .setCustomId(`yes-${interaction.member.user.id}`) + .setLabel("Yes") + .setStyle("DANGER"), + new MessageButton() + .setCustomId(`no-${interaction.member.user.id}`) + .setLabel("No") + .setStyle("SUCCESS") + ) + + interaction.send({ embeds: [prompt], components: [opt], ephemeral: true }); + + client.on("interactionCreate", ButtonInteraction => { + if(!ButtonInteraction.isButton()) return; + const queryString = ButtonInteraction.customId; + if (!queryString.endsWith(ButtonInteraction.member.user.id)) { + return ButtonInteraction.reply({ + content: "This button is not for you", + ephemeral: true + }) + } + let action = ''; + if (queryString==`yes-${interaction.member.user.id}`) { + action = 'removed'; + client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$set: {"server.botAdmin": null}}, function(err, res) { + if (err) { + client.log(err); + const embed = new MessageEmbed() + .setDescriptions(`**Internal Error:** ${err}\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`) + .setColor("RED") + + return interaction.send({ embeds: [embed] }); + } + }); + } else if (queryString==`no-${interaction.member.user.id}`) action = 'kept'; + + const successEmbed = new MessageEmbed() + .setColor("GREEN") + .setTitle(`Successfully ${action} <@&${roleId}> as dispatcher role.`) + + return ButtonInteraction.update({ content: '', embeds: [successEmbed], components: [] }); + }); + } + return; } else if (args[0].name == 'only_officers_search') { const setting = args[0].options[0]; client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$set: {"server.onlyOfficersSearch": setting}}, function(err, res) { @@ -1132,6 +1223,8 @@ module.exports = { const dispatchRoleColor = GuildDB.dispatcherRole ? `+ ` : '- '; const dispatchChannel = GuildDB.dispatchChannel ? `\n╚➤ <#${GuildDB.dispatcherRole}>` : ''; const dispatchChannelColor = GuildDB.dispatchChannel ? `+ ` : '- '; + const botAdminRole = GuildDB.botAdmin ? `\n╚➤ <#${GuildDB.botAdmin}>` : ''; + const botAdminRoleColor = GuildDB.botAdmin ? `+ ` : '- '; const settingsEmbed = new MessageEmbed() .setColor(client.config.EmbedColor) @@ -1148,7 +1241,8 @@ module.exports = { { name: 'Has Officer Role?', value: `\`\`\`diff\n${officerRoleColor}${client.exists(GuildDB.officerRole)}\`\`\`${officerRole}`, inline: true }, { name: 'Only Officers Search?', value: `\`\`\`diff\n${oosColor}${oos}\`\`\``, inline: true }, { name: 'Has Disptach Role?', value: `\`\`\`diff\n${dispatchRoleColor}${client.exists(GuildDB.dispatcherRole)}\`\`\`${dispatchRole}`, inline: true }, - { name: 'Has Dispatch Channel?', value: `\`\`\`diff\n${dispatchChannelColor}${client.exists(GuildDB.dispatchChannel)}\`\`\`${dispatchChannel}`, inline: true }, + { name: 'Has Dispatch Channel?', value: `\`\`\`diff\n${dispatchChannelColor}${client.exists(GuildDB.dispatchChannel)}\`\`\`${dispatchChannel}`, inline: true }, + { name: 'Has bot admin role?', value: `\`\`\`diff\n${botAdminRoleColor}${client.exists(GuildDB.botAdmin)}\`\`\`${botAdminRole}`, inline: true }, ); return interaction.send({ embeds: [settingsEmbed] }); diff --git a/structures/QuarksBot.js b/structures/QuarksBot.js index 3a419d7..427e06f 100644 --- a/structures/QuarksBot.js +++ b/structures/QuarksBot.js @@ -150,6 +150,7 @@ class QuarksBot extends Client { dispatchChannel: null, startingBalance: 1000.00, incomeRoles: [], + botAdmin: null, commercialRole: null, officerRole: null, dispatcherRole: null, @@ -176,6 +177,7 @@ class QuarksBot extends Client { officerRole: guild.server.officerRole, dispatcherRole: guild.server.dispatcherRole, onlyOfficersSearch: guild.server.onlyOfficersSearch, + botAdmin: guild.server.botAdmin, } return guildData; }