From 286cc5f9e339b5afe0eedf8806bec68e50c98039 Mon Sep 17 00:00:00 2001 From: Taken Date: Sun, 28 Jan 2024 17:47:16 +0100 Subject: [PATCH 1/3] Updated types --- src/typings/Types.ts | 10 ---------- src/typings/index.ts | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 12 deletions(-) delete mode 100644 src/typings/Types.ts diff --git a/src/typings/Types.ts b/src/typings/Types.ts deleted file mode 100644 index bf9708a..0000000 --- a/src/typings/Types.ts +++ /dev/null @@ -1,10 +0,0 @@ -type SnipeCache = { - author: string - content: string - channel: string - createdAt: number - deletedAt: number - attachments: string[] -} - -export default SnipeCache diff --git a/src/typings/index.ts b/src/typings/index.ts index c84b166..36d73a3 100644 --- a/src/typings/index.ts +++ b/src/typings/index.ts @@ -1,3 +1,13 @@ -import SnipeCache from "./Types" +import { ChatInputCommandInteraction } from "discord.js" +import { ExtendedClient } from "utils/Client" -export { SnipeCache } +export type SubcommandFunc = (interaction: ChatInputCommandInteraction, client?: ExtendedClient) => Promise + +export type SnipeCache = { + author: string + content: string + channel: string + createdAt: number + deletedAt: number + attachments: string[] +} From 4acc892aa0c30705b70d681ae7ebe9766d59619a Mon Sep 17 00:00:00 2001 From: Taken Date: Sun, 28 Jan 2024 17:47:59 +0100 Subject: [PATCH 2/3] Added purne subcommand to staff --- src/commands/staff.ts | 11 +++++ src/commands/staff/prune.ts | 86 +++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 src/commands/staff/prune.ts diff --git a/src/commands/staff.ts b/src/commands/staff.ts index 0a7ef52..28a8776 100644 --- a/src/commands/staff.ts +++ b/src/commands/staff.ts @@ -4,6 +4,7 @@ import { Command } from "interfaces" import help from "./staff/help" import beast from "./staff/beast" import updateDiscordRoles from "./staff/updatediscordroles" +import prune from "./staff/prune" export = { name: "staff", @@ -31,6 +32,11 @@ export = { .setRequired(true) ) ) + .addSubcommand(subcommand => + subcommand + .setName("prune") + .setDescription("Update the discord roles of all guild members") + ) .addSubcommand(subcommand => subcommand .setName("updatediscordroles") @@ -53,6 +59,11 @@ export = { return } + if (subcommand === "prune") { + prune(interaction) + return + } + if (subcommand === "updatediscordroles") { updateDiscordRoles(interaction) return diff --git a/src/commands/staff/prune.ts b/src/commands/staff/prune.ts new file mode 100644 index 0000000..149cdf5 --- /dev/null +++ b/src/commands/staff/prune.ts @@ -0,0 +1,86 @@ +import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ChatInputCommandInteraction, GuildMember } from "discord.js" +import { color, devMessage } from "config/options.json" +import env from "utils/Env" + +export default async function prune(interaction: ChatInputCommandInteraction): Promise { + await interaction.deferReply({ ephemeral: true }) + + if (interaction.user.id !== env.prod.dev) { + await interaction.editReply("You are not allowed to use this command.") + return + } + + const embedColor = Number(color.replace("#", "0x")) + const members = await interaction.guild!.members.fetch() + + await interaction.editReply({ + embeds: [{ + description: "Updating discord roles...", + color: embedColor + }] + }) + + const fields: { name: string, value: string }[] = [] + + for (const member of members) { + const roles = member[1].roles.cache + + if (roles.size !== 1) continue + + const guildMember = await interaction.guild!.members.fetch(member[1].id) + + fields.push({ + name: guildMember.user.username, + value: guildMember.user.id + }) + } + + await interaction.editReply({ + embeds: [{ + title: "Prune", + description: "Prune members with no roles", + fields: fields.splice(0, 5), + color: embedColor, + thumbnail: { + url: interaction.guild!.iconURL() || "" + }, + footer: { + icon_url: interaction.guild!.iconURL() || undefined, + text: interaction.guild?.name + " | " + devMessage + } + }], + components: [ + new ActionRowBuilder().addComponents( + new ButtonBuilder() + .setLabel("Confirm") + .setCustomId("staff_prune_confirm") + .setStyle(ButtonStyle.Danger) + .setEmoji("❗") + ) + ] + }).then(async () => { + const filter = (i: any) => i.customId === "staff_prune_confirm" && i.user.id === interaction.user.id + + const collector = interaction.channel!.createMessageComponentCollector({ filter, time: 60000 }) + + collector.on("collect", async i => { + await i.deferUpdate() + + const members = i.message.embeds[0].fields + + for (const member of members) { + const guildMember = await interaction.guild!.members.fetch(member.value) + + await i.guild?.members.kick(guildMember, "Pruned") + } + + await i.editReply({ + embeds: [{ + description: "Prruned all the members", + color: embedColor + }], + components: [] + }) + }) + }) +} From 5213ac11dbca3a5e8db5a24dce2bbd74e4b4c1e0 Mon Sep 17 00:00:00 2001 From: Taken Date: Sun, 28 Jan 2024 18:05:01 +0100 Subject: [PATCH 3/3] Removed unused import Signed-off-by: Taken --- src/commands/staff/prune.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/staff/prune.ts b/src/commands/staff/prune.ts index 149cdf5..12ffe8e 100644 --- a/src/commands/staff/prune.ts +++ b/src/commands/staff/prune.ts @@ -1,4 +1,4 @@ -import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ChatInputCommandInteraction, GuildMember } from "discord.js" +import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ChatInputCommandInteraction } from "discord.js" import { color, devMessage } from "config/options.json" import env from "utils/Env"