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

Updated Massmute to work with latest release

Tested and Working
This commit is contained in:
Nils Blömeke 2020-01-28 22:31:37 +01:00 committed by Dark
parent 77e5f429c5
commit 6a4d356e97
4 changed files with 120 additions and 15 deletions

View file

@ -48,6 +48,7 @@
"CASE_CREATE": "✏ {userMention(mod)} manually created new **{caseType}** case (#{caseNum})", "CASE_CREATE": "✏ {userMention(mod)} manually created new **{caseType}** case (#{caseNum})",
"MASSBAN": "⚒ {userMention(mod)} massbanned {count} users", "MASSBAN": "⚒ {userMention(mod)} massbanned {count} users",
"MASSMUTE": "📢🚫 {userMention(mod)} massmuted {count} users",
"MEMBER_JOIN_WITH_PRIOR_RECORDS": "⚠ {userMention(member)} joined with prior records. Recent cases:\n{recentCaseSummary}", "MEMBER_JOIN_WITH_PRIOR_RECORDS": "⚠ {userMention(member)} joined with prior records. Recent cases:\n{recentCaseSummary}",

View file

@ -40,6 +40,7 @@ export enum LogType {
CASE_CREATE, CASE_CREATE,
MASSBAN, MASSBAN,
MASSMUTE,
MEMBER_TIMED_MUTE, MEMBER_TIMED_MUTE,
MEMBER_TIMED_UNMUTE, MEMBER_TIMED_UNMUTE,

View file

@ -54,6 +54,7 @@ const ConfigSchema = t.type({
can_view: t.boolean, can_view: t.boolean,
can_addcase: t.boolean, can_addcase: t.boolean,
can_massban: t.boolean, can_massban: t.boolean,
can_massmute: t.boolean,
can_hidecase: t.boolean, can_hidecase: t.boolean,
can_act_as_other: t.boolean, can_act_as_other: t.boolean,
}); });
@ -155,6 +156,7 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
can_view: false, can_view: false,
can_addcase: false, can_addcase: false,
can_massban: false, can_massban: false,
can_massmute: false,
can_hidecase: false, can_hidecase: false,
can_act_as_other: false, can_act_as_other: false,
}, },
@ -175,6 +177,7 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
level: ">=100", level: ">=100",
config: { config: {
can_massban: true, can_massban: true,
can_massmute: true,
can_hidecase: true, can_hidecase: true,
can_act_as_other: true, can_act_as_other: true,
}, },
@ -197,10 +200,7 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
} }
clearIgnoredEvent(type: IgnoredEventType, userId: any) { clearIgnoredEvent(type: IgnoredEventType, userId: any) {
this.ignoredEvents.splice( this.ignoredEvents.splice(this.ignoredEvents.findIndex(info => type === info.type && userId === info.userId), 1);
this.ignoredEvents.findIndex(info => type === info.type && userId === info.userId),
1,
);
} }
formatReasonWithAttachments(reason: string, attachments: Attachment[]) { formatReasonWithAttachments(reason: string, attachments: Attachment[]) {
@ -328,7 +328,9 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
if (actions.length) { if (actions.length) {
const alertChannel: any = this.guild.channels.get(alertChannelId); const alertChannel: any = this.guild.channels.get(alertChannelId);
alertChannel.send( alertChannel.send(
`<@!${member.id}> (${member.user.username}#${member.user.discriminator} \`${member.id}\`) joined with ${actions.length} prior record(s)`, `<@!${member.id}> (${member.user.username}#${member.user.discriminator} \`${member.id}\`) joined with ${
actions.length
} prior record(s)`,
); );
} }
} }
@ -349,7 +351,9 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
const existingCaseForThisEntry = await this.cases.findByAuditLogId(kickAuditLogEntry.id); const existingCaseForThisEntry = await this.cases.findByAuditLogId(kickAuditLogEntry.id);
if (existingCaseForThisEntry) { if (existingCaseForThisEntry) {
logger.warn( logger.warn(
`Tried to create duplicate case for audit log entry ${kickAuditLogEntry.id}, existing case id ${existingCaseForThisEntry.id}`, `Tried to create duplicate case for audit log entry ${kickAuditLogEntry.id}, existing case id ${
existingCaseForThisEntry.id
}`,
); );
} else { } else {
const casesPlugin = this.getPlugin<CasesPlugin>("cases"); const casesPlugin = this.getPlugin<CasesPlugin>("cases");
@ -626,7 +630,9 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
this.sendSuccessMessage( this.sendSuccessMessage(
msg.channel, msg.channel,
`Warned **${memberToWarn.user.username}#${memberToWarn.user.discriminator}** (Case #${warnResult.case.case_number})${messageResultText}`, `Warned **${memberToWarn.user.username}#${memberToWarn.user.discriminator}** (Case #${
warnResult.case.case_number
})${messageResultText}`,
); );
} }
@ -1013,7 +1019,9 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
} }
// Confirm the action to the moderator // Confirm the action to the moderator
let response = `Kicked **${memberToKick.user.username}#${memberToKick.user.discriminator}** (Case #${kickResult.case.case_number})`; let response = `Kicked **${memberToKick.user.username}#${memberToKick.user.discriminator}** (Case #${
kickResult.case.case_number
})`;
if (kickResult.notifyResult.text) response += ` (${kickResult.notifyResult.text})`; if (kickResult.notifyResult.text) response += ` (${kickResult.notifyResult.text})`;
this.sendSuccessMessage(msg.channel, response); this.sendSuccessMessage(msg.channel, response);
@ -1074,7 +1082,9 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
} }
// Confirm the action to the moderator // Confirm the action to the moderator
let response = `Banned **${memberToBan.user.username}#${memberToBan.user.discriminator}** (Case #${banResult.case.case_number})`; let response = `Banned **${memberToBan.user.username}#${memberToBan.user.discriminator}** (Case #${
banResult.case.case_number
})`;
if (banResult.notifyResult.text) response += ` (${banResult.notifyResult.text})`; if (banResult.notifyResult.text) response += ` (${banResult.notifyResult.text})`;
this.sendSuccessMessage(msg.channel, response); this.sendSuccessMessage(msg.channel, response);
@ -1159,7 +1169,9 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
// Confirm the action to the moderator // Confirm the action to the moderator
this.sendSuccessMessage( this.sendSuccessMessage(
msg.channel, msg.channel,
`Softbanned **${memberToSoftban.user.username}#${memberToSoftban.user.discriminator}** (Case #${createdCase.case_number})`, `Softbanned **${memberToSoftban.user.username}#${memberToSoftban.user.discriminator}** (Case #${
createdCase.case_number
})`,
); );
// Log the action // Log the action
@ -1384,6 +1396,93 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
} }
} }
@d.command("massmute", "<userIds:string...>", {
extra: {
info: {
description: "Mass-mute a list of user IDs",
},
},
})
@d.permission("can_massmute")
async massmuteCmd(msg: Message, args: { userIds: string[] }) {
// Limit to 100 users at once (arbitrary?)
if (args.userIds.length > 100) {
this.sendErrorMessage(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(this.bot, msg.channel as TextChannel, msg.author.id);
if (
!muteReasonReceived ||
!muteReasonReceived.content ||
muteReasonReceived.content.toLowerCase().trim() === "cancel"
) {
this.sendErrorMessage(msg.channel, "Cancelled");
return;
}
const muteReason = this.formatReasonWithAttachments(muteReasonReceived.content, msg.attachments);
// Verify we can act upon all users
for (const userId of args.userIds) {
const member = this.guild.members.get(userId);
if (member && !this.canActOn(msg.member, member)) {
this.sendErrorMessage(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
this.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 = this.getPlugin<MutesPlugin>("mutes");
for (const userId of args.userIds) {
try {
await mutesPlugin.muteUser(userId, 0, `Mass mute: ${muteReason}`, {
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
this.sendErrorMessage(msg.channel, "All mutes failed. Make sure the IDs are valid.");
} else {
// Success on all or some mutes
this.serverLogs.log(LogType.MASSMUTE, {
mod: stripObjectToScalars(msg.author),
count: successfulMuteCount,
});
if (failedMutes.length) {
msg.channel.createMessage(
successMessage(`Muted ${successfulMuteCount} users, ${failedMutes.length} failed: ${failedMutes.join(" ")}`),
);
} else {
msg.channel.createMessage(successMessage(`Muted ${successfulMuteCount} users successfully`));
}
}
}
@d.command("addcase", "<type:string> <user:string> [reason:string$]", { @d.command("addcase", "<type:string> <user:string> [reason:string$]", {
options: [{ name: "mod", type: "member" }], options: [{ name: "mod", type: "member" }],
extra: { extra: {

View file

@ -256,11 +256,13 @@ export class MutesPlugin extends ZeppelinPlugin<TConfigSchema> {
time: timeUntilUnmute, time: timeUntilUnmute,
}); });
} else { } else {
if (!this.serverLogs.isLogIgnored(LogType.MEMBER_MUTE, user.id)) {
this.serverLogs.log(LogType.MEMBER_MUTE, { this.serverLogs.log(LogType.MEMBER_MUTE, {
mod: stripObjectToScalars(mod), mod: stripObjectToScalars(mod),
user: stripObjectToScalars(user), user: stripObjectToScalars(user),
}); });
} }
}
return { return {
case: theCase, case: theCase,
@ -476,7 +478,9 @@ export class MutesPlugin extends ZeppelinPlugin<TConfigSchema> {
lines.push( lines.push(
...manuallyMutedMembers.map(member => { ...manuallyMutedMembers.map(member => {
return `<@!${member.id}> (**${member.user.username}#${member.user.discriminator}**, \`${member.id}\`) 🔧 Manual mute`; return `<@!${member.id}> (**${member.user.username}#${member.user.discriminator}**, \`${
member.id
}\`) 🔧 Manual mute`;
}), }),
); );
} }