ModActions: !cases without id now returns 5 most recent cases created by you, or the mod specified with --mod

This commit is contained in:
Dragory 2019-02-23 22:40:43 +02:00
parent 7ced26cd19
commit ffafc765d8
2 changed files with 14 additions and 6 deletions

View file

@ -70,11 +70,12 @@ export class GuildCases extends BaseRepository {
}); });
} }
async getRecent(count: number): Promise<Case[]> { async getRecentByModId(modId: string, count: number): Promise<Case[]> {
return this.cases.find({ return this.cases.find({
relations: this.getRelations(), relations: this.getRelations(),
where: { where: {
guild_id: this.guildId, guild_id: this.guildId,
mod_id: modId,
is_hidden: 0, is_hidden: 0,
}, },
take: count, take: count,

View file

@ -1138,16 +1138,23 @@ export class ModActionsPlugin extends ZeppelinPlugin {
} }
} }
@d.command("cases") @d.command("cases", null, {
options: [{ name: "mod", type: "Member" }],
})
@d.permission("view") @d.permission("view")
async recentCasesCmd(msg: Message) { async recentCasesCmd(msg: Message, args: { mod?: Member }) {
const recentCases = await this.cases.with("notes").getRecent(5); 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) { if (recentCases.length === 0) {
msg.channel.createMessage(errorMessage("No cases")); msg.channel.createMessage(errorMessage(`No cases by **${modName}**`));
} else { } else {
const lines = recentCases.map(c => this.cases.getSummaryText(c)); const lines = recentCases.map(c => this.cases.getSummaryText(c));
const finalMessage = trimLines(` const finalMessage = trimLines(`
Most recent 5 cases: Most recent 5 cases by **${modName}**:
${lines.join("\n")} ${lines.join("\n")}