diff --git a/config.example.json b/config.example.json index daa15e83..43b66fc4 100644 --- a/config.example.json +++ b/config.example.json @@ -112,7 +112,7 @@ "ranks": [ { "name": "IN_GAME_RANK_NAME", - "role": "DISCORD_ROLE_ID" + "roles": ["DISCORD_ROLE_ID"] } ] }, diff --git a/src/discord/commands/forceUpdateCommand.js b/src/discord/commands/forceUpdateCommand.js index 44e33eed..7d96ff84 100644 --- a/src/discord/commands/forceUpdateCommand.js +++ b/src/discord/commands/forceUpdateCommand.js @@ -5,6 +5,7 @@ module.exports = { description: "Update a user's roles", moderatorOnly: true, verificationCommand: true, + requiresBot: true, options: [ { name: "user", diff --git a/src/discord/commands/forceUpdateEveryone.js b/src/discord/commands/forceUpdateEveryone.js index ac11be4d..692f4c0a 100644 --- a/src/discord/commands/forceUpdateEveryone.js +++ b/src/discord/commands/forceUpdateEveryone.js @@ -7,6 +7,7 @@ module.exports = { description: "Update a user's roles", moderatorOnly: true, verificationCommand: true, + requiresBot: true, execute: async (interaction, doNotRespond = false) => { try { diff --git a/src/discord/commands/forceVerifyCommand.js b/src/discord/commands/forceVerifyCommand.js index 97d25f8b..fab167fc 100644 --- a/src/discord/commands/forceVerifyCommand.js +++ b/src/discord/commands/forceVerifyCommand.js @@ -5,6 +5,7 @@ module.exports = { description: "Connect Discord account to a Minecraft", moderatorOnly: true, verificationCommand: true, + requiresBot: true, options: [ { name: "user", diff --git a/src/discord/commands/unverifyCommand.js b/src/discord/commands/unverifyCommand.js index 065e1ce6..75727dea 100644 --- a/src/discord/commands/unverifyCommand.js +++ b/src/discord/commands/unverifyCommand.js @@ -7,6 +7,7 @@ const { EmbedBuilder } = require("discord.js"); module.exports = { name: "unverify", description: "Remove your linked Minecraft account", + requiresBot: true, verificationCommand: true, execute: async (interaction) => { @@ -36,6 +37,12 @@ module.exports = { { text: `by @.kathund | /help [command] for more information`, iconURL: "https://i.imgur.com/uUuZx2E.png" }, ); await interaction.followUp({ embeds: [updateRole] }); + const updateRolesCommand = require("./updateCommand.js"); + if (updateRolesCommand === undefined) { + throw new HypixelDiscordChatBridgeError("The update command does not exist. Please contact an administrator."); + } + + await updateRolesCommand.execute(interaction, undefined, true); } catch (error) { const errorEmbed = new EmbedBuilder() .setColor(15548997) diff --git a/src/discord/commands/updateCommand.js b/src/discord/commands/updateCommand.js index 41da8efd..2e206ffc 100644 --- a/src/discord/commands/updateCommand.js +++ b/src/discord/commands/updateCommand.js @@ -9,9 +9,10 @@ const { readFileSync } = require("fs"); module.exports = { name: "update", verificationCommand: true, + requiresBot: true, description: "Update your current roles", - execute: async (interaction, user) => { + execute: async (interaction, user = undefined, unverify = false) => { try { const linkedData = readFileSync("data/linked.json"); if (!linkedData) { @@ -39,7 +40,7 @@ module.exports = { const roles = [ config.verification.verifiedRole, config.verification.guildMemberRole, - ...config.verification.ranks.map((r) => r.role), + ...config.verification.ranks.flatMap((r) => r.roles), ]; for (const role of roles) { @@ -47,14 +48,23 @@ module.exports = { continue; } + if (role === config.verification.unverifiedRole) { + continue; + } + if (interaction.member.roles.cache.has(role)) { await interaction.member.roles.remove(role, "Updated Roles"); } } + if (!interaction.member.roles.cache.has(config.verification.unverifiedRole)) { + await interaction.member.roles.add(config.verification.unverifiedRole, "Updated Roles"); + } + interaction.member.setNickname(null, "Updated Roles"); - throw new HypixelDiscordChatBridgeError("You are not linked to a Minecraft account."); + if (unverify === false) throw new HypixelDiscordChatBridgeError("You are not linked to a Minecraft account."); + return; } if (!interaction.member.roles.cache.has(config.verification.verifiedRole)) { @@ -77,13 +87,17 @@ module.exports = { if (config.verification.ranks.length > 0 && guildMember.rank) { const rank = config.verification.ranks.find((r) => r.name.toLowerCase() == guildMember.rank.toLowerCase()); if (rank) { - for (const role of config.verification.ranks) { - if (interaction.member.roles.cache.has(role.role)) { - await interaction.member.roles.remove(role.role, "Updated Roles"); + for (const rankRole of config.verification.ranks) { + for (const role of rankRole.roles) { + if (interaction.member.roles.cache.has(role)) { + await interaction.member.roles.remove(role, "Updated Roles"); + } } } - await interaction.member.roles.add(rank.role, "Updated Roles"); + for (const role of rank.roles) { + await interaction.member.roles.add(role, "Updated Roles"); + } } } } else { diff --git a/src/discord/commands/verifyCommand.js b/src/discord/commands/verifyCommand.js index 9ef48579..ceee0718 100644 --- a/src/discord/commands/verifyCommand.js +++ b/src/discord/commands/verifyCommand.js @@ -8,6 +8,7 @@ module.exports = { name: "verify", description: "Connect your Discord account to Minecraft", verificationCommand: true, + requiresBot: true, options: [ { name: "username",