
* update pkgs Signed-off-by: GitHub <noreply@github.com> * new knub typings Signed-off-by: GitHub <noreply@github.com> * more pkg updates Signed-off-by: GitHub <noreply@github.com> * more fixes Signed-off-by: GitHub <noreply@github.com> * channel typings Signed-off-by: GitHub <noreply@github.com> * more message utils typings fixes Signed-off-by: GitHub <noreply@github.com> * migrate permissions Signed-off-by: GitHub <noreply@github.com> * fix: InternalPoster webhookables Signed-off-by: GitHub <noreply@github.com> * djs typings: Attachment & Util Signed-off-by: GitHub <noreply@github.com> * more typings Signed-off-by: GitHub <noreply@github.com> * fix: rename permissionNames Signed-off-by: GitHub <noreply@github.com> * more fixes Signed-off-by: GitHub <noreply@github.com> * half the number of errors * knub commands => messageCommands Signed-off-by: GitHub <noreply@github.com> * configPreprocessor => configParser Signed-off-by: GitHub <noreply@github.com> * fix channel.messages Signed-off-by: GitHub <noreply@github.com> * revert automod any typing Signed-off-by: GitHub <noreply@github.com> * more configParser typings Signed-off-by: GitHub <noreply@github.com> * revert Signed-off-by: GitHub <noreply@github.com> * remove knub type params Signed-off-by: GitHub <noreply@github.com> * fix more MessageEmbed / MessageOptions Signed-off-by: GitHub <noreply@github.com> * dumb commit for @almeidx to see why this is stupid Signed-off-by: GitHub <noreply@github.com> * temp disable custom_events Signed-off-by: GitHub <noreply@github.com> * more minor typings fixes - 23 err left Signed-off-by: GitHub <noreply@github.com> * update djs dep * +debug build method (revert this) Signed-off-by: GitHub <noreply@github.com> * Revert "+debug build method (revert this)" This reverts commit a80af1e729b742d1aad1097df538d224fbd32ce7. * Redo +debug build (Revert this) Signed-off-by: GitHub <noreply@github.com> * uniform before/after Load shorthands Signed-off-by: GitHub <noreply@github.com> * remove unused imports & add prettier plugin Signed-off-by: GitHub <noreply@github.com> * env fixes for web platform hosting Signed-off-by: GitHub <noreply@github.com> * feat: knub v32-next; related fixes * fix: allow legacy keys in change_perms action * fix: request Message Content intent * fix: use Knub's config validation logic in API * fix(dashboard): fix error when there are no message and/or slash commands in a plugin * fix(automod): start_thread action thread options * fix(CustomEvents): message command types * chore: remove unneeded type annotation * feat: add forum channel icon; use thread icon for news threads * chore: make tslint happy * chore: fix formatting --------- Signed-off-by: GitHub <noreply@github.com> Co-authored-by: almeidx <almeidx@pm.me> Co-authored-by: Dragory <2606411+Dragory@users.noreply.github.com>
105 lines
3.6 KiB
TypeScript
105 lines
3.6 KiB
TypeScript
import { Snowflake } from "discord.js";
|
|
import { waitForReply } from "knub/helpers";
|
|
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
|
import { LogType } from "../../../data/LogType";
|
|
import { logger } from "../../../logger";
|
|
import { MutesPlugin } from "../../../plugins/Mutes/MutesPlugin";
|
|
import { canActOn, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
|
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
|
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
|
|
import { modActionsCmd } from "../types";
|
|
|
|
export const MassmuteCmd = modActionsCmd({
|
|
trigger: "massmute",
|
|
permission: "can_massmute",
|
|
description: "Mass-mute a list of user IDs",
|
|
|
|
signature: [
|
|
{
|
|
userIds: ct.string({ rest: true }),
|
|
},
|
|
],
|
|
|
|
async run({ pluginData, message: msg, args }) {
|
|
// Limit to 100 users at once (arbitrary?)
|
|
if (args.userIds.length > 100) {
|
|
sendErrorMessage(pluginData, msg.channel, `Can only massmute max 100 users at once`);
|
|
return;
|
|
}
|
|
|
|
// Ask for mute reason
|
|
msg.channel.send("Mute reason? `cancel` to cancel");
|
|
const muteReasonReceived = await waitForReply(pluginData.client, msg.channel, msg.author.id);
|
|
if (
|
|
!muteReasonReceived ||
|
|
!muteReasonReceived.content ||
|
|
muteReasonReceived.content.toLowerCase().trim() === "cancel"
|
|
) {
|
|
sendErrorMessage(pluginData, msg.channel, "Cancelled");
|
|
return;
|
|
}
|
|
|
|
const muteReason = formatReasonWithAttachments(muteReasonReceived.content, [...msg.attachments.values()]);
|
|
|
|
// Verify we can act upon all users
|
|
for (const userId of args.userIds) {
|
|
const member = pluginData.guild.members.cache.get(userId as Snowflake);
|
|
if (member && !canActOn(pluginData, msg.member, member)) {
|
|
sendErrorMessage(pluginData, msg.channel, "Cannot massmute one or more users: insufficient permissions");
|
|
return;
|
|
}
|
|
}
|
|
|
|
// Ignore automatic mute cases and logs for these users
|
|
// We'll create our own cases below and post a single "mass muted" log instead
|
|
args.userIds.forEach((userId) => {
|
|
// Use longer timeouts since this can take a while
|
|
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_MUTE, userId, 120 * 1000);
|
|
});
|
|
|
|
// Show loading indicator
|
|
const loadingMsg = await msg.channel.send("Muting...");
|
|
|
|
// Mute everyone and count fails
|
|
const modId = msg.author.id;
|
|
const failedMutes: string[] = [];
|
|
const mutesPlugin = pluginData.getPlugin(MutesPlugin);
|
|
for (const userId of args.userIds) {
|
|
try {
|
|
await mutesPlugin.muteUser(userId, 0, `Mass mute: ${muteReason}`, {
|
|
caseArgs: {
|
|
modId,
|
|
},
|
|
});
|
|
} catch (e) {
|
|
logger.info(e);
|
|
failedMutes.push(userId);
|
|
}
|
|
}
|
|
|
|
// Clear loading indicator
|
|
loadingMsg.delete();
|
|
|
|
const successfulMuteCount = args.userIds.length - failedMutes.length;
|
|
if (successfulMuteCount === 0) {
|
|
// All mutes failed
|
|
sendErrorMessage(pluginData, msg.channel, "All mutes failed. Make sure the IDs are valid.");
|
|
} else {
|
|
// Success on all or some mutes
|
|
pluginData.getPlugin(LogsPlugin).logMassMute({
|
|
mod: msg.author,
|
|
count: successfulMuteCount,
|
|
});
|
|
|
|
if (failedMutes.length) {
|
|
sendSuccessMessage(
|
|
pluginData,
|
|
msg.channel,
|
|
`Muted ${successfulMuteCount} users, ${failedMutes.length} failed: ${failedMutes.join(" ")}`,
|
|
);
|
|
} else {
|
|
sendSuccessMessage(pluginData, msg.channel, `Muted ${successfulMuteCount} users successfully`);
|
|
}
|
|
}
|
|
},
|
|
});
|