From 061b375b346197c5703994f48935a482d44608fe Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Fri, 19 Aug 2022 19:54:26 +0100 Subject: [PATCH] Create add audit subcommand --- src/commands/audits.ts | 25 +++++++++++++++++++++++++ src/helpers/AuditTools.ts | 17 +++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/commands/audits.ts b/src/commands/audits.ts index f0138b5..e3dfd80 100644 --- a/src/commands/audits.ts +++ b/src/commands/audits.ts @@ -29,6 +29,9 @@ export default class Audits extends Command { case "clear": await this.ClearAudit(context); break; + case "add": + await this.AddAudit(context); + break; default: await this.SendUsage(context); } @@ -41,6 +44,7 @@ export default class Audits extends Command { `\`${prefix}audits user \` - Send the audits for this user`, `\`${prefix}audits view \` - Send information about an audit`, `\`${prefix}audits clear \` - Clears an audit for a user by audit id`, + `\`${prefix}audits add [reason]\` - Manually add an audit for a user`, ] const publicEmbed = new PublicEmbed(context, "Usage", description.join("\n")); @@ -116,4 +120,25 @@ export default class Audits extends Command { const publicEmbed = new PublicEmbed(context, "", "Audit cleared"); await publicEmbed.SendToCurrentChannel(); } + + private async AddAudit(context: ICommandContext) { + const userId = context.args[1]; + const typeString = context.args[2]; + const reason = context.args.splice(3) + .join(" "); + + if (!userId || !typeString) { + await this.SendUsage(context); + return; + } + + const type = AuditTools.StringToType(typeString); + + const audit = new Audit(userId, type, reason, context.message.author.id, context.message.guild!.id); + + await audit.Save(Audit, audit); + + const publicEmbed = new PublicEmbed(context, "", `Created new audit with ID \`${audit.AuditId}\``); + await publicEmbed.SendToCurrentChannel(); + } } \ No newline at end of file diff --git a/src/helpers/AuditTools.ts b/src/helpers/AuditTools.ts index 1464fa1..fa06c43 100644 --- a/src/helpers/AuditTools.ts +++ b/src/helpers/AuditTools.ts @@ -17,4 +17,21 @@ export default class AuditTools { return "Other"; } } + + public static StringToType(str: string): AuditType { + switch (str.toLowerCase()) { + case "general": + return AuditType.General; + case "warn": + return AuditType.Warn; + case "mute": + return AuditType.Mute; + case "kick": + return AuditType.Kick; + case "ban": + return AuditType.Ban; + default: + return AuditType.General; + } + } } \ No newline at end of file