aboutsummaryrefslogtreecommitdiff
path: root/src/lib/extensions/discord.js
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-09-02 19:49:21 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-09-02 19:49:21 -0400
commit29cebebc18e9570b699caef8ebb04f4d3934722d (patch)
tree15a47fb5bea3839098d7700b48ad0f8b33eb13fa /src/lib/extensions/discord.js
parent39927eb63081eb8120f75ad38bc336bb48d0f2a7 (diff)
downloadtanzanite-29cebebc18e9570b699caef8ebb04f4d3934722d.tar.gz
tanzanite-29cebebc18e9570b699caef8ebb04f4d3934722d.tar.bz2
tanzanite-29cebebc18e9570b699caef8ebb04f4d3934722d.zip
clean up
Diffstat (limited to 'src/lib/extensions/discord.js')
-rw-r--r--src/lib/extensions/discord.js/BushGuildMember.ts51
-rw-r--r--src/lib/extensions/discord.js/BushMessage.ts8
-rw-r--r--src/lib/extensions/discord.js/BushThreadMember.ts1
3 files changed, 26 insertions, 34 deletions
diff --git a/src/lib/extensions/discord.js/BushGuildMember.ts b/src/lib/extensions/discord.js/BushGuildMember.ts
index 67fa2fa..2c41873 100644
--- a/src/lib/extensions/discord.js/BushGuildMember.ts
+++ b/src/lib/extensions/discord.js/BushGuildMember.ts
@@ -1,5 +1,4 @@
-/* eslint-disable @typescript-eslint/no-unused-vars */
-import { GuildMember, Partialize, Role } from 'discord.js';
+import { GuildMember, MessageEmbed, Partialize, Role } from 'discord.js';
import { RawGuildMemberData } from 'discord.js/typings/rawDataTypes';
import { ModLogType } from '../../models/ModLog';
import { BushClient, BushUserResolvable } from '../discord-akairo/BushClient';
@@ -86,6 +85,21 @@ export class BushGuildMember extends GuildMember {
super(client, data, guild);
}
+ private async punishDM(punishment: string, reason?: string | null, duration?: number, sendFooter = true): Promise<boolean> {
+ const ending = await this.guild.getSetting('punishmentEnding');
+ const dmEmbed =
+ ending && ending.length && sendFooter
+ ? new MessageEmbed().setDescription(ending).setColor(util.colors.newBlurple)
+ : undefined;
+ const dmSuccess = await this.send({
+ content: `You have been ${punishment} in **${this.guild.name}** ${
+ duration !== null || duration !== undefined ? (duration ? `for ${util.humanizeDuration(duration)}` : 'permanently') : ''
+ }for **${reason ?? 'No reason provided'}**.${ending ? `\n\n${ending}` : ''}`,
+ embeds: dmEmbed ? [dmEmbed] : undefined
+ }).catch(() => false);
+ return !!dmSuccess;
+ }
+
public async warn(options: BushPunishmentOptions): Promise<{ result: WarnResponse | null; caseNum: number | null }> {
const moderator = (await util.resolveNonCachedUser(options.moderator ?? this.guild.me))!;
@@ -103,13 +117,7 @@ export class BushGuildMember extends GuildMember {
if (!result || !result.log) return { result: 'error creating modlog entry', caseNum: null };
// dm user
- const ending = await this.guild.getSetting('punishmentEnding');
- const dmSuccess = await this.send({
- content: `You have been warned in **${this.guild.name}** for **${options.reason ?? 'No reason provided'}**.${
- ending ? `\n\n${ending}` : ''
- }`
- }).catch(() => false);
-
+ const dmSuccess = await this.punishDM('warned', options.reason);
if (!dmSuccess) return { result: 'failed to dm', caseNum: result.caseNum };
return { result: 'success', caseNum: result.caseNum };
@@ -244,12 +252,7 @@ export class BushGuildMember extends GuildMember {
if (!punishmentEntrySuccess) return 'error creating mute entry';
// dm user
- const ending = await this.guild.getSetting('punishmentEnding');
- const dmSuccess = await this.send({
- content: `You have been muted ${
- options.duration ? 'for ' + util.humanizeDuration(options.duration) : 'permanently'
- } in **${this.guild.name}** for **${options.reason ?? 'No reason provided'}**.${ending ? `\n\n${ending}` : ''}`
- }).catch(() => false);
+ const dmSuccess = await this.punishDM('muted', options.reason, options.duration ?? 0);
if (!dmSuccess) return 'failed to dm';
@@ -297,9 +300,7 @@ export class BushGuildMember extends GuildMember {
if (!removePunishmentEntrySuccess) return 'error removing mute entry';
//dm user
- const dmSuccess = await this.send({
- content: `You have been unmuted in **${this.guild.name}** because **${options.reason ?? 'No reason provided'}**.`
- }).catch(() => false);
+ const dmSuccess = await this.punishDM('unmuted', options.reason, undefined, false);
if (!dmSuccess) return 'failed to dm';
@@ -313,12 +314,7 @@ export class BushGuildMember extends GuildMember {
const moderator = (await util.resolveNonCachedUser(options.moderator ?? this.guild.me))!;
// dm user
- const ending = await this.guild.getSetting('punishmentEnding');
- const dmSuccess = await this.send({
- content: `You have been kicked from **${this.guild.name}** for **${options.reason ?? 'No reason provided'}**.${
- ending ? `\n\n${ending}` : ''
- }`
- }).catch(() => false);
+ const dmSuccess = await this.punishDM('kicked', options.reason);
// kick
const kickSuccess = await this.kick(`${moderator?.tag} | ${options.reason ?? 'No reason provided.'}`).catch(() => false);
@@ -344,12 +340,7 @@ export class BushGuildMember extends GuildMember {
const moderator = (await util.resolveNonCachedUser(options.moderator ?? this.guild.me))!;
// dm user
- const ending = await this.guild.getSetting('punishmentEnding');
- const dmSuccess = await this.send({
- content: `You have been banned ${
- options?.duration ? 'for ' + util.humanizeDuration(options.duration) : 'permanently'
- } from **${this.guild.name}** for **${options.reason ?? 'No reason provided'}**.${ending ? `\n\n${ending}` : ''}`
- }).catch(() => false);
+ const dmSuccess = await this.punishDM('banned', options.reason, options.duration ?? 0);
// ban
const banSuccess = await this.ban({
diff --git a/src/lib/extensions/discord.js/BushMessage.ts b/src/lib/extensions/discord.js/BushMessage.ts
index 7907efe..f2dd02c 100644
--- a/src/lib/extensions/discord.js/BushMessage.ts
+++ b/src/lib/extensions/discord.js/BushMessage.ts
@@ -1,4 +1,3 @@
-/* eslint-disable @typescript-eslint/no-empty-interface */
import { Message, Partialize } from 'discord.js';
import { RawMessageData } from 'discord.js/typings/rawDataTypes';
import { BushClient, BushTextBasedChannels } from '../discord-akairo/BushClient';
@@ -7,8 +6,11 @@ import { BushGuild } from './BushGuild';
import { BushGuildMember } from './BushGuildMember';
import { BushUser } from './BushUser';
-export interface PartialBushMessage
- extends Partialize<BushMessage, 'type' | 'system' | 'pinned' | 'tts', 'content' | 'cleanContent' | 'author'> {}
+export type PartialBushMessage = Partialize<
+ BushMessage,
+ 'type' | 'system' | 'pinned' | 'tts',
+ 'content' | 'cleanContent' | 'author'
+>;
export class BushMessage extends Message {
public declare readonly client: BushClient;
public override util!: BushCommandUtil;
diff --git a/src/lib/extensions/discord.js/BushThreadMember.ts b/src/lib/extensions/discord.js/BushThreadMember.ts
index 77f2b20..10c7e84 100644
--- a/src/lib/extensions/discord.js/BushThreadMember.ts
+++ b/src/lib/extensions/discord.js/BushThreadMember.ts
@@ -1,4 +1,3 @@
-/* eslint-disable @typescript-eslint/ban-types */
import { ThreadMember } from 'discord.js';
import { RawThreadMemberData } from 'discord.js/typings/rawDataTypes';
import { BushGuildMember } from './BushGuildMember';