From 67b869c40d2d3fabbc6fe4c61466d793dbb45529 Mon Sep 17 00:00:00 2001 From: Taken Date: Mon, 5 Feb 2024 11:53:05 +0100 Subject: [PATCH 1/3] Added remove guild roles subcommand --- src/commands/staff.ts | 19 ++++-- src/commands/staff/removeguildroles.ts | 63 +++++++++++++++++++ .../{updatediscordroles.ts => updateall.ts} | 2 +- 3 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 src/commands/staff/removeguildroles.ts rename src/commands/staff/{updatediscordroles.ts => updateall.ts} (97%) diff --git a/src/commands/staff.ts b/src/commands/staff.ts index 40f3277..a24b1a3 100644 --- a/src/commands/staff.ts +++ b/src/commands/staff.ts @@ -3,8 +3,9 @@ import { embedColor, devMessage } from "config/options" import { Command } from "interfaces" import help from "./staff/help" import beast from "./staff/beast" -import updateDiscordRoles from "./staff/updatediscordroles" +import updateAll from "./staff/updateall" import prune from "./staff/prune" +import removeGuildRoles from "./staff/removeguildroles" export = { name: "staff", @@ -39,7 +40,12 @@ export = { ) .addSubcommand(subcommand => subcommand - .setName("updatediscordroles") + .setName("removeguildroles") + .setDescription("Update the discord roles of all guild members") + ) + .addSubcommand(subcommand => + subcommand + .setName("updateall") .setDescription("Update the discord roles of all guild members") ) .setDefaultMemberPermissions(PermissionFlagsBits.Administrator) @@ -63,8 +69,13 @@ export = { return } - if (subcommand === "updatediscordroles") { - updateDiscordRoles(interaction) + if (subcommand === "removeguildroles") { + removeGuildRoles(interaction) + return + } + + if (subcommand === "updateall") { + updateAll(interaction) return } diff --git a/src/commands/staff/removeguildroles.ts b/src/commands/staff/removeguildroles.ts new file mode 100644 index 0000000..d693256 --- /dev/null +++ b/src/commands/staff/removeguildroles.ts @@ -0,0 +1,63 @@ +import { embedColor, hypixelGuildID } from "config/options" +import { ChatInputCommandInteraction, GuildMember } from "discord.js" +import verify from "schemas/verifySchema" +import { GuildData } from "interfaces" +import env from "utils/Env" +import { getGuild } from "utils/Hypixel" +import roleManage from "utils/functions/rolesmanage" + +export default async function removeGuildRoles(interaction: ChatInputCommandInteraction): Promise { + await interaction.deferReply() + + const discordMember = interaction.member as GuildMember + + if (discordMember.user.id !== env.prod.dev) { + await interaction.editReply({ + embeds: [{ + description: "You do not have permission to use this command.", + color: embedColor + }] + }) + return + } + + const guildMembers = await interaction.guild!.members.fetch().then( + members => members.map(member => { + return { + id: member.id, + member: member + } + }) + ) + + const guildData = (await getGuild(hypixelGuildID, "id")) as GuildData + + const hypixelGuildMembers = guildData.members.map(gmember => gmember.uuid) + + const allVerifiedUsers = (await verify.find({})) as { + userID: string + uuid: string + }[] + + const verifiedUsers = allVerifiedUsers.map(user => { + return { + userID: user.userID, + uuid: user.uuid + } + }) + + for (const gmember of guildMembers) { + const gmemberuuid = verifiedUsers.find(user => user.userID === gmember.id)?.uuid + const roles = roleManage("default") + + if (!gmemberuuid) { + await gmember.member.roles.remove(roles.rolesToRemove) + continue + } + + if (!hypixelGuildMembers.includes(gmemberuuid)) { + await gmember.member.roles.remove(roles.rolesToRemove) + continue + } + } +} \ No newline at end of file diff --git a/src/commands/staff/updatediscordroles.ts b/src/commands/staff/updateall.ts similarity index 97% rename from src/commands/staff/updatediscordroles.ts rename to src/commands/staff/updateall.ts index 558c890..9d1154c 100644 --- a/src/commands/staff/updatediscordroles.ts +++ b/src/commands/staff/updateall.ts @@ -8,7 +8,7 @@ import env from "utils/Env" import { getGuild } from "utils/Hypixel" import { GuildData } from "interfaces" -export default async function updateDiscordRoles(interaction: ChatInputCommandInteraction): Promise { +export default async function updateAll(interaction: ChatInputCommandInteraction): Promise { await interaction.deferReply() const discordMember = interaction.member as GuildMember From da9bb585624b270576899b97c166733bc894318b Mon Sep 17 00:00:00 2001 From: Taken Date: Mon, 5 Feb 2024 11:56:29 +0100 Subject: [PATCH 2/3] Updated update commands to remove waitinglist role --- src/commands-contextmenu/updateuser.ts | 3 +++ src/commands/forceupdate.ts | 3 +++ src/commands/update.ts | 3 +++ 3 files changed, 9 insertions(+) diff --git a/src/commands-contextmenu/updateuser.ts b/src/commands-contextmenu/updateuser.ts index 6f9f9fc..57dc3c3 100644 --- a/src/commands-contextmenu/updateuser.ts +++ b/src/commands-contextmenu/updateuser.ts @@ -4,6 +4,7 @@ import { ContextMenu } from "interfaces" import verifySchema from "schemas/verifySchema" import { getGuild, getHeadURL, getIGN } from "utils/Hypixel" import roleManage from "utils/functions/rolesmanage" +import { waitingListRole } from "config/roles" export = { name: "Update User", @@ -134,6 +135,8 @@ export = { replyRank = "Member" } + await user.roles.remove(waitingListRole) + await interaction.editReply({ embeds: [{ description: usermentioned + " was given the " + replyRank + " role.", diff --git a/src/commands/forceupdate.ts b/src/commands/forceupdate.ts index 461c57e..45ad37c 100644 --- a/src/commands/forceupdate.ts +++ b/src/commands/forceupdate.ts @@ -4,6 +4,7 @@ import { hypixelGuildID, embedColor, devMessage } from "config/options" import verify from "schemas/verifySchema" import { Command } from "interfaces" import roleManage from "utils/functions/rolesmanage" +import { waitingListRole } from "config/roles" export = { name: "forceupdate", @@ -140,6 +141,8 @@ export = { replyRank = "Member" } + await user.roles.remove(waitingListRole) + await interaction.editReply({ embeds: [{ description: usermentioned + " was given the the " + replyRank + " role.", diff --git a/src/commands/update.ts b/src/commands/update.ts index ad39ab6..d9141a3 100644 --- a/src/commands/update.ts +++ b/src/commands/update.ts @@ -4,6 +4,7 @@ import verify from "schemas/verifySchema" import { embedColor, hypixelGuildID, devMessage } from "config/options" import roleManage from "utils/functions/rolesmanage" import { Command } from "interfaces" +import { waitingListRole } from "config/roles" export = { name: "update", @@ -123,6 +124,8 @@ export = { replyRank = "Member" } + await user.roles.remove(waitingListRole) + await interaction.editReply({ embeds: [{ description: "Updated your roles to `" + replyRank + "`", From b2420e949c2feb4abd3c567de834ec1c8f00fe47 Mon Sep 17 00:00:00 2001 From: Taken Date: Mon, 5 Feb 2024 12:09:41 +0100 Subject: [PATCH 3/3] Updated a bunch of commands --- src/commands-contextmenu/updateuser.ts | 4 +++- src/commands/forceupdate.ts | 4 +++- src/commands/staff.ts | 2 +- src/commands/staff/updateall.ts | 2 +- src/commands/update.ts | 4 +++- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/commands-contextmenu/updateuser.ts b/src/commands-contextmenu/updateuser.ts index 57dc3c3..a63b435 100644 --- a/src/commands-contextmenu/updateuser.ts +++ b/src/commands-contextmenu/updateuser.ts @@ -135,7 +135,9 @@ export = { replyRank = "Member" } - await user.roles.remove(waitingListRole) + if (user.roles.cache.has(waitingListRole)) { + await user.roles.remove(waitingListRole, "User was force updated.") + } await interaction.editReply({ embeds: [{ diff --git a/src/commands/forceupdate.ts b/src/commands/forceupdate.ts index 45ad37c..f623532 100644 --- a/src/commands/forceupdate.ts +++ b/src/commands/forceupdate.ts @@ -141,7 +141,9 @@ export = { replyRank = "Member" } - await user.roles.remove(waitingListRole) + if (user.roles.cache.has(waitingListRole)) { + await user.roles.remove(waitingListRole, "User was force updated.") + } await interaction.editReply({ embeds: [{ diff --git a/src/commands/staff.ts b/src/commands/staff.ts index a24b1a3..4f3c621 100644 --- a/src/commands/staff.ts +++ b/src/commands/staff.ts @@ -41,7 +41,7 @@ export = { .addSubcommand(subcommand => subcommand .setName("removeguildroles") - .setDescription("Update the discord roles of all guild members") + .setDescription("Remove guild roles from non members") ) .addSubcommand(subcommand => subcommand diff --git a/src/commands/staff/updateall.ts b/src/commands/staff/updateall.ts index 9d1154c..9fd822f 100644 --- a/src/commands/staff/updateall.ts +++ b/src/commands/staff/updateall.ts @@ -72,7 +72,7 @@ export default async function updateAll(interaction: ChatInputCommandInteraction await gmember.member.roles.remove(rolesToremove, "Updating all discord members") continue } else { - await gmember.member.roles.add(verifyTick) + await gmember.member.roles.add(verifyTick, "Updating all discord members") console.log(color(" Added verified tick to " + gmember.member.user.username, "lavender")) } diff --git a/src/commands/update.ts b/src/commands/update.ts index d9141a3..2b97eb2 100644 --- a/src/commands/update.ts +++ b/src/commands/update.ts @@ -124,7 +124,9 @@ export = { replyRank = "Member" } - await user.roles.remove(waitingListRole) + if (user.roles.cache.has(waitingListRole)) { + await user.roles.remove(waitingListRole, "User used the update command") + } await interaction.editReply({ embeds: [{