3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

Allow using !update without a case number. Will update the mod's latest case instead.

This commit is contained in:
Dragory 2019-02-17 15:23:40 +02:00
parent ed3760313f
commit fa759d1f46
2 changed files with 47 additions and 13 deletions

View file

@ -22,8 +22,8 @@ export class GuildCases extends BaseRepository {
relations: this.getRelations(),
where: {
guild_id: this.guildId,
id: In(ids)
}
id: In(ids),
},
});
}
@ -32,8 +32,8 @@ export class GuildCases extends BaseRepository {
relations: this.getRelations(),
where: {
guild_id: this.guildId,
id
}
id,
},
});
}
@ -42,8 +42,21 @@ export class GuildCases extends BaseRepository {
relations: this.getRelations(),
where: {
guild_id: this.guildId,
case_number: caseNumber
}
case_number: caseNumber,
},
});
}
async findLatestByModId(modId: string): Promise<Case> {
return this.cases.findOne({
relations: this.getRelations(),
where: {
guild_id: this.guildId,
mod_id: modId,
},
order: {
case_number: "DESC",
},
});
}
@ -52,8 +65,8 @@ export class GuildCases extends BaseRepository {
relations: this.getRelations(),
where: {
guild_id: this.guildId,
user_id: userId
}
user_id: userId,
},
});
}
@ -61,8 +74,8 @@ export class GuildCases extends BaseRepository {
await this.cases.update(
{ id },
{
is_hidden: hidden
}
is_hidden: hidden,
},
);
}
@ -70,7 +83,7 @@ export class GuildCases extends BaseRepository {
const result = await this.cases.insert({
...data,
guild_id: this.guildId,
case_number: () => `(SELECT IFNULL(MAX(case_number)+1, 1) FROM cases AS ma2 WHERE guild_id = ${this.guildId})`
case_number: () => `(SELECT IFNULL(MAX(case_number)+1, 1) FROM cases AS ma2 WHERE guild_id = ${this.guildId})`,
});
return this.find(result.identifiers[0].id);
@ -83,7 +96,7 @@ export class GuildCases extends BaseRepository {
async createNote(caseId: number, data: any): Promise<void> {
await this.caseNotes.insert({
...data,
case_id: caseId
case_id: caseId,
});
}

View file

@ -261,7 +261,7 @@ export class ModActionsPlugin extends ZeppelinPlugin {
*/
@d.command(/update|updatecase/, "<caseNumber:number> <note:string$>")
@d.permission("note")
async updateCmd(msg: Message, args: any) {
async updateSpecificCmd(msg: Message, args: { caseNumber: number; note: string }) {
const theCase = await this.cases.findByCaseNumber(args.caseNumber);
if (!theCase) {
msg.channel.createMessage(errorMessage("Case not found"));
@ -277,6 +277,27 @@ export class ModActionsPlugin extends ZeppelinPlugin {
msg.channel.createMessage(successMessage(`Case \`#${theCase.case_number}\` updated`));
}
/**
* Update the latest case
*/
@d.command(/update|updatecase/, "<note:string$>")
@d.permission("note")
async updateLatestCmd(msg: Message, args: { note: string }) {
const theCase = await this.cases.findLatestByModId(msg.author.id);
if (!theCase) {
msg.channel.createMessage(errorMessage("No latest case"));
return;
}
await this.actions.fire("createCaseNote", {
caseId: theCase.id,
modId: msg.author.id,
note: args.note,
});
msg.channel.createMessage(successMessage(`Case \`#${theCase.case_number}\` updated`));
}
@d.command("note", "<userId:userId> <note:string$>")
@d.permission("note")
async noteCmd(msg: Message, args: any) {