Merge pull request #36 from DarkView/updatedWarnThreshold

Updated Warn Threshold to work with latest release
This commit is contained in:
Miikka 2020-04-03 16:22:45 +03:00 committed by GitHub
commit aba270ffbb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 0 deletions

View file

@ -245,6 +245,21 @@ export class CasesPlugin extends ZeppelinPlugin<TConfigSchema> {
return { embed };
}
public async getCaseTypeAmountForUserId(userID: string, type: CaseTypes): Promise<number> {
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.

View file

@ -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<TConfigSchema> {
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<TConfigSchema> {
const config = this.getConfig();
const reason = this.formatReasonWithAttachments(args.reason, msg.attachments);
const casesPlugin = this.getPlugin<CasesPlugin>("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);