aboutsummaryrefslogtreecommitdiff
path: root/src/lib/common/util/Moderation.ts
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-01-06 17:02:57 -0500
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-01-06 17:02:57 -0500
commit1a48fd647fc84952439da5484d38f4d16c89198c (patch)
treed2033f7f614ee95013b3abb92b8ad890653d1fee /src/lib/common/util/Moderation.ts
parente8a55bd9edf535d30171c2f1c7c3cc11b4f7595c (diff)
downloadtanzanite-1a48fd647fc84952439da5484d38f4d16c89198c.tar.gz
tanzanite-1a48fd647fc84952439da5484d38f4d16c89198c.tar.bz2
tanzanite-1a48fd647fc84952439da5484d38f4d16c89198c.zip
fixed some errors, made moderation methods use manual enum thing
Diffstat (limited to 'src/lib/common/util/Moderation.ts')
-rw-r--r--src/lib/common/util/Moderation.ts62
1 files changed, 61 insertions, 1 deletions
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<boolean> {
+ 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;
+}