diff --git a/src/data/GuildCases.ts b/src/data/GuildCases.ts index b4ed2a7d..a49f72bc 100644 --- a/src/data/GuildCases.ts +++ b/src/data/GuildCases.ts @@ -77,6 +77,16 @@ export class GuildCases extends BaseRepository { }); } + async findByAuditLogId(auditLogId: string): Promise { + return this.cases.findOne({ + relations: this.getRelations(), + where: { + guild_id: this.guildId, + audit_log_id: auditLogId, + }, + }); + } + async getByUserId(userId: string): Promise { return this.cases.find({ relations: this.getRelations(), diff --git a/src/plugins/ModActions.ts b/src/plugins/ModActions.ts index de6108b2..a45503ea 100644 --- a/src/plugins/ModActions.ts +++ b/src/plugins/ModActions.ts @@ -267,14 +267,23 @@ export class ModActionsPlugin extends ZeppelinPlugin { ); if (kickAuditLogEntry) { - this.actions.fire("createCase", { - userId: member.id, - modId: kickAuditLogEntry.user.id, - type: CaseTypes.Kick, - auditLogId: kickAuditLogEntry.id, - reason: kickAuditLogEntry.reason, - automatic: true, - }); + 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 + }`, + ); + } else { + this.actions.fire("createCase", { + userId: member.id, + modId: kickAuditLogEntry.user.id, + type: CaseTypes.Kick, + auditLogId: kickAuditLogEntry.id, + reason: kickAuditLogEntry.reason, + automatic: true, + }); + } this.serverLogs.log(LogType.MEMBER_KICK, { user: stripObjectToScalars(member.user),