3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

Add total time taken to !massban result message

This commit is contained in:
Dragory 2021-05-22 13:32:27 +03:00
parent b6915671ca
commit 772d13fd94
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1

View file

@ -12,6 +12,8 @@ import { waitForReply } from "knub/dist/helpers";
import { ignoreEvent } from "../functions/ignoreEvent"; import { ignoreEvent } from "../functions/ignoreEvent";
import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin"; import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
import { performance } from "perf_hooks";
import { humanizeDurationShort } from "../../../humanizeDurationShort";
export const MassbanCmd = modActionsCmd({ export const MassbanCmd = modActionsCmd({
trigger: "massban", trigger: "massban",
@ -54,6 +56,7 @@ export const MassbanCmd = modActionsCmd({
const loadingMsg = await msg.channel.createMessage("Banning..."); const loadingMsg = await msg.channel.createMessage("Banning...");
// Ban each user and count failed bans (if any) // Ban each user and count failed bans (if any)
const startTime = performance.now();
const failedBans: string[] = []; const failedBans: string[] = [];
const casesPlugin = pluginData.getPlugin(CasesPlugin); const casesPlugin = pluginData.getPlugin(CasesPlugin);
for (const [i, userId] of args.userIds.entries()) { for (const [i, userId] of args.userIds.entries()) {
@ -84,6 +87,9 @@ export const MassbanCmd = modActionsCmd({
} }
} }
const totalTime = performance.now() - startTime;
const formattedTimeTaken = humanizeDurationShort(totalTime);
// Clear loading indicator // Clear loading indicator
loadingMsg.delete().catch(noop); loadingMsg.delete().catch(noop);
@ -103,10 +109,16 @@ export const MassbanCmd = modActionsCmd({
sendSuccessMessage( sendSuccessMessage(
pluginData, pluginData,
msg.channel, msg.channel,
`Banned ${successfulBanCount} users, ${failedBans.length} failed: ${failedBans.join(" ")}`, `Banned ${successfulBanCount} users in ${formattedTimeTaken}, ${failedBans.length} failed: ${failedBans.join(
" ",
)}`,
); );
} else { } else {
sendSuccessMessage(pluginData, msg.channel, `Banned ${successfulBanCount} users successfully`); sendSuccessMessage(
pluginData,
msg.channel,
`Banned ${successfulBanCount} users successfully in ${formattedTimeTaken}`,
);
} }
} }
}, },