3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

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({
relations: this.getRelations(),
where: {
guild_id: this.guildId,
mod_id: modId,
is_hidden: 0,
},
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")
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")}