Merge branch 'dev' into 'main'

Dev

See merge request illegitimate/illegitimate-bot!205
This commit is contained in:
2024-01-28 17:05:43 +00:00
4 changed files with 109 additions and 12 deletions

View File

@@ -4,6 +4,7 @@ import { Command } from "interfaces"
import help from "./staff/help" import help from "./staff/help"
import beast from "./staff/beast" import beast from "./staff/beast"
import updateDiscordRoles from "./staff/updatediscordroles" import updateDiscordRoles from "./staff/updatediscordroles"
import prune from "./staff/prune"
export = { export = {
name: "staff", name: "staff",
@@ -31,6 +32,11 @@ export = {
.setRequired(true) .setRequired(true)
) )
) )
.addSubcommand(subcommand =>
subcommand
.setName("prune")
.setDescription("Update the discord roles of all guild members")
)
.addSubcommand(subcommand => .addSubcommand(subcommand =>
subcommand subcommand
.setName("updatediscordroles") .setName("updatediscordroles")
@@ -53,6 +59,11 @@ export = {
return return
} }
if (subcommand === "prune") {
prune(interaction)
return
}
if (subcommand === "updatediscordroles") { if (subcommand === "updatediscordroles") {
updateDiscordRoles(interaction) updateDiscordRoles(interaction)
return return

View File

@@ -0,0 +1,86 @@
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ChatInputCommandInteraction } from "discord.js"
import { color, devMessage } from "config/options.json"
import env from "utils/Env"
export default async function prune(interaction: ChatInputCommandInteraction): Promise<void> {
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<ButtonBuilder>().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: []
})
})
})
}

View File

@@ -1,10 +0,0 @@
type SnipeCache = {
author: string
content: string
channel: string
createdAt: number
deletedAt: number
attachments: string[]
}
export default SnipeCache

View File

@@ -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<void>
export type SnipeCache = {
author: string
content: string
channel: string
createdAt: number
deletedAt: number
attachments: string[]
}