From ffafc765d830d8beb3314a3b3995d35cee1e3ce9 Mon Sep 17 00:00:00 2001 From: Dragory Date: Sat, 23 Feb 2019 22:40:43 +0200 Subject: [PATCH] ModActions: !cases without id now returns 5 most recent cases created by you, or the mod specified with --mod --- src/data/GuildCases.ts | 3 ++- src/plugins/ModActions.ts | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/data/GuildCases.ts b/src/data/GuildCases.ts index afad41bc..90a10c3a 100644 --- a/src/data/GuildCases.ts +++ b/src/data/GuildCases.ts @@ -70,11 +70,12 @@ export class GuildCases extends BaseRepository { }); } - async getRecent(count: number): Promise { + async getRecentByModId(modId: string, count: number): Promise { return this.cases.find({ relations: this.getRelations(), where: { guild_id: this.guildId, + mod_id: modId, is_hidden: 0, }, take: count, diff --git a/src/plugins/ModActions.ts b/src/plugins/ModActions.ts index 9f45edf0..f82c23e8 100644 --- a/src/plugins/ModActions.ts +++ b/src/plugins/ModActions.ts @@ -1138,16 +1138,23 @@ export class ModActionsPlugin extends ZeppelinPlugin { } } - @d.command("cases") + @d.command("cases", null, { + options: [{ name: "mod", type: "Member" }], + }) @d.permission("view") - async recentCasesCmd(msg: Message) { - const recentCases = await this.cases.with("notes").getRecent(5); + async recentCasesCmd(msg: Message, args: { mod?: Member }) { + const modId = args.mod ? args.mod.id : msg.author.id; + const recentCases = await this.cases.with("notes").getRecentByModId(modId, 5); + + const mod = this.bot.users.get(modId); + const modName = mod ? `${mod.username}#${mod.discriminator}` : modId; + if (recentCases.length === 0) { - msg.channel.createMessage(errorMessage("No cases")); + msg.channel.createMessage(errorMessage(`No cases by **${modName}**`)); } else { const lines = recentCases.map(c => this.cases.getSummaryText(c)); const finalMessage = trimLines(` - Most recent 5 cases: + Most recent 5 cases by **${modName}**: ${lines.join("\n")}