aboutsummaryrefslogtreecommitdiff
path: root/lib/extensions/discord.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/extensions/discord.js')
-rw-r--r--lib/extensions/discord.js/BotClientEvents.ts31
-rw-r--r--lib/extensions/discord.js/ExtendedGuild.ts21
-rw-r--r--lib/extensions/discord.js/ExtendedGuildMember.ts69
3 files changed, 44 insertions, 77 deletions
diff --git a/lib/extensions/discord.js/BotClientEvents.ts b/lib/extensions/discord.js/BotClientEvents.ts
index 284ea32..941a6d8 100644
--- a/lib/extensions/discord.js/BotClientEvents.ts
+++ b/lib/extensions/discord.js/BotClientEvents.ts
@@ -1,4 +1,3 @@
-import type { BanResponse, CommandMessage, Guild as GuildDB, GuildSettings } from '#lib';
import type { AkairoClientEvents } from 'discord-akairo';
import type {
ButtonInteraction,
@@ -13,32 +12,10 @@ import type {
Snowflake,
User
} from 'discord.js';
-
-export enum TanzaniteEvent {
- Ban = 'customBan',
- Block = 'customBlock',
- Kick = 'customKick',
- Mute = 'customMute',
- PunishRoleAdd = 'punishRoleAdd',
- PunishRoleRemove = 'punishRoleRemove',
- Purge = 'customPurge',
- RemoveTimeout = 'customRemoveTimeout',
- Timeout = 'customTimeout',
- Unban = 'customUnban',
- Unblock = 'customUnblock',
- Unmute = 'customUnmute',
- UpdateModlog = 'updateModlog',
- UpdateSettings = 'updateSettings',
- Warn = 'customWarn',
- LevelUpdate = 'levelUpdate',
- Lockdown = 'lockdown',
- Unlockdown = 'unlockdown',
- MassBan = 'massBan',
- MassEvidence = 'massEvidence',
- Button = 'button',
- SelectMenu = 'selectMenu',
- ModalSubmit = 'modal'
-}
+import { Guild as GuildDB, GuildSettings } from '../../models/index.js';
+import { TanzaniteEvent } from '../../utils/Constants.js';
+import { CommandMessage } from '../discord-akairo/BotCommand.js';
+import { BanResponse } from './ExtendedGuildMember.js';
export interface BotClientEvents extends AkairoClientEvents {
[TanzaniteEvent.Ban]: [
diff --git a/lib/extensions/discord.js/ExtendedGuild.ts b/lib/extensions/discord.js/ExtendedGuild.ts
index 67de5cf..6b69206 100644
--- a/lib/extensions/discord.js/ExtendedGuild.ts
+++ b/lib/extensions/discord.js/ExtendedGuild.ts
@@ -1,19 +1,7 @@
-import {
- AllowedMentions,
- banResponse,
- colors,
- dmResponse,
- emojis,
- permissionsResponse,
- punishmentEntryRemove,
- TanzaniteClient,
- type BanResponse,
- type GuildFeatures,
- type GuildLogType,
- type GuildModel
-} from '#lib';
import * as Moderation from '#lib/common/Moderation.js';
-import { Guild as GuildDB, ModLogType } from '#lib/models/index.js';
+import { Guild as GuildDB, GuildFeatures, GuildLogType, GuildModel, ModLogType } from '#lib/models/index.js';
+import { AllowedMentions } from '#lib/utils/AllowedMentions.js';
+import { colors, emojis, TanzaniteEvent } from '#lib/utils/Constants.js';
import { addOrRemoveFromArray } from '#lib/utils/Utils.js';
import assert from 'assert/strict';
import {
@@ -43,7 +31,8 @@ import {
type WebhookMessageOptions
} from 'discord.js';
import _ from 'lodash';
-import { TanzaniteEvent } from './BotClientEvents.js';
+import { TanzaniteClient } from '../discord-akairo/TanzaniteClient.js';
+import { banResponse, BanResponse, dmResponse, permissionsResponse, punishmentEntryRemove } from './ExtendedGuildMember.js';
declare module 'discord.js' {
export interface BaseGuild {
diff --git a/lib/extensions/discord.js/ExtendedGuildMember.ts b/lib/extensions/discord.js/ExtendedGuildMember.ts
index 172f6df..043cc1d 100644
--- a/lib/extensions/discord.js/ExtendedGuildMember.ts
+++ b/lib/extensions/discord.js/ExtendedGuildMember.ts
@@ -1,15 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import {
- formatError,
- Moderation,
- ModLogType,
- TanzaniteClient,
- Time,
- type BotClientEvents,
- type PunishmentTypeDM,
- type ValueOf
-} from '#lib';
-import {
ChannelType,
GuildMember,
PermissionFlagsBits,
@@ -17,7 +7,18 @@ import {
type GuildTextBasedChannel,
type Role
} from 'discord.js';
-import { TanzaniteEvent } from './BotClientEvents.js';
+import {
+ checkMutePermissions,
+ createModLogEntry,
+ createPunishmentEntry,
+ punishDM,
+ PunishmentTypeDM,
+ removePunishmentEntry
+} from '../../common/Moderation.js';
+import { ModLogType } from '../../models/index.js';
+import { TanzaniteEvent, Time } from '../../utils/Constants.js';
+import { formatError, ValueOf } from '../../utils/Utils.js';
+import { TanzaniteClient } from '../discord-akairo/TanzaniteClient.js';
/* eslint-enable @typescript-eslint/no-unused-vars */
declare module 'discord.js' {
@@ -140,7 +141,7 @@ export class ExtendedGuildMember extends GuildMember {
modlog?: string,
sendFooter = true
): Promise<boolean> {
- return Moderation.punishDM({
+ return punishDM({
client: this.client,
modlog,
guild: this.guild,
@@ -166,7 +167,7 @@ export class ExtendedGuildMember extends GuildMember {
const ret = await (async (): Promise<{ result: WarnResponse; caseNum: number | null }> => {
// add modlog entry
- const result = await Moderation.createModLogEntry(
+ const result = await createModLogEntry(
{
client: this.client,
type: ModLogType.WARN,
@@ -214,7 +215,7 @@ export class ExtendedGuildMember extends GuildMember {
const ret = await (async () => {
if (options.addToModlog || options.duration) {
- const { log: modlog } = await Moderation.createModLogEntry({
+ const { log: modlog } = await createModLogEntry({
client: this.client,
type: options.duration ? ModLogType.TEMP_PUNISHMENT_ROLE : ModLogType.PERM_PUNISHMENT_ROLE,
guild: this.guild,
@@ -230,7 +231,7 @@ export class ExtendedGuildMember extends GuildMember {
caseID = modlog.id;
if (options.addToModlog || options.duration) {
- const punishmentEntrySuccess = await Moderation.createPunishmentEntry({
+ const punishmentEntrySuccess = await createPunishmentEntry({
client: this.client,
type: 'role',
user: this,
@@ -287,7 +288,7 @@ export class ExtendedGuildMember extends GuildMember {
const ret = await (async () => {
if (options.addToModlog) {
- const { log: modlog } = await Moderation.createModLogEntry({
+ const { log: modlog } = await createModLogEntry({
client: this.client,
type: ModLogType.REMOVE_PUNISHMENT_ROLE,
guild: this.guild,
@@ -301,7 +302,7 @@ export class ExtendedGuildMember extends GuildMember {
if (!modlog) return removeRoleResponse.MODLOG_ERROR;
caseID = modlog.id;
- const punishmentEntrySuccess = await Moderation.removePunishmentEntry({
+ const punishmentEntrySuccess = await removePunishmentEntry({
client: this.client,
type: 'role',
user: this,
@@ -370,7 +371,7 @@ export class ExtendedGuildMember extends GuildMember {
*/
public override async customMute(options: CustomTimedPunishmentOptions): Promise<MuteResponse> {
// checks
- const checks = await Moderation.checkMutePermissions(this.guild);
+ const checks = await checkMutePermissions(this.guild);
if (checks !== true) return checks;
const muteRoleID = (await this.guild.getSetting('muteRole'))!;
@@ -393,7 +394,7 @@ export class ExtendedGuildMember extends GuildMember {
if (!muteSuccess) return muteResponse.ACTION_ERROR;
// add modlog entry
- const { log: modlog } = await Moderation.createModLogEntry({
+ const { log: modlog } = await createModLogEntry({
client: this.client,
type: options.duration ? ModLogType.TEMP_MUTE : ModLogType.PERM_MUTE,
user: this,
@@ -409,7 +410,7 @@ export class ExtendedGuildMember extends GuildMember {
caseID = modlog.id;
// add punishment entry so they can be unmuted later
- const punishmentEntrySuccess = await Moderation.createPunishmentEntry({
+ const punishmentEntrySuccess = await createPunishmentEntry({
client: this.client,
type: 'mute',
user: this,
@@ -456,7 +457,7 @@ export class ExtendedGuildMember extends GuildMember {
*/
public override async customUnmute(options: CustomPunishmentOptions): Promise<UnmuteResponse> {
// checks
- const checks = await Moderation.checkMutePermissions(this.guild);
+ const checks = await checkMutePermissions(this.guild);
if (checks !== true) return checks;
const muteRoleID = (await this.guild.getSetting('muteRole'))!;
@@ -478,7 +479,7 @@ export class ExtendedGuildMember extends GuildMember {
if (!muteSuccess) return unmuteResponse.ACTION_ERROR;
// add modlog entry
- const { log: modlog } = await Moderation.createModLogEntry({
+ const { log: modlog } = await createModLogEntry({
client: this.client,
type: ModLogType.UNMUTE,
user: this,
@@ -493,7 +494,7 @@ export class ExtendedGuildMember extends GuildMember {
caseID = modlog.id;
// remove mute entry
- const removePunishmentEntrySuccess = await Moderation.removePunishmentEntry({
+ const removePunishmentEntrySuccess = await removePunishmentEntry({
client: this.client,
type: 'mute',
user: this,
@@ -548,7 +549,7 @@ export class ExtendedGuildMember extends GuildMember {
if (!moderator) return kickResponse.CANNOT_RESOLVE_USER;
const ret = await (async () => {
// add modlog entry
- const { log: modlog } = await Moderation.createModLogEntry({
+ const { log: modlog } = await createModLogEntry({
client: this.client,
type: ModLogType.KICK,
user: this,
@@ -613,7 +614,7 @@ export class ExtendedGuildMember extends GuildMember {
const ret = await (async () => {
// add modlog entry
- const { log: modlog } = await Moderation.createModLogEntry({
+ const { log: modlog } = await createModLogEntry({
client: this.client,
type: options.duration ? ModLogType.TEMP_BAN : ModLogType.PERM_BAN,
user: this,
@@ -641,7 +642,7 @@ export class ExtendedGuildMember extends GuildMember {
if (!banSuccess) return banResponse.ACTION_ERROR;
// add punishment entry so they can be unbanned later
- const punishmentEntrySuccess = await Moderation.createPunishmentEntry({
+ const punishmentEntrySuccess = await createPunishmentEntry({
client: this.client,
type: 'ban',
user: this,
@@ -699,7 +700,7 @@ export class ExtendedGuildMember extends GuildMember {
if (!blockSuccess) return blockResponse.ACTION_ERROR;
// add modlog entry
- const { log: modlog } = await Moderation.createModLogEntry({
+ const { log: modlog } = await createModLogEntry({
client: this.client,
type: options.duration ? ModLogType.TEMP_CHANNEL_BLOCK : ModLogType.PERM_CHANNEL_BLOCK,
user: this,
@@ -713,7 +714,7 @@ export class ExtendedGuildMember extends GuildMember {
caseID = modlog.id;
// add punishment entry so they can be unblocked later
- const punishmentEntrySuccess = await Moderation.createPunishmentEntry({
+ const punishmentEntrySuccess = await createPunishmentEntry({
client: this.client,
type: 'block',
user: this,
@@ -727,7 +728,7 @@ export class ExtendedGuildMember extends GuildMember {
// dm user
const dmSuccess = options.silent
? null
- : await Moderation.punishDM({
+ : await punishDM({
client: this.client,
punishment: 'blocked',
reason: options.reason ?? undefined,
@@ -793,7 +794,7 @@ export class ExtendedGuildMember extends GuildMember {
if (!blockSuccess) return unblockResponse.ACTION_ERROR;
// add modlog entry
- const { log: modlog } = await Moderation.createModLogEntry({
+ const { log: modlog } = await createModLogEntry({
client: this.client,
type: ModLogType.CHANNEL_UNBLOCK,
user: this,
@@ -807,7 +808,7 @@ export class ExtendedGuildMember extends GuildMember {
caseID = modlog.id;
// remove punishment entry
- const punishmentEntrySuccess = await Moderation.removePunishmentEntry({
+ const punishmentEntrySuccess = await removePunishmentEntry({
client: this.client,
type: 'block',
user: this,
@@ -819,7 +820,7 @@ export class ExtendedGuildMember extends GuildMember {
// dm user
const dmSuccess = options.silent
? null
- : await Moderation.punishDM({
+ : await punishDM({
client: this.client,
punishment: 'unblocked',
reason: options.reason ?? undefined,
@@ -880,7 +881,7 @@ export class ExtendedGuildMember extends GuildMember {
if (!timeoutSuccess) return timeoutResponse.ACTION_ERROR;
// add modlog entry
- const { log: modlog } = await Moderation.createModLogEntry({
+ const { log: modlog } = await createModLogEntry({
client: this.client,
type: ModLogType.TIMEOUT,
user: this,
@@ -942,7 +943,7 @@ export class ExtendedGuildMember extends GuildMember {
if (!timeoutSuccess) return removeTimeoutResponse.ACTION_ERROR;
// add modlog entry
- const { log: modlog } = await Moderation.createModLogEntry({
+ const { log: modlog } = await createModLogEntry({
client: this.client,
type: ModLogType.REMOVE_TIMEOUT,
user: this,