From 1a48fd647fc84952439da5484d38f4d16c89198c Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Thu, 6 Jan 2022 17:02:57 -0500 Subject: fixed some errors, made moderation methods use manual enum thing --- src/lib/common/util/Moderation.ts | 62 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) (limited to 'src/lib/common') diff --git a/src/lib/common/util/Moderation.ts b/src/lib/common/util/Moderation.ts index a09930b..9757f25 100644 --- a/src/lib/common/util/Moderation.ts +++ b/src/lib/common/util/Moderation.ts @@ -3,12 +3,14 @@ import { ActivePunishmentType, Guild, ModLog, + type BushGuild, type BushGuildMember, type BushGuildMemberResolvable, type BushGuildResolvable, + type BushUserResolvable, type ModLogType } from '#lib'; -import { type Snowflake } from 'discord.js'; +import { MessageEmbed, type Snowflake } from 'discord.js'; /** * A utility class with moderation-related methods. @@ -197,6 +199,28 @@ export class Moderation { }; return typeMap[type]; } + + public static async punishDM(options: PunishDMOptions): Promise { + const ending = await options.guild.getSetting('punishmentEnding'); + const dmEmbed = + ending && ending.length && options.sendFooter + ? new MessageEmbed().setDescription(ending).setColor(util.colors.newBlurple) + : undefined; + + const dmSuccess = await client.users + .send(options.user, { + content: `You have been ${options.punishment} in **${options.guild.name}** ${ + options.duration !== null && options.duration !== undefined + ? options.duration + ? `for ${util.humanizeDuration(options.duration)} ` + : 'permanently ' + : '' + }for **${options.reason?.trim() ? options.reason?.trim() : 'No reason provided'}**.`, + embeds: dmEmbed ? [dmEmbed] : undefined + }) + .catch(() => false); + return !!dmSuccess; + } } /** @@ -303,3 +327,39 @@ export interface RemovePunishmentEntryOptions { */ extraInfo?: Snowflake; } + +/** + * Options for sending a user a punishment dm. + */ +export interface PunishDMOptions { + /** + * The guild that the punishment is taking place in. + */ + guild: BushGuild; + + /** + * The user that is being punished. + */ + user: BushUserResolvable; + + /** + * The punishment that the user has received. + */ + punishment: string; + + /** + * The reason the user's punishment. + */ + reason?: string; + + /** + * The duration of the punishment. + */ + duration?: number; + + /** + * Whether or not to send the guild's punishment footer with the dm. + * @default true + */ + sendFooter: boolean; +} -- cgit