Add audit view subcommand

This commit is contained in:
Ethan Lane 2022-08-19 19:35:05 +01:00
parent 595c15acb1
commit b85af78e5c
Signed by: Vylpes
GPG key ID: EED233CC06D12504
2 changed files with 33 additions and 2 deletions

View file

@ -4,6 +4,7 @@ import AuditTools from "../helpers/AuditTools";
import PublicEmbed from "../helpers/embeds/PublicEmbed";
import { Command } from "../type/command";
import SettingsHelper from "../helpers/SettingsHelper";
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
export default class Audits extends Command {
constructor() {
@ -22,6 +23,9 @@ export default class Audits extends Command {
case "user":
await this.SendAuditForUser(context);
break;
case "view":
await this.SendAudit(context);
break;
default:
await this.SendUsage(context);
}
@ -32,6 +36,7 @@ export default class Audits extends Command {
const description = [
`\`${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"));
@ -58,4 +63,30 @@ export default class Audits extends Command {
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();
}
}

View file

@ -44,12 +44,12 @@ export default class Audit extends BaseEntity {
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 repository = connection.getRepository(Audit);
const single = await repository.findOne({ AuditId: auditId });
const single = await repository.findOne({ AuditId: auditId, ServerId: serverId });
return single;
}