3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

Merge pull request #98 from DarkView/k30_massmute

Update Massmute to newest version... again
This commit is contained in:
Miikka 2020-08-05 02:40:36 +03:00 committed by GitHub
commit ca0fe50806
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 112 additions and 0 deletions

View file

@ -0,0 +1,105 @@
import { modActionsCommand } from "../types";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { canActOn, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { stripObjectToScalars } from "../../../utils";
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
import { TextChannel } from "eris";
import { waitForReply } from "knub/dist/helpers";
import { LogType } from "src/data/LogType";
import { logger } from "src/logger";
import { MutesPlugin } from "src/plugins/Mutes/MutesPlugin";
export const MassmuteCmd = modActionsCommand({
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.createMessage("Mute reason? `cancel` to cancel");
const muteReasonReceived = await waitForReply(pluginData.client, msg.channel as TextChannel, 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);
// Verify we can act upon all users
for (const userId of args.userIds) {
const member = pluginData.guild.members.get(userId);
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.createMessage("Muting...");
// Mute everyone and count fails
const modId = msg.author.id;
const failedMutes = [];
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.state.serverLogs.log(LogType.MASSMUTE, {
mod: stripObjectToScalars(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`);
}
}
},
});