diff --git a/src/commands/audits.ts b/src/commands/audits.ts index b6045a0..fb28026 100644 --- a/src/commands/audits.ts +++ b/src/commands/audits.ts @@ -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 \` - Send the audits for this user`, + `\`${prefix}audits view \` - 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(); + } } \ No newline at end of file diff --git a/src/entity/Audit.ts b/src/entity/Audit.ts index 58d2356..0ec1ea7 100644 --- a/src/entity/Audit.ts +++ b/src/entity/Audit.ts @@ -44,12 +44,12 @@ export default class Audit extends BaseEntity { return all; } - public static async FetchAuditByAuditId(auditId: string): Promise { + public static async FetchAuditByAuditId(auditId: string, serverId: string): Promise { 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; }