Add audit view subcommand
This commit is contained in:
parent
595c15acb1
commit
b85af78e5c
2 changed files with 33 additions and 2 deletions
|
@ -4,6 +4,7 @@ import AuditTools from "../helpers/AuditTools";
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
import SettingsHelper from "../helpers/SettingsHelper";
|
import SettingsHelper from "../helpers/SettingsHelper";
|
||||||
|
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
||||||
|
|
||||||
export default class Audits extends Command {
|
export default class Audits extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -22,6 +23,9 @@ export default class Audits extends Command {
|
||||||
case "user":
|
case "user":
|
||||||
await this.SendAuditForUser(context);
|
await this.SendAuditForUser(context);
|
||||||
break;
|
break;
|
||||||
|
case "view":
|
||||||
|
await this.SendAudit(context);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
await this.SendUsage(context);
|
await this.SendUsage(context);
|
||||||
}
|
}
|
||||||
|
@ -32,6 +36,7 @@ export default class Audits extends Command {
|
||||||
|
|
||||||
const description = [
|
const description = [
|
||||||
`\`${prefix}audits user <id>\` - Send the audits for this user`,
|
`\`${prefix}audits user <id>\` - Send the audits for this user`,
|
||||||
|
`\`${prefix}audits view <id>\` - Send information about an audit`,
|
||||||
]
|
]
|
||||||
|
|
||||||
const publicEmbed = new PublicEmbed(context, "Usage", description.join("\n"));
|
const publicEmbed = new PublicEmbed(context, "Usage", description.join("\n"));
|
||||||
|
@ -58,4 +63,30 @@ export default class Audits extends Command {
|
||||||
|
|
||||||
await publicEmbed.SendToCurrentChannel();
|
await publicEmbed.SendToCurrentChannel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async SendAudit(context: ICommandContext) {
|
||||||
|
const auditId = context.args[1];
|
||||||
|
|
||||||
|
if (!auditId) {
|
||||||
|
await this.SendUsage(context);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const audit = await Audit.FetchAuditByAuditId(auditId.toUpperCase(), context.message.guild!.id);
|
||||||
|
|
||||||
|
if (!audit) {
|
||||||
|
const errorEmbed = new ErrorEmbed(context, "This audit can not be found.");
|
||||||
|
await errorEmbed.SendToCurrentChannel();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const publicEmbed = new PublicEmbed(context, `Audit ${audit.AuditId.toUpperCase()}`, "");
|
||||||
|
|
||||||
|
publicEmbed.addField("Reason", audit.Reason, true);
|
||||||
|
publicEmbed.addField("Type", AuditTools.TypeToFriendlyText(audit.AuditType), true);
|
||||||
|
publicEmbed.addField("Moderator", `<@${audit.ModeratorId}>`, true);
|
||||||
|
|
||||||
|
await publicEmbed.SendToCurrentChannel();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -44,12 +44,12 @@ export default class Audit extends BaseEntity {
|
||||||
return all;
|
return all;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async FetchAuditByAuditId(auditId: string): Promise<Audit | undefined> {
|
public static async FetchAuditByAuditId(auditId: string, serverId: string): Promise<Audit | undefined> {
|
||||||
const connection = getConnection();
|
const connection = getConnection();
|
||||||
|
|
||||||
const repository = connection.getRepository(Audit);
|
const repository = connection.getRepository(Audit);
|
||||||
|
|
||||||
const single = await repository.findOne({ AuditId: auditId });
|
const single = await repository.findOne({ AuditId: auditId, ServerId: serverId });
|
||||||
|
|
||||||
return single;
|
return single;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue