Include durations in mute and unmute case notes, clarify bot responses when updating an active mute

This commit is contained in:
Dragory 2019-03-07 22:35:33 +02:00
parent 18f16f6bad
commit 374e79e2dc
3 changed files with 52 additions and 26 deletions

View file

@ -3,13 +3,12 @@ import { Attachment, Constants as ErisConstants, Guild, Member, Message, TextCha
import humanizeDuration from "humanize-duration";
import { GuildCases } from "../data/GuildCases";
import {
chunkMessageLines,
convertDelayStringToMS,
createChunkedMessage,
disableLinkPreviews,
errorMessage,
findRelevantAuditLogEntry,
formatTemplateString,
asSingleLine,
stripObjectToScalars,
successMessage,
trimLines,
@ -483,23 +482,22 @@ export class ModActionsPlugin extends ZeppelinPlugin<IModActionsPluginConfig, IM
let theCase;
if (hasOldCase) {
// Update old case
theCase = await this.cases.find(mute.case_id);
if (args.reason) {
// Update old case
await this.actions.fire("createCaseNote", {
caseId: mute.case_id,
modId: mod.id,
note: reason,
});
}
const caseNote = `__[Mute updated to ${muteTime ? timeUntilUnmute : "indefinite"}]__ ${reason}`.trim();
await this.actions.fire("createCaseNote", {
caseId: mute.case_id,
modId: mod.id,
note: caseNote,
});
} else {
// Create new case
const caseNote = `__[Muted ${muteTime ? `for ${timeUntilUnmute}` : "indefinitely"}]__ ${reason}`.trim();
theCase = await this.actions.fire("createCase", {
userId: args.member.id,
modId: mod.id,
type: CaseTypes.Mute,
reason,
reason: caseNote,
ppId: mod.id !== msg.author.id ? msg.author.id : null,
});
await this.mutes.setCaseId(args.member.id, theCase.id);
@ -529,13 +527,29 @@ export class ModActionsPlugin extends ZeppelinPlugin<IModActionsPluginConfig, IM
// Confirm the action to the moderator
let response;
if (muteTime) {
response = `Muted **${args.member.user.username}#${
args.member.user.discriminator
}** for ${timeUntilUnmute} (Case #${theCase.case_number})`;
if (hasOldCase) {
response = asSingleLine(`
Updated **${args.member.user.username}#${args.member.user.discriminator}**'s
mute to ${timeUntilUnmute} (Case #${theCase.case_number})
`);
} else {
response = asSingleLine(`
Muted **${args.member.user.username}#${args.member.user.discriminator}**
for ${timeUntilUnmute} (Case #${theCase.case_number})
`);
}
} else {
response = `Muted **${args.member.user.username}#${args.member.user.discriminator}** indefinitely (Case #${
theCase.case_number
})`;
if (hasOldCase) {
response = asSingleLine(`
Updated **${args.member.user.username}#${args.member.user.discriminator}**'s
mute to indefinite (Case #${theCase.case_number})
`);
} else {
response = asSingleLine(`
Muted **${args.member.user.username}#${args.member.user.discriminator}**
indefinitely (Case #${theCase.case_number})
`);
}
}
if (userMessageResult.text) response += ` (${userMessageResult.text})`;
@ -587,6 +601,7 @@ export class ModActionsPlugin extends ZeppelinPlugin<IModActionsPluginConfig, IM
// Convert unmute time from e.g. "2h30m" to milliseconds
const unmuteTime = args.time ? convertDelayStringToMS(args.time) : null;
const timeUntilUnmute = unmuteTime && humanizeDuration(unmuteTime);
if (unmuteTime == null && args.time) {
// Invalid unmuteTime -> assume it's actually part of the reason
@ -594,19 +609,19 @@ export class ModActionsPlugin extends ZeppelinPlugin<IModActionsPluginConfig, IM
}
const reason = this.formatReasonWithAttachments(args.reason, msg.attachments);
const caseNote = unmuteTime ? `__[Scheduled unmute in ${timeUntilUnmute}]__ ${reason}` : reason;
// Create a case
const createdCase = await this.actions.fire("createCase", {
userId: args.member.id,
modId: mod.id,
type: CaseTypes.Unmute,
reason,
reason: caseNote,
ppId: mod.id !== msg.author.id ? msg.author.id : null,
});
if (unmuteTime) {
// If we have an unmute time, just update the old mute to expire in that time
const timeUntilUnmute = unmuteTime && humanizeDuration(unmuteTime);
await this.actions.fire("unmute", { member: args.member, unmuteTime });
// Confirm the action to the moderator

View file

@ -1,5 +1,6 @@
import { decorators as d, IPluginOptions, Plugin } from "knub";
import { Channel, Member, User } from "eris";
import { decorators as d, IPluginOptions } from "knub";
import { Channel, Member } from "eris";
import humanizeDuration from "humanize-duration";
import {
getEmojiInString,
getRoleMentions,
@ -240,8 +241,10 @@ export class SpamPlugin extends ZeppelinPlugin<ISpamPluginConfig> {
const recentActions = this.getRecentActions(type, savedMessage.user_id, savedMessage.channel_id, since);
// Start by muting them, if enabled
let timeUntilUnmute;
if (spamConfig.mute && member) {
const muteTime = spamConfig.mute_time ? spamConfig.mute_time * 60 * 1000 : 120 * 1000;
timeUntilUnmute = humanizeDuration(muteTime);
this.logs.ignoreLog(LogType.MEMBER_ROLE_ADD, savedMessage.user_id);
this.actions.fire("mute", { member, muteTime, reason: "Automatic spam detection" });
}
@ -288,10 +291,14 @@ export class SpamPlugin extends ZeppelinPlugin<ISpamPluginConfig> {
// Create a case and log the actions taken above
const caseType = spamConfig.mute ? CaseTypes.Mute : CaseTypes.Note;
const caseText = trimLines(`
Automatic spam detection: ${description} (over ${spamConfig.count} in ${spamConfig.interval}s)
${archiveUrl}
`);
let caseText = trimLines(`
Automatic spam detection: ${description} (over ${spamConfig.count} in ${spamConfig.interval}s)
${archiveUrl}
`);
if (spamConfig.mute) {
caseText = `__[Muted for ${timeUntilUnmute}]__ ${caseText}`;
}
this.logs.log(LogType.MESSAGE_SPAM_DETECTED, {
member: stripObjectToScalars(member, ["user"]),

View file

@ -199,6 +199,10 @@ export function trimLines(str: string) {
.trim();
}
export function asSingleLine(str: string) {
return trimLines(str).replace(/\n/g, " ");
}
export const emptyEmbedValue = "\u200b";
export const embedPadding = "\n" + emptyEmbedValue;