Merge branch 'dev' into 'main'

Dev

See merge request illegitimate/illegitimate-bot!217
This commit is contained in:
2024-02-08 17:08:18 +00:00

View File

@@ -1,9 +1,9 @@
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ChatInputCommandInteraction } from "discord.js" import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, ChatInputCommandInteraction, ComponentType } from "discord.js"
import { embedColor, devMessage } from "config/options" import { embedColor, devMessage } from "config/options"
import env from "utils/Env" import env from "utils/Env"
export default async function prune(interaction: ChatInputCommandInteraction): Promise<void> { export default async function prune(interaction: ChatInputCommandInteraction): Promise<void> {
await interaction.deferReply({ ephemeral: true }) await interaction.deferReply()
if (interaction.user.id !== env.prod.dev) { if (interaction.user.id !== env.prod.dev) {
await interaction.editReply("You are not allowed to use this command.") await interaction.editReply("You are not allowed to use this command.")
@@ -34,6 +34,10 @@ export default async function prune(interaction: ChatInputCommandInteraction): P
}) })
} }
const id = Math.random().toString(32).slice(2)
const buttonid = "button-" + id
const cancelid = "cancel-" + id
await interaction.editReply({ await interaction.editReply({
embeds: [{ embeds: [{
title: "Prune", title: "Prune",
@@ -52,34 +56,65 @@ export default async function prune(interaction: ChatInputCommandInteraction): P
new ActionRowBuilder<ButtonBuilder>().addComponents( new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder() new ButtonBuilder()
.setLabel("Confirm") .setLabel("Confirm")
.setCustomId("staff_prune_confirm") .setCustomId(buttonid)
.setStyle(ButtonStyle.Danger) .setStyle(ButtonStyle.Danger)
.setEmoji("❗") .setEmoji("❗"),
new ButtonBuilder()
.setLabel("Cancel")
.setCustomId(cancelid)
.setStyle(ButtonStyle.Primary)
.setEmoji("❌")
) )
] ]
}).then(async () => { }).then(async (m) => {
const filter = (i: any) => i.customId === "staff_prune_confirm" && i.user.id === interaction.user.id const collector = interaction.channel!.createMessageComponentCollector({
componentType: ComponentType.Button,
filter: (i: ButtonInteraction) =>
(i.customId === buttonid || i.customId === cancelid) &&
i.user.id === interaction.user.id,
time: 5 * 60 * 1000
})
const collector = interaction.channel!.createMessageComponentCollector({ filter, time: 60000 }) collector.on("end", async () => {
// ...
})
collector.on("collect", async i => { collector.on("collect", async i => {
if (i.customId === cancelid) {
await m.edit({
components: []
})
await i.reply({
embeds: [{
description: "Cancelled",
color: embedColor
}],
}).then(() => {
collector.stop()
})
return
} else if (i.customId === buttonid) {
await i.deferUpdate() await i.deferUpdate()
const members = i.message.embeds[0].fields const members = i.message.embeds[0].fields
for (const member of members) { for (const member of members) {
const guildMember = await interaction.guild!.members.fetch(member.value) const guildMember = await interaction.guild!.members.fetch(member.value)
await i.guild?.members.kick(guildMember, "Pruned") await i.guild?.members.kick(guildMember, "Pruned")
} }
await m.edit({
components: [],
})
await i.editReply({ await i.editReply({
embeds: [{ embeds: [{
description: "Prruned all the members", description: "Pruned all the members",
color: embedColor color: embedColor
}], }],
components: [] }).then(() => {
collector.stop()
}) })
}
}) })
}) })
} }