From ca44746ae6fd1f722402ff40cfe6b2ba8604d30e Mon Sep 17 00:00:00 2001 From: Dragory Date: Thu, 3 Jan 2019 04:30:16 +0200 Subject: [PATCH] cases: fix cases without a reason not being posted The fact that cases *with* a reason were being posted was actually an unintended side effect of createCaseNote also posting the case after creating the note. Had the issue with the cases not being posted not existed, new cases with a reason would've been posted twice. This commit changes this so createCaseNote doesn't post the case when used from createCase, and fixes the actual case posting at the end of createCase. --- src/plugins/Cases.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/plugins/Cases.ts b/src/plugins/Cases.ts index 33715422..cf18684c 100644 --- a/src/plugins/Cases.ts +++ b/src/plugins/Cases.ts @@ -52,8 +52,8 @@ export class CasesPlugin extends ZeppelinPlugin { this.actions.unregister("postCase"); } - protected async resolveCase(caseOrCaseId: Case | number): Promise { - return caseOrCaseId instanceof Case ? caseOrCaseId : this.cases.with("notes").find(caseOrCaseId); + protected resolveCaseId(caseOrCaseId: Case | number): number { + return caseOrCaseId instanceof Case ? caseOrCaseId.id : caseOrCaseId; } /** @@ -85,7 +85,7 @@ export class CasesPlugin extends ZeppelinPlugin { }); if (reason) { - await this.createCaseNote(createdCase, modId, reason); + await this.createCaseNote(createdCase, modId, reason, automatic, false); } if ( @@ -114,7 +114,7 @@ export class CasesPlugin extends ZeppelinPlugin { const mod = this.bot.users.get(modId); const modName = mod ? `${mod.username}#${mod.discriminator}` : "Unknown#0000"; - const theCase = await this.resolveCase(caseOrCaseId); + const theCase = await this.cases.find(this.resolveCaseId(caseOrCaseId)); if (!theCase) { this.throwPluginRuntimeError(`Unknown case ID: ${caseOrCaseId}`); } @@ -144,7 +144,7 @@ export class CasesPlugin extends ZeppelinPlugin { * Returns a Discord embed for the specified case */ public async getCaseEmbed(caseOrCaseId: Case | number): Promise { - const theCase = await this.resolveCase(caseOrCaseId); + const theCase = await this.cases.with("notes").find(this.resolveCaseId(caseOrCaseId)); if (!theCase) return null; const createdAt = moment(theCase.created_at);