From e841f20ab09bf357075e7f58f06d2e709eac2e5a Mon Sep 17 00:00:00 2001 From: Dragory Date: Fri, 8 Feb 2019 20:25:35 +0200 Subject: [PATCH] Add special mention if a mod action was performed on behalf of another mod with the --mmod option --- src/data/entities/Case.ts | 4 +++ .../1549649586803-AddPPFieldsToCases.ts | 19 +++++++++++++ src/plugins/Cases.ts | 20 +++++++++++--- src/plugins/ModActions.ts | 27 ++++++++++++------- 4 files changed, 58 insertions(+), 12 deletions(-) create mode 100644 src/migrations/1549649586803-AddPPFieldsToCases.ts diff --git a/src/data/entities/Case.ts b/src/data/entities/Case.ts index fd9dd4db..88a920e3 100644 --- a/src/data/entities/Case.ts +++ b/src/data/entities/Case.ts @@ -25,6 +25,10 @@ export class Case { @Column() is_hidden: boolean; + @Column() pp_id: string; + + @Column() pp_name: string; + @OneToMany(type => CaseNote, note => note.case) notes: CaseNote[]; } diff --git a/src/migrations/1549649586803-AddPPFieldsToCases.ts b/src/migrations/1549649586803-AddPPFieldsToCases.ts new file mode 100644 index 00000000..d7f873cb --- /dev/null +++ b/src/migrations/1549649586803-AddPPFieldsToCases.ts @@ -0,0 +1,19 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddPPFieldsToCases1549649586803 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(` + ALTER TABLE \`cases\` + ADD COLUMN \`pp_id\` BIGINT NULL, + ADD COLUMN \`pp_name\` VARCHAR(128) NULL + `); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(` + ALTER TABLE \`cases\` + DROP COLUMN \`pp_id\`, + DROP COLUMN \`pp_name\` + `); + } +} diff --git a/src/plugins/Cases.ts b/src/plugins/Cases.ts index 2a484f8d..07ec44f3 100644 --- a/src/plugins/Cases.ts +++ b/src/plugins/Cases.ts @@ -37,7 +37,8 @@ export class CasesPlugin extends ZeppelinPlugin { args.auditLogId, args.reason, args.automatic, - args.postInCaseLog + args.postInCaseLog, + args.ppId ); }); @@ -72,7 +73,8 @@ export class CasesPlugin extends ZeppelinPlugin { auditLogId: string = null, reason: string = null, automatic = false, - postInCaseLogOverride = null + postInCaseLogOverride = null, + ppId = null ): Promise { const user = this.bot.users.get(userId); const userName = user ? `${user.username}#${user.discriminator}` : "Unknown#0000"; @@ -80,13 +82,21 @@ export class CasesPlugin extends ZeppelinPlugin { const mod = this.bot.users.get(modId); const modName = mod ? `${mod.username}#${mod.discriminator}` : "Unknown#0000"; + let ppName = null; + if (ppId) { + const pp = this.bot.users.get(ppId); + ppName = pp ? `${pp.username}#${pp.discriminator}` : "Unknown#0000"; + } + const createdCase = await this.cases.create({ type, user_id: userId, user_name: userName, mod_id: modId, mod_name: modName, - audit_log_id: auditLogId + audit_log_id: auditLogId, + pp_id: ppId, + pp_name: ppName }); if (reason) { @@ -180,6 +190,10 @@ export class CasesPlugin extends ZeppelinPlugin { ] }; + if (theCase.pp_id) { + embed.fields[1].value += `\np.p. ${theCase.pp_name}\n<@!${theCase.pp_id}>`; + } + if (theCase.is_hidden) { embed.title += " (hidden)"; } diff --git a/src/plugins/ModActions.ts b/src/plugins/ModActions.ts index c1fa3b24..665de608 100644 --- a/src/plugins/ModActions.ts +++ b/src/plugins/ModActions.ts @@ -339,7 +339,8 @@ export class ModActionsPlugin extends ZeppelinPlugin { userId: args.member.id, modId: mod.id, type: CaseTypes.Warn, - reason: args.reason + reason: args.reason, + ppId: mod.id !== msg.author.id ? msg.author.id : null }); msg.channel.createMessage( @@ -419,7 +420,8 @@ export class ModActionsPlugin extends ZeppelinPlugin { userId: args.member.id, modId: mod.id, type: CaseTypes.Mute, - reason: args.reason + reason: args.reason, + ppId: mod.id !== msg.author.id ? msg.author.id : null }); await this.mutes.setCaseId(args.member.id, theCase.id); } @@ -515,7 +517,8 @@ export class ModActionsPlugin extends ZeppelinPlugin { userId: args.member.id, modId: mod.id, type: CaseTypes.Unmute, - reason: args.reason + reason: args.reason, + ppId: mod.id !== msg.author.id ? msg.author.id : null }); if (unmuteTime) { @@ -615,7 +618,8 @@ export class ModActionsPlugin extends ZeppelinPlugin { userId: args.member.id, modId: mod.id, type: CaseTypes.Kick, - reason: args.reason + reason: args.reason, + ppId: mod.id !== msg.author.id ? msg.author.id : null }); // Confirm the action to the moderator @@ -680,7 +684,8 @@ export class ModActionsPlugin extends ZeppelinPlugin { userId: args.member.id, modId: mod.id, type: CaseTypes.Ban, - reason: args.reason + reason: args.reason, + ppId: mod.id !== msg.author.id ? msg.author.id : null }); // Confirm the action to the moderator @@ -733,7 +738,8 @@ export class ModActionsPlugin extends ZeppelinPlugin { userId: args.member.id, modId: mod.id, type: CaseTypes.Softban, - reason: args.reason + reason: args.reason, + ppId: mod.id !== msg.author.id ? msg.author.id : null }); // Confirm the action to the moderator @@ -783,7 +789,8 @@ export class ModActionsPlugin extends ZeppelinPlugin { userId: args.userId, modId: mod.id, type: CaseTypes.Unban, - reason: args.reason + reason: args.reason, + ppId: mod.id !== msg.author.id ? msg.author.id : null }); // Confirm the action @@ -834,7 +841,8 @@ export class ModActionsPlugin extends ZeppelinPlugin { userId: args.userId, modId: mod.id, type: CaseTypes.Ban, - reason: args.reason + reason: args.reason, + ppId: mod.id !== msg.author.id ? msg.author.id : null }); // Confirm the action @@ -970,7 +978,8 @@ export class ModActionsPlugin extends ZeppelinPlugin { userId: args.target, modId: mod.id, type: CaseTypes[type], - reason: args.reason + reason: args.reason, + ppId: mod.id !== msg.author.id ? msg.author.id : null }); msg.channel.createMessage(successMessage(`Case #${theCase.case_number} created`));