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.ts2
-rw-r--r--lib/extensions/discord.js/ExtendedGuild.ts40
-rw-r--r--lib/extensions/discord.js/ExtendedGuildMember.ts48
-rw-r--r--lib/extensions/discord.js/ExtendedMessage.ts8
-rw-r--r--lib/extensions/discord.js/ExtendedUser.ts2
5 files changed, 53 insertions, 47 deletions
diff --git a/lib/extensions/discord.js/BotClientEvents.ts b/lib/extensions/discord.js/BotClientEvents.ts
index 941a6d8..88f67e9 100644
--- a/lib/extensions/discord.js/BotClientEvents.ts
+++ b/lib/extensions/discord.js/BotClientEvents.ts
@@ -1,4 +1,4 @@
-import type { AkairoClientEvents } from 'discord-akairo';
+import type { AkairoClientEvents } from '@notenoughupdates/discord-akairo';
import type {
ButtonInteraction,
Collection,
diff --git a/lib/extensions/discord.js/ExtendedGuild.ts b/lib/extensions/discord.js/ExtendedGuild.ts
index 6bf81ee..84db7d0 100644
--- a/lib/extensions/discord.js/ExtendedGuild.ts
+++ b/lib/extensions/discord.js/ExtendedGuild.ts
@@ -1,4 +1,5 @@
import {
+ Action,
createModLogEntry,
createModLogEntrySimple,
createPunishmentEntry,
@@ -17,15 +18,16 @@ import {
Guild,
JSONEncodable,
Message,
+ MessageCreateOptions,
MessageType,
PermissionFlagsBits,
SnowflakeUtil,
ThreadChannel,
+ WebhookCreateMessageOptions,
type APIMessage,
type GuildMember,
type GuildMemberResolvable,
type GuildTextBasedChannel,
- type MessageOptions,
type MessagePayload,
type NewsChannel,
type Snowflake,
@@ -33,10 +35,9 @@ import {
type User,
type UserResolvable,
type VoiceChannel,
- type Webhook,
- type WebhookMessageOptions
+ type Webhook
} from 'discord.js';
-import _ from 'lodash';
+import { camelCase } from 'lodash-es';
import { TanzaniteClient } from '../discord-akairo/TanzaniteClient.js';
import { banResponse, BanResponse, dmResponse, permissionsResponse, punishmentEntryRemove } from './ExtendedGuildMember.js';
@@ -91,7 +92,10 @@ interface Extension {
* @param logType The corresponding channel that the message will be sent to
* @param message The parameters for {@link TextChannel.send}
*/
- sendLogChannel(logType: GuildLogType, message: string | MessagePayload | MessageOptions): Promise<Message | null | undefined>;
+ sendLogChannel(
+ logType: GuildLogType,
+ message: string | MessagePayload | MessageCreateOptions
+ ): Promise<Message | null | undefined>;
/**
* Sends a formatted error message in a guild's error log channel
* @param title The title of the error embed
@@ -135,7 +139,7 @@ interface Extension {
declare module 'discord.js' {
export interface BaseGuild {
- client: TanzaniteClient;
+ client: TanzaniteClient<true>;
}
export interface Guild extends AnonymousGuild, Extension {}
@@ -202,7 +206,7 @@ export class ExtendedGuild extends Guild implements Extension {
public override async sendLogChannel(
logType: GuildLogType,
- message: string | MessagePayload | MessageOptions
+ message: string | MessagePayload | MessageCreateOptions
): Promise<Message | null | undefined> {
const logChannel = await this.getLogChannel(logType);
if (!logChannel || !logChannel.isTextBased()) {
@@ -220,7 +224,7 @@ export class ExtendedGuild extends Guild implements Extension {
}
public override async error(title: string, message: string): Promise<void> {
- void this.client.console.info(_.camelCase(title), message.replace(/\*\*(.*?)\*\*/g, '<<$1>>'));
+ void this.client.console.info(camelCase(title), message.replace(/\*\*(.*?)\*\*/g, '<<$1>>'));
void this.sendLogChannel('error', { embeds: [{ title: title, description: message, color: colors.error }] });
}
@@ -240,7 +244,7 @@ export class ExtendedGuild extends Guild implements Extension {
// add modlog entry
const { log: modlog } = await createModLogEntry({
client: this.client,
- type: options.duration ? ModLogType.TEMP_BAN : ModLogType.PERM_BAN,
+ type: options.duration ? ModLogType.TempBan : ModLogType.PermBan,
user: user,
moderator: moderator.id,
reason: options.reason,
@@ -257,7 +261,7 @@ export class ExtendedGuild extends Guild implements Extension {
modlog: modlog.id,
guild: this,
user: user,
- punishment: 'banned',
+ punishment: Action.Ban,
duration: options.duration ?? 0,
reason: options.reason ?? undefined,
sendFooter: true
@@ -309,7 +313,7 @@ export class ExtendedGuild extends Guild implements Extension {
// add modlog entry
const { log: modlog } = await createModLogEntrySimple({
client: this.client,
- type: ModLogType.PERM_BAN,
+ type: ModLogType.PermBan,
user: options.user,
moderator: options.moderator,
reason: options.reason,
@@ -326,7 +330,7 @@ export class ExtendedGuild extends Guild implements Extension {
modlog: modlog.id,
guild: this,
user: options.user,
- punishment: 'banned',
+ punishment: Action.Ban,
duration: 0,
reason: options.reason ?? undefined,
sendFooter: true
@@ -390,7 +394,7 @@ export class ExtendedGuild extends Guild implements Extension {
// add modlog entry
const { log: modlog } = await createModLogEntry({
client: this.client,
- type: ModLogType.UNBAN,
+ type: ModLogType.Unban,
user: user.id,
moderator: moderator.id,
reason: options.reason,
@@ -414,7 +418,7 @@ export class ExtendedGuild extends Guild implements Extension {
client: this.client,
guild: this,
user: user,
- punishment: 'unbanned',
+ punishment: Action.Unban,
reason: options.reason ?? undefined,
sendFooter: false
});
@@ -546,7 +550,7 @@ export class ExtendedGuild extends Guild implements Extension {
if (!webhook) return null;
- const sendOptions: Omit<WebhookMessageOptions, 'flags'> = {};
+ const sendOptions: Omit<WebhookCreateMessageOptions, 'flags'> = {};
const displayName = quote.member?.displayName ?? quote.author.username;
@@ -559,7 +563,7 @@ export class ExtendedGuild extends Guild implements Extension {
sendOptions.content = quote.content || undefined;
sendOptions.threadId = channel instanceof ThreadChannel ? channel.id : undefined;
sendOptions.embeds = quote.embeds.length ? quote.embeds : undefined;
- //@ts-expect-error: jank
+ // @ts-expect-error: jank
sendOptions.attachments = quote.attachments.size
? [...quote.attachments.values()].map((a) => AttachmentBuilder.from(a as JSONEncodable<AttachmentPayload>))
: undefined;
@@ -720,7 +724,9 @@ export class ExtendedGuild extends Guild implements Extension {
}
sendOptions.allowedMentions = AllowedMentions.none();
- sendOptions.username ??= quote.member?.displayName ?? quote.author.username;
+ sendOptions.username ??= (quote.member?.displayName ?? quote.author.username)
+ .replaceAll(/discord/gi, '[REDACTED]')
+ .replaceAll(/clyde/gi, '[REDACTED]');
sendOptions.avatarURL = quote.member?.displayAvatarURL({ size: 2048 }) ?? quote.author.displayAvatarURL({ size: 2048 });
return await webhook.send(sendOptions); /* .catch((e: any) => e); */
diff --git a/lib/extensions/discord.js/ExtendedGuildMember.ts b/lib/extensions/discord.js/ExtendedGuildMember.ts
index 9ef45f1..b11e9e3 100644
--- a/lib/extensions/discord.js/ExtendedGuildMember.ts
+++ b/lib/extensions/discord.js/ExtendedGuildMember.ts
@@ -8,11 +8,11 @@ import {
type Role
} from 'discord.js';
import {
+ Action,
checkMutePermissions,
createModLogEntry,
createPunishmentEntry,
punishDM,
- PunishmentTypeDM,
removePunishmentEntry
} from '../../common/Moderation.js';
import { ModLogType } from '../../models/index.js';
@@ -32,7 +32,7 @@ interface Extension {
* @returns Whether or not the dm was sent successfully.
*/
customPunishDM(
- punishment: PunishmentTypeDM,
+ punishment: Action,
reason?: string | null,
duration?: number,
modlog?: string,
@@ -119,13 +119,13 @@ interface Extension {
declare module 'discord.js' {
export interface GuildMember extends Extension {
- readonly client: TanzaniteClient;
+ readonly client: TanzaniteClient<true>;
}
}
export class ExtendedGuildMember extends GuildMember implements Extension {
public override async customPunishDM(
- punishment: PunishmentTypeDM,
+ punishment: Action,
reason?: string | null,
duration?: number,
modlog?: string,
@@ -154,7 +154,7 @@ export class ExtendedGuildMember extends GuildMember implements Extension {
const result = await createModLogEntry(
{
client: this.client,
- type: ModLogType.WARN,
+ type: ModLogType.Warn,
user: this,
moderator: moderator.id,
reason: options.reason,
@@ -169,7 +169,7 @@ export class ExtendedGuildMember extends GuildMember implements Extension {
if (!options.silent) {
// dm user
- const dmSuccess = await this.customPunishDM('warned', options.reason);
+ const dmSuccess = await this.customPunishDM(Action.Warn, options.reason);
dmSuccessEvent = dmSuccess;
if (!dmSuccess) return { result: warnResponse.DM_ERROR, caseNum: result.caseNum };
}
@@ -195,7 +195,7 @@ export class ExtendedGuildMember extends GuildMember implements Extension {
if (options.addToModlog || options.duration) {
const { log: modlog } = await createModLogEntry({
client: this.client,
- type: options.duration ? ModLogType.TEMP_PUNISHMENT_ROLE : ModLogType.PERM_PUNISHMENT_ROLE,
+ type: options.duration ? ModLogType.TempPunishmentRole : ModLogType.PermPunishmentRole,
guild: this.guild,
moderator: moderator.id,
user: this,
@@ -262,7 +262,7 @@ export class ExtendedGuildMember extends GuildMember implements Extension {
if (options.addToModlog) {
const { log: modlog } = await createModLogEntry({
client: this.client,
- type: ModLogType.REMOVE_PUNISHMENT_ROLE,
+ type: ModLogType.RemovePunishmentRole,
guild: this.guild,
moderator: moderator.id,
user: this,
@@ -362,7 +362,7 @@ export class ExtendedGuildMember extends GuildMember implements Extension {
// add modlog entry
const { log: modlog } = await createModLogEntry({
client: this.client,
- type: options.duration ? ModLogType.TEMP_MUTE : ModLogType.PERM_MUTE,
+ type: options.duration ? ModLogType.TempMute : ModLogType.PermMute,
user: this,
moderator: moderator.id,
reason: options.reason,
@@ -389,7 +389,7 @@ export class ExtendedGuildMember extends GuildMember implements Extension {
if (!options.silent) {
// dm user
- const dmSuccess = await this.customPunishDM('muted', options.reason, options.duration ?? 0, modlog.id);
+ const dmSuccess = await this.customPunishDM(Action.Mute, options.reason, options.duration ?? 0, modlog.id);
dmSuccessEvent = dmSuccess;
if (!dmSuccess) return muteResponse.DM_ERROR;
}
@@ -441,7 +441,7 @@ export class ExtendedGuildMember extends GuildMember implements Extension {
// add modlog entry
const { log: modlog } = await createModLogEntry({
client: this.client,
- type: ModLogType.UNMUTE,
+ type: ModLogType.Unmute,
user: this,
moderator: moderator.id,
reason: options.reason,
@@ -465,7 +465,7 @@ export class ExtendedGuildMember extends GuildMember implements Extension {
if (!options.silent) {
// dm user
- const dmSuccess = await this.customPunishDM('unmuted', options.reason, undefined, '', false);
+ const dmSuccess = await this.customPunishDM(Action.Unmute, options.reason, undefined, '', false);
dmSuccessEvent = dmSuccess;
if (!dmSuccess) return unmuteResponse.DM_ERROR;
}
@@ -505,7 +505,7 @@ export class ExtendedGuildMember extends GuildMember implements Extension {
// add modlog entry
const { log: modlog } = await createModLogEntry({
client: this.client,
- type: ModLogType.KICK,
+ type: ModLogType.Kick,
user: this,
moderator: moderator.id,
reason: options.reason,
@@ -517,7 +517,7 @@ export class ExtendedGuildMember extends GuildMember implements Extension {
caseID = modlog.id;
// dm user
- const dmSuccess = options.silent ? null : await this.customPunishDM('kicked', options.reason, undefined, modlog.id);
+ const dmSuccess = options.silent ? null : await this.customPunishDM(Action.Kick, options.reason, undefined, modlog.id);
dmSuccessEvent = dmSuccess ?? undefined;
// kick
@@ -564,7 +564,7 @@ export class ExtendedGuildMember extends GuildMember implements Extension {
// add modlog entry
const { log: modlog } = await createModLogEntry({
client: this.client,
- type: options.duration ? ModLogType.TEMP_BAN : ModLogType.PERM_BAN,
+ type: options.duration ? ModLogType.TempBan : ModLogType.PermBan,
user: this,
moderator: moderator.id,
reason: options.reason,
@@ -579,7 +579,7 @@ export class ExtendedGuildMember extends GuildMember implements Extension {
// dm user
const dmSuccess = options.silent
? null
- : await this.customPunishDM('banned', options.reason, options.duration ?? 0, modlog.id);
+ : await this.customPunishDM(Action.Ban, options.reason, options.duration ?? 0, modlog.id);
dmSuccessEvent = dmSuccess ?? undefined;
// ban
@@ -646,7 +646,7 @@ export class ExtendedGuildMember extends GuildMember implements Extension {
// add modlog entry
const { log: modlog } = await createModLogEntry({
client: this.client,
- type: options.duration ? ModLogType.TEMP_CHANNEL_BLOCK : ModLogType.PERM_CHANNEL_BLOCK,
+ type: options.duration ? ModLogType.TempChannelBlock : ModLogType.PermChannelBlock,
user: this,
moderator: moderator.id,
reason: options.reason,
@@ -674,7 +674,7 @@ export class ExtendedGuildMember extends GuildMember implements Extension {
? null
: await punishDM({
client: this.client,
- punishment: 'blocked',
+ punishment: Action.Block,
reason: options.reason ?? undefined,
duration: options.duration ?? 0,
modlog: modlog.id,
@@ -736,7 +736,7 @@ export class ExtendedGuildMember extends GuildMember implements Extension {
// add modlog entry
const { log: modlog } = await createModLogEntry({
client: this.client,
- type: ModLogType.CHANNEL_UNBLOCK,
+ type: ModLogType.ChannelUnblock,
user: this,
moderator: moderator.id,
reason: options.reason,
@@ -762,7 +762,7 @@ export class ExtendedGuildMember extends GuildMember implements Extension {
? null
: await punishDM({
client: this.client,
- punishment: 'unblocked',
+ punishment: Action.Unblock,
reason: options.reason ?? undefined,
guild: this.guild,
user: this,
@@ -819,7 +819,7 @@ export class ExtendedGuildMember extends GuildMember implements Extension {
// add modlog entry
const { log: modlog } = await createModLogEntry({
client: this.client,
- type: ModLogType.TIMEOUT,
+ type: ModLogType.Timeout,
user: this,
moderator: moderator.id,
reason: options.reason,
@@ -834,7 +834,7 @@ export class ExtendedGuildMember extends GuildMember implements Extension {
if (!options.silent) {
// dm user
- const dmSuccess = await this.customPunishDM('timedout', options.reason, options.duration, modlog.id);
+ const dmSuccess = await this.customPunishDM(Action.Timeout, options.reason, options.duration, modlog.id);
dmSuccessEvent = dmSuccess;
if (!dmSuccess) return timeoutResponse.DM_ERROR;
}
@@ -877,7 +877,7 @@ export class ExtendedGuildMember extends GuildMember implements Extension {
// add modlog entry
const { log: modlog } = await createModLogEntry({
client: this.client,
- type: ModLogType.REMOVE_TIMEOUT,
+ type: ModLogType.RemoveTimeout,
user: this,
moderator: moderator.id,
reason: options.reason,
@@ -891,7 +891,7 @@ export class ExtendedGuildMember extends GuildMember implements Extension {
if (!options.silent) {
// dm user
- const dmSuccess = await this.customPunishDM('untimedout', options.reason, undefined, '', false);
+ const dmSuccess = await this.customPunishDM(Action.Untimeout, options.reason, undefined, '', false);
dmSuccessEvent = dmSuccess;
if (!dmSuccess) return removeTimeoutResponse.DM_ERROR;
}
diff --git a/lib/extensions/discord.js/ExtendedMessage.ts b/lib/extensions/discord.js/ExtendedMessage.ts
index 1bb0904..07cba3d 100644
--- a/lib/extensions/discord.js/ExtendedMessage.ts
+++ b/lib/extensions/discord.js/ExtendedMessage.ts
@@ -1,11 +1,11 @@
-import { CommandUtil } from 'discord-akairo';
+import { CommandUtil } from '@notenoughupdates/discord-akairo';
import { Message, type Client } from 'discord.js';
import type { RawMessageData } from 'discord.js/typings/rawDataTypes.js';
-export class ExtendedMessage<Cached extends boolean = boolean> extends Message<Cached> {
- public declare util: CommandUtil<Message>;
+export class ExtendedMessage<InGuild extends boolean = boolean> extends Message<InGuild> {
+ public declare util: CommandUtil<Message<InGuild>>;
- public constructor(client: Client, data: RawMessageData) {
+ public constructor(client: Client<true>, data: RawMessageData) {
super(client, data);
this.util = new CommandUtil(client.commandHandler, this);
}
diff --git a/lib/extensions/discord.js/ExtendedUser.ts b/lib/extensions/discord.js/ExtendedUser.ts
index 7846a70..8f9d27b 100644
--- a/lib/extensions/discord.js/ExtendedUser.ts
+++ b/lib/extensions/discord.js/ExtendedUser.ts
@@ -14,7 +14,7 @@ interface Extension {
declare module 'discord.js' {
export interface User extends Extension {
- readonly client: TanzaniteClient;
+ readonly client: TanzaniteClient<true>;
}
}