Merge pull request #98 from DarkView/k30_massmute
Update Massmute to newest version... again
This commit is contained in:
commit
ca0fe50806
5 changed files with 112 additions and 0 deletions
|
@ -49,6 +49,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}",
|
||||||
|
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -32,6 +32,7 @@ import { warnMember } from "./functions/warnMember";
|
||||||
import { Member } from "eris";
|
import { Member } from "eris";
|
||||||
import { kickMember } from "./functions/kickMember";
|
import { kickMember } from "./functions/kickMember";
|
||||||
import { banUserId } from "./functions/banUserId";
|
import { banUserId } from "./functions/banUserId";
|
||||||
|
import { MassmuteCmd } from "./commands/MassmuteCmd";
|
||||||
import { trimPluginDescription } from "../../utils";
|
import { trimPluginDescription } from "../../utils";
|
||||||
|
|
||||||
const defaultOptions = {
|
const defaultOptions = {
|
||||||
|
@ -62,6 +63,7 @@ const defaultOptions = {
|
||||||
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,
|
||||||
},
|
},
|
||||||
|
@ -82,6 +84,7 @@ const defaultOptions = {
|
||||||
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,
|
||||||
},
|
},
|
||||||
|
@ -124,6 +127,7 @@ export const ModActionsPlugin = zeppelinPlugin<ModActionsPluginType>()("mod_acti
|
||||||
UnbanCmd,
|
UnbanCmd,
|
||||||
ForcebanCmd,
|
ForcebanCmd,
|
||||||
MassbanCmd,
|
MassbanCmd,
|
||||||
|
MassmuteCmd,
|
||||||
AddCaseCmd,
|
AddCaseCmd,
|
||||||
CaseCmd,
|
CaseCmd,
|
||||||
CasesUserCmd,
|
CasesUserCmd,
|
||||||
|
|
105
backend/src/plugins/ModActions/commands/MassmuteCmd.ts
Normal file
105
backend/src/plugins/ModActions/commands/MassmuteCmd.ts
Normal 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`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
|
@ -33,6 +33,7 @@ export 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,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue