From 565aed44a9fe72fea06f92317906230ed5afa500 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20Bl=C3=B6meke?= Date: Sat, 13 Jul 2019 02:50:34 +0200 Subject: [PATCH] Using waitForReaction to ask if we shall go on or not instead of notify --- src/plugins/Cases.ts | 15 +++++++++++++ src/plugins/ModActions.ts | 44 ++++++++++++++++++++++----------------- 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/plugins/Cases.ts b/src/plugins/Cases.ts index 742477e8..69127ac1 100644 --- a/src/plugins/Cases.ts +++ b/src/plugins/Cases.ts @@ -266,4 +266,19 @@ export class CasesPlugin extends ZeppelinPlugin { return null; } } + + public async getCaseTypeAmountForUserId(userID: string, type: CaseTypes) { + 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; + } } diff --git a/src/plugins/ModActions.ts b/src/plugins/ModActions.ts index b50bd0d0..bd800001 100644 --- a/src/plugins/ModActions.ts +++ b/src/plugins/ModActions.ts @@ -51,6 +51,8 @@ interface IModActionsPluginConfig { ban_message: string; alert_on_rejoin: boolean; alert_channel: string; + warn_notify_threshold: number; + warn_threshold_message: string; can_note: boolean; can_warn: boolean; @@ -97,6 +99,8 @@ export class ModActionsPlugin extends ZeppelinPlugin { ban_message: "You have been banned from {guildName}. Reason given: {reason}", alert_on_rejoin: false, alert_channel: null, + warn_notify_threshold: 5, + warn_threshold_message: "The user already has {priorWarnings} warnings. Proceed anyways?", can_note: false, can_warn: false, @@ -256,9 +260,7 @@ export class ModActionsPlugin extends ZeppelinPlugin { if (actions.length) { const alertChannel: any = this.guild.channels.get(alertChannelId); 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)`, ); } } @@ -280,9 +282,7 @@ export class ModActionsPlugin extends ZeppelinPlugin { const existingCaseForThisEntry = await this.cases.findByAuditLogId(kickAuditLogEntry.id); if (existingCaseForThisEntry) { 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 { const casesPlugin = this.getPlugin("cases"); @@ -406,6 +406,21 @@ export class ModActionsPlugin extends ZeppelinPlugin { } const config = this.getConfig(); + + 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_threshold_message.replace("{priorWarnings}", `${priorWarnAmount}`), + ); + const reply = await waitForReaction(this.bot, tooManyWarningsMsg, ["✅", "❌"], msg.author.id); + tooManyWarningsMsg.delete(); + if (!reply || reply.name === "❌") { + return; + } + } + const reason = this.formatReasonWithAttachments(args.reason, msg.attachments); const warnMessage = config.warn_message.replace("{guildName}", this.guild.name).replace("{reason}", reason); @@ -424,7 +439,6 @@ export class ModActionsPlugin extends ZeppelinPlugin { } } - const casesPlugin = this.getPlugin("cases"); const createdCase = await casesPlugin.createCase({ userId: memberToWarn.id, modId: mod.id, @@ -438,9 +452,7 @@ export class ModActionsPlugin extends ZeppelinPlugin { msg.channel.createMessage( successMessage( - `Warned **${memberToWarn.user.username}#${memberToWarn.user.discriminator}** (Case #${ - createdCase.case_number - })${messageResultText}`, + `Warned **${memberToWarn.user.username}#${memberToWarn.user.discriminator}** (Case #${createdCase.case_number})${messageResultText}`, ), ); @@ -773,9 +785,7 @@ export class ModActionsPlugin extends ZeppelinPlugin { }); // Confirm the action to the moderator - let response = `Kicked **${memberToKick.user.username}#${memberToKick.user.discriminator}** (Case #${ - createdCase.case_number - })`; + let response = `Kicked **${memberToKick.user.username}#${memberToKick.user.discriminator}** (Case #${createdCase.case_number})`; if (userMessageResult.text) response += ` (${userMessageResult.text})`; msg.channel.createMessage(successMessage(response)); @@ -860,9 +870,7 @@ export class ModActionsPlugin extends ZeppelinPlugin { }); // Confirm the action to the moderator - let response = `Banned **${memberToBan.user.username}#${memberToBan.user.discriminator}** (Case #${ - createdCase.case_number - })`; + let response = `Banned **${memberToBan.user.username}#${memberToBan.user.discriminator}** (Case #${createdCase.case_number})`; if (userMessageResult.text) response += ` (${userMessageResult.text})`; msg.channel.createMessage(successMessage(response)); @@ -936,9 +944,7 @@ export class ModActionsPlugin extends ZeppelinPlugin { // Confirm the action to the moderator msg.channel.createMessage( successMessage( - `Softbanned **${memberToSoftban.user.username}#${memberToSoftban.user.discriminator}** (Case #${ - createdCase.case_number - })`, + `Softbanned **${memberToSoftban.user.username}#${memberToSoftban.user.discriminator}** (Case #${createdCase.case_number})`, ), );