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