Create add audit subcommand
This commit is contained in:
parent
10f23fedd9
commit
061b375b34
2 changed files with 42 additions and 0 deletions
|
@ -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 <id>\` - Send the audits for this user`,
|
||||
`\`${prefix}audits view <id>\` - Send information about an audit`,
|
||||
`\`${prefix}audits clear <id>\` - Clears an audit for a user by audit id`,
|
||||
`\`${prefix}audits add <userid> <type> [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();
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue