From 763fb7d98c3accbb21adf035a7cf0a83cb9533c9 Mon Sep 17 00:00:00 2001 From: TymanWasTaken <32660892+tymanwastaken@users.noreply.github.com> Date: Tue, 27 Apr 2021 21:06:22 -0600 Subject: legit just copy utilibot v2 code --- src/commands/moderation/WarnCommand.ts | 54 ++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/commands/moderation/WarnCommand.ts (limited to 'src/commands/moderation/WarnCommand.ts') diff --git a/src/commands/moderation/WarnCommand.ts b/src/commands/moderation/WarnCommand.ts new file mode 100644 index 0000000..676615d --- /dev/null +++ b/src/commands/moderation/WarnCommand.ts @@ -0,0 +1,54 @@ +import { GuildMember } from 'discord.js'; +import { BotCommand } from '../../lib/extensions/BotCommand'; +import { BotMessage } from '../../lib/extensions/BotMessage'; +import { Modlog, ModlogType } from '../../lib/types/Models'; + +export default class WarnCommand extends BotCommand { + public constructor() { + super('warn', { + aliases: ['warn'], + userPermissions: ['MANAGE_MESSAGES'], + args: [ + { + id: 'member', + type: 'member' + }, + { + id: 'reason', + match: 'rest' + } + ] + }); + } + public async exec( + message: BotMessage, + { member, reason }: { member: GuildMember; reason: string } + ): Promise { + try { + const entry = Modlog.build({ + user: member.id, + guild: message.guild.id, + moderator: message.author.id, + type: ModlogType.WARN, + reason + }); + await entry.save(); + } catch (e) { + await message.util.send( + 'Error saving to database, please contact the developers' + ); + return; + } + try { + await member.send( + `You were warned in ${message.guild.name} for reason "${reason}".` + ); + } catch (e) { + await message.util.send('Error messaging user, warning still saved.'); + return; + } + await message.util.send( + `${member.user.tag} was warned for reason "${reason}".` + ); + } +} -- cgit