diff --git a/backend/src/plugins/Cases.ts b/backend/src/plugins/Cases.ts index b8fa1448..44c17402 100644 --- a/backend/src/plugins/Cases.ts +++ b/backend/src/plugins/Cases.ts @@ -245,6 +245,21 @@ export class CasesPlugin extends ZeppelinPlugin { return { embed }; } + public async getCaseTypeAmountForUserId(userID: string, type: CaseTypes): Promise { + const cases = (await this.cases.getByUserId(userID)).filter(c => !c.is_hidden); + let typeAmount = 0; + + if (cases.length > 0) { + cases.forEach(singleCase => { + if (singleCase.type === type.valueOf()) { + typeAmount++; + } + }); + } + + return typeAmount; + } + /** * A helper for posting to the case log channel. * Returns silently if the case log channel isn't specified or is invalid. diff --git a/backend/src/plugins/ModActions.ts b/backend/src/plugins/ModActions.ts index ef26c937..09a50784 100644 --- a/backend/src/plugins/ModActions.ts +++ b/backend/src/plugins/ModActions.ts @@ -46,6 +46,8 @@ const ConfigSchema = t.type({ ban_message: tNullable(t.string), alert_on_rejoin: t.boolean, alert_channel: tNullable(t.string), + warn_notify_threshold: t.number, + warn_notify_message: t.string, can_note: t.boolean, can_warn: t.boolean, can_mute: t.boolean, @@ -162,6 +164,9 @@ export class ModActionsPlugin extends ZeppelinPlugin { ban_message: "You have been banned from the {guildName} server. Reason given: {reason}", alert_on_rejoin: false, alert_channel: null, + warn_notify_threshold: 5, + warn_notify_message: + "The user already has **{priorWarnings}** warnings!\n Please check their prior cases and assess whether or not to warn anyways.\n Proceed with the warning?", can_note: false, can_warn: false, @@ -671,6 +676,21 @@ export class ModActionsPlugin extends ZeppelinPlugin { const config = this.getConfig(); const reason = this.formatReasonWithAttachments(args.reason, msg.attachments); + const casesPlugin = this.getPlugin("cases"); + const priorWarnAmount = await casesPlugin.getCaseTypeAmountForUserId(memberToWarn.id, CaseTypes.Warn); + if (priorWarnAmount >= config.warn_notify_threshold) { + const tooManyWarningsMsg = await msg.channel.createMessage( + config.warn_notify_message.replace("{priorWarnings}", `${priorWarnAmount}`), + ); + + const reply = await waitForReaction(this.bot, tooManyWarningsMsg, ["✅", "❌"]); + tooManyWarningsMsg.delete(); + if (!reply || reply.name === "❌") { + msg.channel.createMessage(errorMessage("Warn cancelled by moderator")); + return; + } + } + let contactMethods; try { contactMethods = this.readContactMethodsFromArgs(args);