diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-05-27 17:15:53 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-05-27 17:15:53 -0400 |
commit | 705cead579a79d6ee86dd2e5edfcea2344bea6ce (patch) | |
tree | 3adf8875de96e84506d7b650cdc50d358a861d5c /src/commands/moderation/warn.ts | |
parent | 2c74ebf6651ccdc78e9fa5799c7887fe52b1ac2d (diff) | |
parent | 1546da359646b89f13d17784eb7653a52ca61efd (diff) | |
download | tanzanite-705cead579a79d6ee86dd2e5edfcea2344bea6ce.tar.gz tanzanite-705cead579a79d6ee86dd2e5edfcea2344bea6ce.tar.bz2 tanzanite-705cead579a79d6ee86dd2e5edfcea2344bea6ce.zip |
Merge branch 'rewrite' of https://github.com/NotEnoughUpdates/mb-bot-ts into rewrite
Diffstat (limited to 'src/commands/moderation/warn.ts')
-rw-r--r-- | src/commands/moderation/warn.ts | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/commands/moderation/warn.ts b/src/commands/moderation/warn.ts new file mode 100644 index 0000000..a61eef3 --- /dev/null +++ b/src/commands/moderation/warn.ts @@ -0,0 +1,68 @@ +import { GuildMember, Message } from 'discord.js'; +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { Guild, Modlog, ModlogType } from '../../lib/models'; + +export default class WarnCommand extends BushCommand { + public constructor() { + super('warn', { + aliases: ['warn'], + category: 'moderation', + userPermissions: ['MANAGE_MESSAGES'], + args: [ + { + id: 'member', + type: 'member' + }, + { + id: 'reason', + match: 'rest' + } + ], + description: { + content: 'Warn a member and log it in modlogs', + usage: 'warn <member> <reason>', + examples: ['warn @Tyman being cool'] + } + }); + } + public async exec( + message: Message, + { member, reason }: { member: GuildMember; reason: string } + ): Promise<void> { + // Create guild entry so postgres doesn't get mad when I try and add a modlog entry + await Guild.findOrCreate({ + where: { + id: message.guild.id + }, + defaults: { + id: message.guild.id + } + }); + 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}".` + ); + } +} |