Add safety net for attempts to create a duplicate case for a single kick audit log entry
This commit is contained in:
parent
dd7ae1d4b8
commit
c34532e348
2 changed files with 27 additions and 8 deletions
|
@ -77,6 +77,16 @@ export class GuildCases extends BaseRepository {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async findByAuditLogId(auditLogId: string): Promise<Case> {
|
||||||
|
return this.cases.findOne({
|
||||||
|
relations: this.getRelations(),
|
||||||
|
where: {
|
||||||
|
guild_id: this.guildId,
|
||||||
|
audit_log_id: auditLogId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async getByUserId(userId: string): Promise<Case[]> {
|
async getByUserId(userId: string): Promise<Case[]> {
|
||||||
return this.cases.find({
|
return this.cases.find({
|
||||||
relations: this.getRelations(),
|
relations: this.getRelations(),
|
||||||
|
|
|
@ -267,6 +267,14 @@ export class ModActionsPlugin extends ZeppelinPlugin<IModActionsPluginConfig> {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (kickAuditLogEntry) {
|
if (kickAuditLogEntry) {
|
||||||
|
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", {
|
this.actions.fire("createCase", {
|
||||||
userId: member.id,
|
userId: member.id,
|
||||||
modId: kickAuditLogEntry.user.id,
|
modId: kickAuditLogEntry.user.id,
|
||||||
|
@ -275,6 +283,7 @@ export class ModActionsPlugin extends ZeppelinPlugin<IModActionsPluginConfig> {
|
||||||
reason: kickAuditLogEntry.reason,
|
reason: kickAuditLogEntry.reason,
|
||||||
automatic: true,
|
automatic: true,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this.serverLogs.log(LogType.MEMBER_KICK, {
|
this.serverLogs.log(LogType.MEMBER_KICK, {
|
||||||
user: stripObjectToScalars(member.user),
|
user: stripObjectToScalars(member.user),
|
||||||
|
|
Loading…
Add table
Reference in a new issue