mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 22:21:51 +00:00
Allow using !update without a case number. Will update the mod's latest case instead.
This commit is contained in:
parent
ed3760313f
commit
fa759d1f46
2 changed files with 47 additions and 13 deletions
|
@ -22,8 +22,8 @@ export class GuildCases extends BaseRepository {
|
||||||
relations: this.getRelations(),
|
relations: this.getRelations(),
|
||||||
where: {
|
where: {
|
||||||
guild_id: this.guildId,
|
guild_id: this.guildId,
|
||||||
id: In(ids)
|
id: In(ids),
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,8 +32,8 @@ export class GuildCases extends BaseRepository {
|
||||||
relations: this.getRelations(),
|
relations: this.getRelations(),
|
||||||
where: {
|
where: {
|
||||||
guild_id: this.guildId,
|
guild_id: this.guildId,
|
||||||
id
|
id,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,8 +42,21 @@ export class GuildCases extends BaseRepository {
|
||||||
relations: this.getRelations(),
|
relations: this.getRelations(),
|
||||||
where: {
|
where: {
|
||||||
guild_id: this.guildId,
|
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(),
|
relations: this.getRelations(),
|
||||||
where: {
|
where: {
|
||||||
guild_id: this.guildId,
|
guild_id: this.guildId,
|
||||||
user_id: userId
|
user_id: userId,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,8 +74,8 @@ export class GuildCases extends BaseRepository {
|
||||||
await this.cases.update(
|
await this.cases.update(
|
||||||
{ id },
|
{ id },
|
||||||
{
|
{
|
||||||
is_hidden: hidden
|
is_hidden: hidden,
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +83,7 @@ export class GuildCases extends BaseRepository {
|
||||||
const result = await this.cases.insert({
|
const result = await this.cases.insert({
|
||||||
...data,
|
...data,
|
||||||
guild_id: this.guildId,
|
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);
|
return this.find(result.identifiers[0].id);
|
||||||
|
@ -83,7 +96,7 @@ export class GuildCases extends BaseRepository {
|
||||||
async createNote(caseId: number, data: any): Promise<void> {
|
async createNote(caseId: number, data: any): Promise<void> {
|
||||||
await this.caseNotes.insert({
|
await this.caseNotes.insert({
|
||||||
...data,
|
...data,
|
||||||
case_id: caseId
|
case_id: caseId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -261,7 +261,7 @@ export class ModActionsPlugin extends ZeppelinPlugin {
|
||||||
*/
|
*/
|
||||||
@d.command(/update|updatecase/, "<caseNumber:number> <note:string$>")
|
@d.command(/update|updatecase/, "<caseNumber:number> <note:string$>")
|
||||||
@d.permission("note")
|
@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);
|
const theCase = await this.cases.findByCaseNumber(args.caseNumber);
|
||||||
if (!theCase) {
|
if (!theCase) {
|
||||||
msg.channel.createMessage(errorMessage("Case not found"));
|
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`));
|
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.command("note", "<userId:userId> <note:string$>")
|
||||||
@d.permission("note")
|
@d.permission("note")
|
||||||
async noteCmd(msg: Message, args: any) {
|
async noteCmd(msg: Message, args: any) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue