Updated Warn Threshold to work with latest release
This commit is contained in:
parent
77e5f429c5
commit
0ee942728c
2 changed files with 54 additions and 10 deletions
|
@ -244,6 +244,21 @@ export class CasesPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
return { embed };
|
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.
|
* A helper for posting to the case log channel.
|
||||||
* Returns silently if the case log channel isn't specified or is invalid.
|
* Returns silently if the case log channel isn't specified or is invalid.
|
||||||
|
|
|
@ -46,6 +46,8 @@ const ConfigSchema = t.type({
|
||||||
ban_message: tNullable(t.string),
|
ban_message: tNullable(t.string),
|
||||||
alert_on_rejoin: t.boolean,
|
alert_on_rejoin: t.boolean,
|
||||||
alert_channel: tNullable(t.string),
|
alert_channel: tNullable(t.string),
|
||||||
|
warn_notify_threshold: t.number,
|
||||||
|
warn_notify_message: t.string,
|
||||||
can_note: t.boolean,
|
can_note: t.boolean,
|
||||||
can_warn: t.boolean,
|
can_warn: t.boolean,
|
||||||
can_mute: t.boolean,
|
can_mute: t.boolean,
|
||||||
|
@ -146,6 +148,9 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
ban_message: "You have been banned from the {guildName} server. Reason given: {reason}",
|
ban_message: "You have been banned from the {guildName} server. Reason given: {reason}",
|
||||||
alert_on_rejoin: false,
|
alert_on_rejoin: false,
|
||||||
alert_channel: null,
|
alert_channel: null,
|
||||||
|
warn_notify_threshold: 1,
|
||||||
|
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_note: false,
|
||||||
can_warn: false,
|
can_warn: false,
|
||||||
|
@ -197,10 +202,7 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
}
|
}
|
||||||
|
|
||||||
clearIgnoredEvent(type: IgnoredEventType, userId: any) {
|
clearIgnoredEvent(type: IgnoredEventType, userId: any) {
|
||||||
this.ignoredEvents.splice(
|
this.ignoredEvents.splice(this.ignoredEvents.findIndex(info => type === info.type && userId === info.userId), 1);
|
||||||
this.ignoredEvents.findIndex(info => type === info.type && userId === info.userId),
|
|
||||||
1,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
formatReasonWithAttachments(reason: string, attachments: Attachment[]) {
|
formatReasonWithAttachments(reason: string, attachments: Attachment[]) {
|
||||||
|
@ -328,7 +330,9 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
if (actions.length) {
|
if (actions.length) {
|
||||||
const alertChannel: any = this.guild.channels.get(alertChannelId);
|
const alertChannel: any = this.guild.channels.get(alertChannelId);
|
||||||
alertChannel.send(
|
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)`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -349,7 +353,9 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
const existingCaseForThisEntry = await this.cases.findByAuditLogId(kickAuditLogEntry.id);
|
const existingCaseForThisEntry = await this.cases.findByAuditLogId(kickAuditLogEntry.id);
|
||||||
if (existingCaseForThisEntry) {
|
if (existingCaseForThisEntry) {
|
||||||
logger.warn(
|
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 {
|
} else {
|
||||||
const casesPlugin = this.getPlugin<CasesPlugin>("cases");
|
const casesPlugin = this.getPlugin<CasesPlugin>("cases");
|
||||||
|
@ -605,6 +611,21 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
const config = this.getConfig();
|
const config = this.getConfig();
|
||||||
const reason = this.formatReasonWithAttachments(args.reason, msg.attachments);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const warnMessage = config.warn_message.replace("{guildName}", this.guild.name).replace("{reason}", reason);
|
const warnMessage = config.warn_message.replace("{guildName}", this.guild.name).replace("{reason}", reason);
|
||||||
const warnResult = await this.warnMember(
|
const warnResult = await this.warnMember(
|
||||||
memberToWarn,
|
memberToWarn,
|
||||||
|
@ -626,7 +647,9 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
|
|
||||||
this.sendSuccessMessage(
|
this.sendSuccessMessage(
|
||||||
msg.channel,
|
msg.channel,
|
||||||
`Warned **${memberToWarn.user.username}#${memberToWarn.user.discriminator}** (Case #${warnResult.case.case_number})${messageResultText}`,
|
`Warned **${memberToWarn.user.username}#${memberToWarn.user.discriminator}** (Case #${
|
||||||
|
warnResult.case.case_number
|
||||||
|
})${messageResultText}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1013,7 +1036,9 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Confirm the action to the moderator
|
// Confirm the action to the moderator
|
||||||
let response = `Kicked **${memberToKick.user.username}#${memberToKick.user.discriminator}** (Case #${kickResult.case.case_number})`;
|
let response = `Kicked **${memberToKick.user.username}#${memberToKick.user.discriminator}** (Case #${
|
||||||
|
kickResult.case.case_number
|
||||||
|
})`;
|
||||||
|
|
||||||
if (kickResult.notifyResult.text) response += ` (${kickResult.notifyResult.text})`;
|
if (kickResult.notifyResult.text) response += ` (${kickResult.notifyResult.text})`;
|
||||||
this.sendSuccessMessage(msg.channel, response);
|
this.sendSuccessMessage(msg.channel, response);
|
||||||
|
@ -1074,7 +1099,9 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Confirm the action to the moderator
|
// Confirm the action to the moderator
|
||||||
let response = `Banned **${memberToBan.user.username}#${memberToBan.user.discriminator}** (Case #${banResult.case.case_number})`;
|
let response = `Banned **${memberToBan.user.username}#${memberToBan.user.discriminator}** (Case #${
|
||||||
|
banResult.case.case_number
|
||||||
|
})`;
|
||||||
|
|
||||||
if (banResult.notifyResult.text) response += ` (${banResult.notifyResult.text})`;
|
if (banResult.notifyResult.text) response += ` (${banResult.notifyResult.text})`;
|
||||||
this.sendSuccessMessage(msg.channel, response);
|
this.sendSuccessMessage(msg.channel, response);
|
||||||
|
@ -1159,7 +1186,9 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
// Confirm the action to the moderator
|
// Confirm the action to the moderator
|
||||||
this.sendSuccessMessage(
|
this.sendSuccessMessage(
|
||||||
msg.channel,
|
msg.channel,
|
||||||
`Softbanned **${memberToSoftban.user.username}#${memberToSoftban.user.discriminator}** (Case #${createdCase.case_number})`,
|
`Softbanned **${memberToSoftban.user.username}#${memberToSoftban.user.discriminator}** (Case #${
|
||||||
|
createdCase.case_number
|
||||||
|
})`,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Log the action
|
// Log the action
|
||||||
|
|
Loading…
Add table
Reference in a new issue