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

View file

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

View file

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