Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"ranks": [
{
"name": "IN_GAME_RANK_NAME",
"role": "DISCORD_ROLE_ID"
"roles": ["DISCORD_ROLE_ID"]
}
]
},
Expand Down
1 change: 1 addition & 0 deletions src/discord/commands/forceUpdateCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
description: "Update a user's roles",
moderatorOnly: true,
verificationCommand: true,
requiresBot: true,
options: [
{
name: "user",
Expand Down
1 change: 1 addition & 0 deletions src/discord/commands/forceUpdateEveryone.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
description: "Update a user's roles",
moderatorOnly: true,
verificationCommand: true,
requiresBot: true,

execute: async (interaction, doNotRespond = false) => {
try {
Expand Down
1 change: 1 addition & 0 deletions src/discord/commands/forceVerifyCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
description: "Connect Discord account to a Minecraft",
moderatorOnly: true,
verificationCommand: true,
requiresBot: true,
options: [
{
name: "user",
Expand Down
7 changes: 7 additions & 0 deletions src/discord/commands/unverifyCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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)
Expand Down
28 changes: 21 additions & 7 deletions src/discord/commands/updateCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -39,22 +40,31 @@ 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) {
if (role === config.verification.verifiedRole && config.verification.removeVerificationRole === false) {
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)) {
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/discord/commands/verifyCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
name: "verify",
description: "Connect your Discord account to Minecraft",
verificationCommand: true,
requiresBot: true,
options: [
{
name: "username",
Expand Down
Loading