3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-07-07 11:07:19 +00:00

Made mass action reason part of the slash command options

This commit is contained in:
Lily Bergonzat 2024-02-24 20:30:11 +01:00
parent 4d8b6b5cd7
commit 91025d8569
19 changed files with 213 additions and 88 deletions

View file

@ -1,6 +1,5 @@
import { ChatInputCommandInteraction, GuildMember, Message, Snowflake } from "discord.js";
import { Attachment, ChatInputCommandInteraction, GuildMember, Message, Snowflake } from "discord.js";
import { GuildPluginData } from "knub";
import { waitForReply } from "knub/helpers";
import { CaseTypes } from "../../../../data/CaseTypes";
import { LogType } from "../../../../data/LogType";
import { humanizeDurationShort } from "../../../../humanizeDurationShort";
@ -19,6 +18,8 @@ export async function actualMassBanCmd(
context: Message | ChatInputCommandInteraction,
userIds: string[],
author: GuildMember,
reason: string,
attachments: Attachment[],
) {
// Limit to 100 users at once (arbitrary?)
if (userIds.length > 100) {
@ -26,25 +27,12 @@ export async function actualMassBanCmd(
return;
}
// Ask for ban reason (cleaner this way instead of trying to cram it into the args)
sendContextResponse(context, "Ban reason? `cancel` to cancel");
const banReasonReply = await waitForReply(pluginData.client, await getContextChannel(context), author.id);
if (!banReasonReply || !banReasonReply.content || banReasonReply.content.toLowerCase().trim() === "cancel") {
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, "Cancelled");
if (await handleAttachmentLinkDetectionAndGetRestriction(pluginData, context, reason)) {
return;
}
if (await handleAttachmentLinkDetectionAndGetRestriction(pluginData, context, banReasonReply.content)) {
return;
}
const banReason = await formatReasonWithMessageLinkForAttachments(pluginData, banReasonReply.content, context, [
...banReasonReply.attachments.values(),
]);
const banReasonWithAttachments = formatReasonWithAttachments(banReasonReply.content, [
...banReasonReply.attachments.values(),
]);
const banReason = await formatReasonWithMessageLinkForAttachments(pluginData, reason, context, attachments);
const banReasonWithAttachments = formatReasonWithAttachments(reason, attachments);
// Verify we can act on each of the users specified
for (const userId of userIds) {
@ -64,7 +52,7 @@ export async function actualMassBanCmd(
pluginData.state.massbanQueue.length === 0
? "Banning..."
: `Massban queued. Waiting for previous massban to finish (max wait ${maxWaitTimeFormatted}).`;
const loadingMsg = await sendContextResponse(context, initialLoadingText);
const loadingMsg = await sendContextResponse(context, { content: initialLoadingText, ephemeral: true });
const waitTimeStart = performance.now();
const waitingInterval = setInterval(() => {
@ -78,11 +66,20 @@ export async function actualMassBanCmd(
clearInterval(waitingInterval);
if (pluginData.state.unloaded) {
void loadingMsg.delete().catch(noop);
if (isContextInteraction(context)) {
void context.deleteReply().catch(noop);
} else {
void loadingMsg.delete().catch(noop);
}
return;
}
void loadingMsg.edit("Banning...").catch(noop);
if (isContextInteraction(context)) {
void context.editReply("Banning...").catch(noop);
} else {
void loadingMsg.edit("Banning...").catch(noop);
}
// Ban each user and count failed bans (if any)
const startTime = performance.now();
@ -124,15 +121,23 @@ export async function actualMassBanCmd(
// Send a status update every 10 bans
if ((i + 1) % 10 === 0) {
loadingMsg.edit(`Banning... ${i + 1}/${userIds.length}`).catch(noop);
const newLoadingMessageContent = `Banning... ${i + 1}/${userIds.length}`;
if (isContextInteraction(context)) {
void context.editReply(newLoadingMessageContent).catch(noop);
} else {
loadingMsg.edit(newLoadingMessageContent).catch(noop);
}
}
}
const totalTime = performance.now() - startTime;
const formattedTimeTaken = humanizeDurationShort(totalTime, { round: true });
// Clear loading indicator
loadingMsg.delete().catch(noop);
if (!isContextInteraction(context)) {
// Clear loading indicator
loadingMsg.delete().catch(noop);
}
const successfulBanCount = userIds.length - failedBans.length;
if (successfulBanCount === 0) {