diff options
Diffstat (limited to 'src/listeners')
52 files changed, 173 insertions, 150 deletions
diff --git a/src/listeners/bush/appealListener.ts b/src/listeners/bush/appealListener.ts index 06eb245..b62031d 100644 --- a/src/listeners/bush/appealListener.ts +++ b/src/listeners/bush/appealListener.ts @@ -1,4 +1,3 @@ -/* eslint-disable no-control-regex */ import { BushListener, colors, mappings, ModLog, type BushClientEvents } from '#lib'; import assert from 'assert'; import { EmbedBuilder } from 'discord.js'; @@ -15,7 +14,7 @@ export default class AppealListener extends BushListener { } public async exec(...[message]: BushClientEvents['messageCreate']): Promise<any> { - if (!client.config.isProduction || !message.inGuild() || message.guildId !== mappings.guilds.bush) return; + if (!this.client.config.isProduction || !message.inGuild() || message.guildId !== mappings.guilds.bush) return; if (message.author.id !== '855446927688335370' || message.embeds.length < 1) return; const userId = message.embeds[0].fields?.find?.((f) => f.name === 'What is your discord ID?')?.value; @@ -26,7 +25,7 @@ export default class AppealListener extends BushListener { name: `${message.embeds[0].fields.find((f) => f.name === 'What type of punishment are you appealing?')?.value} appeal` }); - const user = await client.users.fetch(userId, { force: true }).catch(() => null); + const user = await this.client.users.fetch(userId, { force: true }).catch(() => null); if (!user) return await thread.send({ embeds: [ diff --git a/src/listeners/bush/joinAutoBan.ts b/src/listeners/bush/joinAutoBan.ts index eae18d3..082a925 100644 --- a/src/listeners/bush/joinAutoBan.ts +++ b/src/listeners/bush/joinAutoBan.ts @@ -1,4 +1,4 @@ -import { AllowedMentions, BushListener, colors, emojis, format, getShared, mappings, type BushClientEvents } from '#lib'; +import { AllowedMentions, BushListener, colors, emojis, format, mappings, type BushClientEvents } from '#lib'; import { TextChannel } from 'discord.js'; export default class JoinAutoBanListener extends BushListener { @@ -11,13 +11,13 @@ export default class JoinAutoBanListener extends BushListener { } public async exec(...[member]: BushClientEvents['guildMemberAdd']): Promise<void> { - if (!client.config.isProduction) return; + if (!this.client.config.isProduction) return; if (member.guild.id !== mappings.guilds.bush) return; const guild = member.guild; // eslint-disable-next-line @typescript-eslint/no-unused-vars const user = member.user; - const code = getShared('autoBanCode'); + const code = this.client.utils.getShared('autoBanCode'); if (!code) return; if (eval(code)) { const res = await member.bushBan({ diff --git a/src/listeners/bush/supportThread.ts b/src/listeners/bush/supportThread.ts index 3651409..1dadecb 100644 --- a/src/listeners/bush/supportThread.ts +++ b/src/listeners/bush/supportThread.ts @@ -13,7 +13,7 @@ export default class SupportThreadListener extends BushListener { } public async exec(...[message]: BushClientEvents['messageCreate']): Promise<void | undefined> { - if (!client.config.isProduction || !message.inGuild()) return; + if (!this.client.config.isProduction || !message.inGuild()) return; if (![MessageType.Default, MessageType.Reply].includes(message.type)) return; if (message.thread) return; if (message.author.bot && (message.author.id !== '444871677176709141' || !message.content.includes('uploaded a log,'))) @@ -23,10 +23,10 @@ export default class SupportThreadListener extends BushListener { if (message.channel.id !== '714332750156660756') return; // neu-support if ( - [await message.guild.getSetting('prefix'), `<@!${client.user!.id}>`, `<@${client.user!.id}>`].some((v) => + [await message.guild.getSetting('prefix'), `<@!${this.client.user!.id}>`, `<@${this.client.user!.id}>`].some((v) => message.content.trim().startsWith(v) ) && - client.commandHandler.aliases.some((alias) => message.content.includes(alias)) + this.client.commandHandler.aliases.some((alias) => message.content.includes(alias)) ) return; @@ -54,7 +54,7 @@ export default class SupportThreadListener extends BushListener { void thread .send({ embeds: [embed] }) .then(() => - client.console.info( + this.client.console.info( 'supportThread', `opened a support thread for <<${message.author.tag}>> in <<${message.channel.name}>> in <<${message.guild!.name}>>.` ) diff --git a/src/listeners/bush/userUpdateAutoBan.ts b/src/listeners/bush/userUpdateAutoBan.ts index 07381e0..54051b2 100644 --- a/src/listeners/bush/userUpdateAutoBan.ts +++ b/src/listeners/bush/userUpdateAutoBan.ts @@ -1,4 +1,4 @@ -import { AllowedMentions, BushListener, colors, emojis, format, getShared, mappings, type BushClientEvents } from '#lib'; +import { AllowedMentions, BushListener, colors, emojis, format, mappings, type BushClientEvents } from '#lib'; import { GuildMember, type TextChannel } from 'discord.js'; export default class UserUpdateAutoBanListener extends BushListener { @@ -11,14 +11,14 @@ export default class UserUpdateAutoBanListener extends BushListener { } public async exec(...[_oldUser, newUser]: BushClientEvents['userUpdate']): Promise<void> { - if (!client.config.isProduction) return; + if (!this.client.config.isProduction) return; // eslint-disable-next-line @typescript-eslint/no-unused-vars const user = newUser; - const code = getShared('autoBanCode'); + const code = this.client.utils.getShared('autoBanCode'); if (!code) return; if (eval(code)) { - const member = await client.guilds.cache + const member = await this.client.guilds.cache .get(mappings.guilds.bush) ?.members.fetch(newUser.id) .catch(() => undefined); diff --git a/src/listeners/client/akairoDebug.ts b/src/listeners/client/akairoDebug.ts index 208e289..3fa7977 100644 --- a/src/listeners/client/akairoDebug.ts +++ b/src/listeners/client/akairoDebug.ts @@ -11,7 +11,7 @@ export default class DiscordJsDebugListener extends BushListener { public async exec(...[message, ...other]: BushClientEvents['debug']): Promise<void> { if (other.length && !message.includes('[registerInteractionCommands]')) - void client.console.superVerboseRaw('akairoDebug', message, ...other); - else void client.console.superVerbose('akairoDebug', message); + void this.client.console.superVerboseRaw('akairoDebug', message, ...other); + else void this.client.console.superVerbose('akairoDebug', message); } } diff --git a/src/listeners/client/dcjsDebug.ts b/src/listeners/client/dcjsDebug.ts index 56a9eab..4b80c65 100644 --- a/src/listeners/client/dcjsDebug.ts +++ b/src/listeners/client/dcjsDebug.ts @@ -10,6 +10,6 @@ export default class DiscordJsDebugListener extends BushListener { } public async exec(...[message]: BushClientEvents['debug']): Promise<void> { - void client.console.superVerbose('dc.js-debug', message); + void this.client.console.superVerbose('dc.js-debug', message); } } diff --git a/src/listeners/client/dcjsError.ts b/src/listeners/client/dcjsError.ts index c3cf8f0..a39a92d 100644 --- a/src/listeners/client/dcjsError.ts +++ b/src/listeners/client/dcjsError.ts @@ -10,6 +10,6 @@ export default class DiscordJsErrorListener extends BushListener { } public async exec(...[error]: BushClientEvents['error']): Promise<void> { - void client.console.superVerbose('dc.js-error', error); + void this.client.console.superVerbose('dc.js-error', error); } } diff --git a/src/listeners/client/dcjsWarn.ts b/src/listeners/client/dcjsWarn.ts index 6c13630..b187f0c 100644 --- a/src/listeners/client/dcjsWarn.ts +++ b/src/listeners/client/dcjsWarn.ts @@ -10,6 +10,6 @@ export default class DiscordJsWarnListener extends BushListener { } public async exec(...[message]: BushClientEvents['warn']): Promise<void> { - void client.console.superVerbose('dc.js-warn', message); + void this.client.console.superVerbose('dc.js-warn', message); } } diff --git a/src/listeners/client/ready.ts b/src/listeners/client/ready.ts index ae9919c..a6a289c 100644 --- a/src/listeners/client/ready.ts +++ b/src/listeners/client/ready.ts @@ -14,22 +14,22 @@ export default class ReadyListener extends BushListener { public async exec(...[]: BushClientEvents['ready']) { process.emit('ready' as any); - const tag = `<<${client.user?.tag}>>`, - guildCount = `<<${client.guilds.cache.size.toLocaleString()}>>`, - userCount = `<<${client.users.cache.size.toLocaleString()}>>`; + const tag = `<<${this.client.user?.tag}>>`, + guildCount = `<<${this.client.guilds.cache.size.toLocaleString()}>>`, + userCount = `<<${this.client.users.cache.size.toLocaleString()}>>`; - void client.logger.success('ready', `Logged in to ${tag} serving ${guildCount} guilds and ${userCount} users.`); + void this.client.logger.success('ready', `Logged in to ${tag} serving ${guildCount} guilds and ${userCount} users.`); console.log( chalk.blue( `------------------------------------------------------------------------------${ - client.config.isDevelopment ? '---' : client.config.isBeta ? '----' : '' + this.client.config.isDevelopment ? '---' : this.client.config.isBeta ? '----' : '' }` ) ); const guilds = await Guild.findAll(); const needToCreate = []; - for (const [, guild] of client.guilds.cache) { + for (const [, guild] of this.client.guilds.cache) { const find = guilds.find((g) => guild.id === g.id); if (!find) needToCreate.push(guild.id); } diff --git a/src/listeners/commands/commandBlocked.ts b/src/listeners/commands/commandBlocked.ts index 8a05d39..e9d1394 100644 --- a/src/listeners/commands/commandBlocked.ts +++ b/src/listeners/commands/commandBlocked.ts @@ -9,7 +9,7 @@ import { type CommandMessage, type SlashMessage } from '#lib'; -import { type InteractionReplyOptions, type MessagePayload, type ReplyMessageOptions } from 'discord.js'; +import { type Client, type InteractionReplyOptions, type MessagePayload, type ReplyMessageOptions } from 'discord.js'; export default class CommandBlockedListener extends BushListener { public constructor() { @@ -21,10 +21,15 @@ export default class CommandBlockedListener extends BushListener { } public async exec(...[message, command, reason]: BushCommandHandlerEvents['commandBlocked']) { - return await CommandBlockedListener.handleBlocked(message, command, reason); + return await CommandBlockedListener.handleBlocked(this.client, message, command, reason); } - public static async handleBlocked(message: CommandMessage | SlashMessage, command: BushCommand | null, reason?: string) { + public static async handleBlocked( + client: Client, + message: CommandMessage | SlashMessage, + command: BushCommand | null, + reason?: string + ) { const isSlash = !!command && !!message.util?.isSlash; void client.console.info( diff --git a/src/listeners/commands/commandCooldown.ts b/src/listeners/commands/commandCooldown.ts index 74dd4eb..5f4d70e 100644 --- a/src/listeners/commands/commandCooldown.ts +++ b/src/listeners/commands/commandCooldown.ts @@ -10,7 +10,7 @@ export default class CommandCooldownListener extends BushListener { } public async exec(...[message, command, remaining]: BushCommandHandlerEvents['cooldown']) { - void client.console.info( + void this.client.console.info( 'commandCooldown', `<<${message.author.tag}>> tried to run <<${ command ?? message.util!.parsed?.command diff --git a/src/listeners/commands/commandError.ts b/src/listeners/commands/commandError.ts index ca6565e..04ea517 100644 --- a/src/listeners/commands/commandError.ts +++ b/src/listeners/commands/commandError.ts @@ -1,16 +1,6 @@ -import { - capitalize, - colors, - format, - formatError, - inspectAndRedact, - inspectCleanRedactCodeblock, - inspectCleanRedactHaste, - SlashMessage, - type BushCommandHandlerEvents -} from '#lib'; +import { capitalize, colors, format, formatError, SlashMessage, type BushCommandHandlerEvents } from '#lib'; import { type AkairoMessage, type Command } from 'discord-akairo'; -import { ChannelType, EmbedBuilder, escapeInlineCode, Formatters, GuildTextBasedChannel, type Message } from 'discord.js'; +import { ChannelType, Client, EmbedBuilder, escapeInlineCode, Formatters, GuildTextBasedChannel, type Message } from 'discord.js'; import { BushListener } from '../../lib/extensions/discord-akairo/BushListener.js'; export default class CommandErrorListener extends BushListener { @@ -23,10 +13,11 @@ export default class CommandErrorListener extends BushListener { } public exec(...[error, message, command]: BushCommandHandlerEvents['error']) { - return CommandErrorListener.handleError(error, message, command); + return CommandErrorListener.handleError(this.client, error, message, command); } public static async handleError( + client: Client, ...[error, message, _command]: BushCommandHandlerEvents['error'] | BushCommandHandlerEvents['slashError'] ) { try { @@ -63,8 +54,8 @@ export default class CommandErrorListener extends BushListener { false ); - const _haste = CommandErrorListener.getErrorHaste(error); - const _stack = CommandErrorListener.getErrorStack(error); + const _haste = CommandErrorListener.getErrorHaste(client, error); + const _stack = CommandErrorListener.getErrorStack(client, error); const [haste, stack] = await Promise.all([_haste, _stack]); const options = { message, error, isSlash, errorNum, command, channel, haste, stack }; @@ -97,6 +88,7 @@ export default class CommandErrorListener extends BushListener { } public static async generateErrorEmbed( + client: Client, options: | { message: Message | AkairoMessage; @@ -109,8 +101,8 @@ export default class CommandErrorListener extends BushListener { } | { error: Error | any; type: 'uncaughtException' | 'unhandledRejection'; context?: string } ): Promise<EmbedBuilder[]> { - const _haste = CommandErrorListener.getErrorHaste(options.error); - const _stack = CommandErrorListener.getErrorStack(options.error); + const _haste = CommandErrorListener.getErrorHaste(client, options.error); + const _stack = CommandErrorListener.getErrorStack(client, options.error); const [haste, stack] = await Promise.all([_haste, _stack]); return CommandErrorListener._generateErrorEmbed({ ...options, haste, stack }); @@ -179,7 +171,7 @@ export default class CommandErrorListener extends BushListener { return embeds; } - public static async getErrorHaste(error: Error | any): Promise<string[]> { + public static async getErrorHaste(client: Client, error: Error | any): Promise<string[]> { const inspectOptions = { showHidden: false, depth: 9, @@ -209,7 +201,7 @@ export default class CommandErrorListener extends BushListener { for (const element in error) { if (['stack', 'name', 'message'].includes(element)) continue; else if (typeof (error as any)[element] === 'object') { - promises.push(inspectCleanRedactHaste((error as any)[element], inspectOptions)); + promises.push(client.utils.inspectCleanRedactHaste((error as any)[element], inspectOptions)); } } @@ -235,7 +227,7 @@ export default class CommandErrorListener extends BushListener { ? `[haste](${pair[element].url})${pair[element].error ? ` - ${pair[element].error}` : ''}` : pair[element].error }` - : `\`${escapeInlineCode(inspectAndRedact((error as any)[element], inspectOptions))}\`` + : `\`${escapeInlineCode(client.utils.inspectAndRedact((error as any)[element], inspectOptions))}\`` }` ); } @@ -243,8 +235,8 @@ export default class CommandErrorListener extends BushListener { return ret; } - public static async getErrorStack(error: Error | any): Promise<string> { - return await inspectCleanRedactCodeblock(error, 'js', { colors: false }, 4000); + public static async getErrorStack(client: Client, error: Error | any): Promise<string> { + return await client.utils.inspectCleanRedactCodeblock(error, 'js', { colors: false }, 4000); } } diff --git a/src/listeners/commands/commandMissingPermissions.ts b/src/listeners/commands/commandMissingPermissions.ts index 352899d..4d39264 100644 --- a/src/listeners/commands/commandMissingPermissions.ts +++ b/src/listeners/commands/commandMissingPermissions.ts @@ -1,5 +1,5 @@ import { BushListener, emojis, format, mappings, oxford, surroundArray, type BushCommandHandlerEvents } from '#lib'; -import { type PermissionsString } from 'discord.js'; +import { Client, type PermissionsString } from 'discord.js'; export default class CommandMissingPermissionsListener extends BushListener { public constructor() { @@ -11,10 +11,11 @@ export default class CommandMissingPermissionsListener extends BushListener { } public async exec(...[message, command, type, missing]: BushCommandHandlerEvents['missingPermissions']) { - return await CommandMissingPermissionsListener.handleMissing(message, command, type, missing); + return await CommandMissingPermissionsListener.handleMissing(this.client, message, command, type, missing); } public static async handleMissing( + client: Client, ...[message, command, type, missing]: | BushCommandHandlerEvents['missingPermissions'] | BushCommandHandlerEvents['slashMissingPermissions'] diff --git a/src/listeners/commands/commandStarted.ts b/src/listeners/commands/commandStarted.ts index 89fea28..9d0e4cb 100644 --- a/src/listeners/commands/commandStarted.ts +++ b/src/listeners/commands/commandStarted.ts @@ -11,7 +11,7 @@ export default class CommandStartedListener extends BushListener { } public exec(...[message, command]: BushCommandHandlerEvents['commandStarted']): void { - client.sentry.addBreadcrumb({ + this.client.sentry.addBreadcrumb({ message: `[commandStarted] The ${command.id} was started by ${message.author.tag}.`, level: 'info', timestamp: Date.now(), @@ -25,11 +25,11 @@ export default class CommandStartedListener extends BushListener { (message.channel.isDMBased() ? message.channel.recipient?.tag : (<any>message.channel)?.name) ?? '¯\\_(ツ)_/¯', 'guild.id': message.guild?.id ?? '¯\\_(ツ)_/¯', 'guild.name': message.guild?.name ?? '¯\\_(ツ)_/¯', - 'environment': client.config.environment + 'environment': this.client.config.environment } }); - void client.logger.info( + void this.client.logger.info( 'commandStarted', `The <<${command.id}>> command was used by <<${message.author.tag}>> in ${ message.channel.type === ChannelType.DM ? `their <<DMs>>` : `<<#${message.channel.name}>> in <<${message.guild?.name}>>` @@ -37,6 +37,6 @@ export default class CommandStartedListener extends BushListener { true ); - client.stats.commandsUsed = client.stats.commandsUsed + 1n; + this.client.stats.commandsUsed = this.client.stats.commandsUsed + 1n; } } diff --git a/src/listeners/commands/messageBlocked.ts b/src/listeners/commands/messageBlocked.ts index 997579c..d73cff1 100644 --- a/src/listeners/commands/messageBlocked.ts +++ b/src/listeners/commands/messageBlocked.ts @@ -12,6 +12,9 @@ export default class MessageBlockedListener extends BushListener { public async exec(...[message, reason]: BushCommandHandlerEvents['messageBlocked']) { if (['client', 'bot'].includes(reason)) return; // return await CommandBlockedListener.handleBlocked(message as Message, null, reason); - return void client.console.verbose(`messageBlocked`, `<<${message.author.tag}>>'s message was blocked because ${reason}`); + return void this.client.console.verbose( + `messageBlocked`, + `<<${message.author.tag}>>'s message was blocked because ${reason}` + ); } } diff --git a/src/listeners/commands/slashBlocked.ts b/src/listeners/commands/slashBlocked.ts index 915b953..c877708 100644 --- a/src/listeners/commands/slashBlocked.ts +++ b/src/listeners/commands/slashBlocked.ts @@ -11,6 +11,6 @@ export default class SlashBlockedListener extends BushListener { } public async exec(...[message, command, reason]: BushCommandHandlerEvents['slashBlocked']) { - return await CommandBlockedListener.handleBlocked(message, command, reason); + return await CommandBlockedListener.handleBlocked(this.client, message, command, reason); } } diff --git a/src/listeners/commands/slashCommandError.ts b/src/listeners/commands/slashCommandError.ts index f851f4f..7c0d52c 100644 --- a/src/listeners/commands/slashCommandError.ts +++ b/src/listeners/commands/slashCommandError.ts @@ -11,6 +11,6 @@ export default class SlashCommandErrorListener extends BushListener { } public async exec(...[error, message, command]: BushCommandHandlerEvents['slashError']) { - return await CommandErrorListener.handleError(error, message, command); + return await CommandErrorListener.handleError(this.client, error, message, command); } } diff --git a/src/listeners/commands/slashMissingPermissions.ts b/src/listeners/commands/slashMissingPermissions.ts index 3ae03e3..0a1383b 100644 --- a/src/listeners/commands/slashMissingPermissions.ts +++ b/src/listeners/commands/slashMissingPermissions.ts @@ -11,6 +11,6 @@ export default class SlashMissingPermissionsListener extends BushListener { } public async exec(...[message, command, type, missing]: BushCommandHandlerEvents['slashMissingPermissions']) { - return await CommandMissingPermissionsListener.handleMissing(message, command, type, missing); + return await CommandMissingPermissionsListener.handleMissing(this.client, message, command, type, missing); } } diff --git a/src/listeners/commands/slashNotFound.ts b/src/listeners/commands/slashNotFound.ts index 8c6d2d4..cc14969 100644 --- a/src/listeners/commands/slashNotFound.ts +++ b/src/listeners/commands/slashNotFound.ts @@ -10,6 +10,6 @@ export default class SlashNotFoundListener extends BushListener { } public async exec(...[interaction]: BushCommandHandlerEvents['slashNotFound']) { - void client.console.info('slashNotFound', `<<${interaction?.commandName}>> could not be found.`); + void this.client.console.info('slashNotFound', `<<${interaction?.commandName}>> could not be found.`); } } diff --git a/src/listeners/commands/slashStarted.ts b/src/listeners/commands/slashStarted.ts index e2c8a47..400920f 100644 --- a/src/listeners/commands/slashStarted.ts +++ b/src/listeners/commands/slashStarted.ts @@ -11,7 +11,7 @@ export default class SlashStartedListener extends BushListener { } public async exec(...[message, command]: BushCommandHandlerEvents['slashStarted']) { - client.sentry.addBreadcrumb({ + this.client.sentry.addBreadcrumb({ message: `[slashStarted] The ${command.id} was started by ${message.author.tag}.`, level: 'info', timestamp: Date.now(), @@ -25,11 +25,11 @@ export default class SlashStartedListener extends BushListener { (message.channel?.isDMBased() ? message.channel.recipient?.tag : (<any>message.channel)?.name) ?? '¯\\_(ツ)_/¯', 'guild.id': message.guild?.id ?? '¯\\_(ツ)_/¯', 'guild.name': message.guild?.name ?? '¯\\_(ツ)_/¯', - 'environment': client.config.environment + 'environment': this.client.config.environment } }); - void client.logger.info( + void this.client.logger.info( 'slashStarted', `The <<${command.id}>> command was used by <<${message.author.tag}>> in ${ message.channel @@ -41,6 +41,6 @@ export default class SlashStartedListener extends BushListener { true ); - client.stats.commandsUsed = client.stats.commandsUsed + 1n; + this.client.stats.commandsUsed = this.client.stats.commandsUsed + 1n; } } diff --git a/src/listeners/contextCommands/contextCommandBlocked.ts b/src/listeners/contextCommands/contextCommandBlocked.ts index a9397b6..bb237a0 100644 --- a/src/listeners/contextCommands/contextCommandBlocked.ts +++ b/src/listeners/contextCommands/contextCommandBlocked.ts @@ -11,7 +11,7 @@ export default class ContextCommandBlockedListener extends BushListener { } public async exec(...[interaction, command, reason]: ContextMenuCommandHandlerEvents['blocked']) { - void client.console.info( + void this.client.console.info( `ContextCommandBlocked`, `<<${interaction.user.tag}>> tried to run <<${command}>> but was blocked because <<${reason}>>.`, true diff --git a/src/listeners/contextCommands/contextCommandError.ts b/src/listeners/contextCommands/contextCommandError.ts index e69ed4e..4b1ea52 100644 --- a/src/listeners/contextCommands/contextCommandError.ts +++ b/src/listeners/contextCommands/contextCommandError.ts @@ -1,6 +1,6 @@ import { BushListener, colors, format, formatError } from '#lib'; import { type ContextMenuCommand, type ContextMenuCommandHandlerEvents } from 'discord-akairo'; -import { ChannelType, ContextMenuCommandInteraction, EmbedBuilder, GuildTextBasedChannel } from 'discord.js'; +import { ChannelType, Client, ContextMenuCommandInteraction, EmbedBuilder, GuildTextBasedChannel } from 'discord.js'; import CommandErrorListener, { IFuckedUpError } from '../commands/commandError.js'; export default class ContextCommandErrorListener extends BushListener { @@ -13,10 +13,10 @@ export default class ContextCommandErrorListener extends BushListener { } public exec(...[error, interaction, command]: ContextMenuCommandHandlerEvents['error']) { - return ContextCommandErrorListener.handleError(error, interaction, command); + return ContextCommandErrorListener.handleError(this.client, error, interaction, command); } - public static async handleError(...[error, interaction, command]: ContextMenuCommandHandlerEvents['error']) { + public static async handleError(client: Client, ...[error, interaction, command]: ContextMenuCommandHandlerEvents['error']) { try { const errorNum = Math.floor(Math.random() * 6969696969) + 69; // hehe funny number const channel = @@ -49,8 +49,8 @@ export default class ContextCommandErrorListener extends BushListener { false ); - const _haste = CommandErrorListener.getErrorHaste(error); - const _stack = CommandErrorListener.getErrorStack(error); + const _haste = CommandErrorListener.getErrorHaste(client, error); + const _stack = CommandErrorListener.getErrorStack(client, error); const [haste, stack] = await Promise.all([_haste, _stack]); const options = { interaction, error, errorNum, command, channel, haste, stack }; diff --git a/src/listeners/contextCommands/contextCommandNotFound.ts b/src/listeners/contextCommands/contextCommandNotFound.ts index 65954a2..f5097f3 100644 --- a/src/listeners/contextCommands/contextCommandNotFound.ts +++ b/src/listeners/contextCommands/contextCommandNotFound.ts @@ -11,6 +11,6 @@ export default class ContextCommandNotFoundListener extends BushListener { } public async exec(...[interaction]: ContextMenuCommandHandlerEvents['notFound']) { - void client.console.info('contextCommandNotFound', `<<${interaction?.commandName}>> could not be found.`); + void this.client.console.info('contextCommandNotFound', `<<${interaction?.commandName}>> could not be found.`); } } diff --git a/src/listeners/contextCommands/contextCommandStarted.ts b/src/listeners/contextCommands/contextCommandStarted.ts index 3aab07a..2d1e9ef 100644 --- a/src/listeners/contextCommands/contextCommandStarted.ts +++ b/src/listeners/contextCommands/contextCommandStarted.ts @@ -12,7 +12,7 @@ export default class ContextCommandStartedListener extends BushListener { } public async exec(...[interaction, command]: ContextMenuCommandHandlerEvents['started']) { - client.sentry.addBreadcrumb({ + this.client.sentry.addBreadcrumb({ message: `[contextCommandStarted] The ${command.id} was started by ${interaction.user.tag}.`, level: 'info', timestamp: Date.now(), @@ -28,11 +28,11 @@ export default class ContextCommandStartedListener extends BushListener { '¯\\_(ツ)_/¯', 'guild.id': interaction.guild?.id ?? '¯\\_(ツ)_/¯', 'guild.name': interaction.guild?.name ?? '¯\\_(ツ)_/¯', - 'environment': client.config.environment + 'environment': this.client.config.environment } }); - return void client.logger.info( + return void this.client.logger.info( 'contextCommandStarted', `The <<${command.id}>> command was used by <<${interaction.user.tag}>> in ${ interaction.channel diff --git a/src/listeners/guild/guildCreate.ts b/src/listeners/guild/guildCreate.ts index fe23979..9f5f56c 100644 --- a/src/listeners/guild/guildCreate.ts +++ b/src/listeners/guild/guildCreate.ts @@ -1,4 +1,4 @@ -import { BushListener, colors, emojis, format, getConfigChannel, Guild, type BushClientEvents } from '#lib'; +import { BushListener, colors, emojis, format, Guild, type BushClientEvents } from '#lib'; export default class GuildCreateListener extends BushListener { public constructor() { @@ -10,11 +10,14 @@ export default class GuildCreateListener extends BushListener { } public async exec(...[guild]: BushClientEvents['guildCreate']) { - void client.console.info('guildCreate', `Joined <<${guild.name}>> with <<${guild.memberCount?.toLocaleString()}>> members.`); + void this.client.console.info( + 'guildCreate', + `Joined <<${guild.name}>> with <<${guild.memberCount?.toLocaleString()}>> members.` + ); const g = await Guild.findByPk(guild.id); if (!g) void Guild.create({ id: guild.id }); - const channel = await getConfigChannel('servers'); + const channel = await this.client.utils.getConfigChannel('servers'); if (!channel) return; return await channel.send({ embeds: [ @@ -22,7 +25,7 @@ export default class GuildCreateListener extends BushListener { color: colors.Green, description: `${emojis.join} Joined ${format.input( guild.name - )} with **${guild.memberCount?.toLocaleString()}** members. I am now in **${client.guilds.cache.size}** guilds.`, + )} with **${guild.memberCount?.toLocaleString()}** members. I am now in **${this.client.guilds.cache.size}** guilds.`, timestamp: new Date().toISOString(), footer: { text: `${guild.id}`, icon_url: guild.iconURL() ?? undefined } } diff --git a/src/listeners/guild/guildDelete.ts b/src/listeners/guild/guildDelete.ts index 5efbe9b..62d98e3 100644 --- a/src/listeners/guild/guildDelete.ts +++ b/src/listeners/guild/guildDelete.ts @@ -1,4 +1,4 @@ -import { BushListener, colors, emojis, format, getConfigChannel, type BushClientEvents } from '#lib'; +import { BushListener, colors, emojis, format, type BushClientEvents } from '#lib'; export default class GuildDeleteListener extends BushListener { public constructor() { @@ -10,9 +10,12 @@ export default class GuildDeleteListener extends BushListener { } public async exec(...[guild]: BushClientEvents['guildDelete']) { - void client.console.info('guildDelete', `Left <<${guild.name}>> with <<${guild.memberCount?.toLocaleString()}>> members.`); + void this.client.console.info( + 'guildDelete', + `Left <<${guild.name}>> with <<${guild.memberCount?.toLocaleString()}>> members.` + ); - const channel = await getConfigChannel('servers'); + const channel = await this.client.utils.getConfigChannel('servers'); if (!channel) return; return await channel.send({ embeds: [ @@ -20,7 +23,7 @@ export default class GuildDeleteListener extends BushListener { color: colors.Red, description: `${emojis.leave} Left ${format.input( guild.name - )} with **${guild.memberCount?.toLocaleString()}** members. I am now in **${client.guilds.cache.size}** guilds.`, + )} with **${guild.memberCount?.toLocaleString()}** members. I am now in **${this.client.guilds.cache.size}** guilds.`, timestamp: new Date().toISOString(), footer: { text: `${guild.id}`, icon_url: guild.iconURL() ?? undefined } } diff --git a/src/listeners/guild/guildMemberAdd.ts b/src/listeners/guild/guildMemberAdd.ts index 004a2c2..f1f90af 100644 --- a/src/listeners/guild/guildMemberAdd.ts +++ b/src/listeners/guild/guildMemberAdd.ts @@ -15,10 +15,10 @@ export default class GuildMemberAddListener extends BushListener { } private async sendWelcomeMessage(member: GuildMember) { - if (client.config.isDevelopment) return; + if (this.client.config.isDevelopment) return; const welcomeChannel = await member.guild.getSetting('welcomeChannel'); if (!welcomeChannel) return; - const welcome = client.channels.cache.get(welcomeChannel) as TextChannel | undefined; + const welcome = this.client.channels.cache.get(welcomeChannel) as TextChannel | undefined; if (!welcome) return; if (member.guild.id !== welcome?.guild.id) throw new Error('Welcome channel must be in the guild.'); @@ -39,7 +39,7 @@ export default class GuildMemberAddListener extends BushListener { await welcome .send({ embeds: [embed] }) .then(() => - client.console.info( + this.client.console.info( 'guildMemberAdd', `Sent a message for ${format.inputLog(member.user.tag)} in ${format.inputLog(member.guild.name)}.` ) diff --git a/src/listeners/guild/guildMemberRemove.ts b/src/listeners/guild/guildMemberRemove.ts index 80e9ee8..39bab24 100644 --- a/src/listeners/guild/guildMemberRemove.ts +++ b/src/listeners/guild/guildMemberRemove.ts @@ -16,13 +16,13 @@ export default class GuildMemberRemoveListener extends BushListener { } private async sendWelcomeMessage(member: GuildMember | PartialGuildMember) { - if (client.config.isDevelopment) return; - const user = member.partial ? await client.users.fetch(member.id) : member.user; + if (this.client.config.isDevelopment) return; + const user = member.partial ? await this.client.users.fetch(member.id) : member.user; await sleep(50 * Time.Millisecond); // ban usually triggers after member leave const isBan = member.guild.bans.cache.has(member.id); const welcomeChannel = await member.guild.getSetting('welcomeChannel'); if (!welcomeChannel) return; - const welcome = client.channels.cache.get(welcomeChannel) as TextChannel | undefined; + const welcome = this.client.channels.cache.get(welcomeChannel) as TextChannel | undefined; if (member.guild.id !== welcome?.guild.id) throw new Error('Welcome channel must be in the guild.'); const embed: EmbedBuilder = new EmbedBuilder() .setDescription( @@ -34,7 +34,7 @@ export default class GuildMemberRemoveListener extends BushListener { welcome .send({ embeds: [embed] }) .then(() => - client.console.info( + this.client.console.info( 'guildMemberRemove', `Sent a message for ${format.inputLog(user.tag)} in ${format.inputLog(member.guild.name)}.` ) @@ -72,7 +72,7 @@ export default class GuildMemberRemoveListener extends BushListener { await row .save() .then(() => - client.console.info( + this.client.console.info( 'guildMemberRemove', `${isNew ? 'Created' : 'Updated'} info for ${format.inputLog(member.user.tag)}.` ) diff --git a/src/listeners/guild/joinRoles.ts b/src/listeners/guild/joinRoles.ts index f2922c8..539fa71 100644 --- a/src/listeners/guild/joinRoles.ts +++ b/src/listeners/guild/joinRoles.ts @@ -11,7 +11,7 @@ export default class JoinRolesListener extends BushListener { } public async exec(...[oldMember, newMember]: BushClientEvents['guildMemberUpdate']) { - if (client.config.isDevelopment) return; + if (this.client.config.isDevelopment) return; if (oldMember.pending && !newMember.pending) { const feat = { stickyRoles: await newMember.guild.hasFeature('stickyRoles'), @@ -66,7 +66,7 @@ export default class JoinRolesListener extends BushListener { return false as const; }); if (addedRoles) { - void client.console.info( + void this.client.console.info( 'guildMemberAdd', `Assigned sticky roles to ${format.inputLog(member.user.tag)} in ${format.inputLog(member.guild.name)}.` ); @@ -78,9 +78,9 @@ export default class JoinRolesListener extends BushListener { .catch(() => failedRoles.push(rolesArray[i])); } if (failedRoles.length) { - void client.console.warn('guildMemberAdd', `Failed assigning the following roles on Fallback: ${failedRoles}`); + void this.client.console.warn('guildMemberAdd', `Failed assigning the following roles on Fallback: ${failedRoles}`); } else { - void client.console.info( + void this.client.console.info( 'guildMemberAdd', `[Fallback] Assigned sticky roles to ${format.inputLog(member.user.tag)} in ${format.inputLog(member.guild.name)}.` ); @@ -102,7 +102,7 @@ export default class JoinRolesListener extends BushListener { await member.roles .add(joinRoles, 'Join roles.') .then(() => - client.console.info( + this.client.console.info( 'guildMemberAdd', `Assigned join roles to ${format.inputLog(member.user.tag)} in ${format.inputLog(member.guild.name)}.` ) diff --git a/src/listeners/interaction/interactionCreate.ts b/src/listeners/interaction/interactionCreate.ts index 6c421d1..91bcae6 100644 --- a/src/listeners/interaction/interactionCreate.ts +++ b/src/listeners/interaction/interactionCreate.ts @@ -13,7 +13,7 @@ export default class InteractionCreateListener extends BushListener { public async exec(...[interaction]: BushClientEvents['interactionCreate']) { if (!interaction) return; if ('customId' in interaction && (interaction as any)['customId'].startsWith('test')) return; - void client.console.verbose( + void this.client.console.verbose( 'interactionVerbose', `An interaction of type <<${InteractionType[interaction.type]}>> was received from <<${interaction.user.tag}>>.` ); diff --git a/src/listeners/member-custom/bushPurge.ts b/src/listeners/member-custom/bushPurge.ts index ea30bc5..61a65e1 100644 --- a/src/listeners/member-custom/bushPurge.ts +++ b/src/listeners/member-custom/bushPurge.ts @@ -1,4 +1,4 @@ -import { BushListener, colors, emojis, inspectCleanRedactHaste, type BushClientEvents } from '#lib'; +import { BushListener, colors, emojis, type BushClientEvents } from '#lib'; import { EmbedBuilder } from 'discord.js'; export default class BushPurgeListener extends BushListener { @@ -21,7 +21,7 @@ export default class BushPurgeListener extends BushListener { embeds: m.embeds, attachments: [...m.attachments.values()] })); - const haste = await inspectCleanRedactHaste(mappedMessages); + const haste = await this.client.utils.inspectCleanRedactHaste(mappedMessages); const logEmbed = new EmbedBuilder() .setColor(colors.DarkPurple) diff --git a/src/listeners/member-custom/bushUpdateModlog.ts b/src/listeners/member-custom/bushUpdateModlog.ts index 5e29b9a..893bec6 100644 --- a/src/listeners/member-custom/bushUpdateModlog.ts +++ b/src/listeners/member-custom/bushUpdateModlog.ts @@ -1,4 +1,4 @@ -import { BushListener, colors, inspectCleanRedactCodeblock, type BushClientEvents } from '#lib'; +import { BushListener, colors, type BushClientEvents } from '#lib'; import { EmbedBuilder } from 'discord.js'; export default class BushUpdateModlogListener extends BushListener { @@ -26,8 +26,14 @@ export default class BushUpdateModlogListener extends BushListener { { name: '**Moderator**', value: `${moderator} (${moderator.user.tag})` }, { name: '**ModLog Changed**', value: modlogID }, { name: '**Value Changed**', value: key }, - { name: '**Old Value**', value: await inspectCleanRedactCodeblock(oldModlog, undefined, undefined, 1024) }, - { name: '**New Value**', value: await inspectCleanRedactCodeblock(newModlog, undefined, undefined, 1024) } + { + name: '**Old Value**', + value: await this.client.utils.inspectCleanRedactCodeblock(oldModlog, undefined, undefined, 1024) + }, + { + name: '**New Value**', + value: await this.client.utils.inspectCleanRedactCodeblock(newModlog, undefined, undefined, 1024) + } ]); return await logChannel.send({ embeds: [logEmbed] }); diff --git a/src/listeners/member-custom/bushUpdateSettings.ts b/src/listeners/member-custom/bushUpdateSettings.ts index e367c4e..3781a8b 100644 --- a/src/listeners/member-custom/bushUpdateSettings.ts +++ b/src/listeners/member-custom/bushUpdateSettings.ts @@ -1,4 +1,4 @@ -import { BushListener, colors, inspectCleanRedactCodeblock, type BushClientEvents } from '#lib'; +import { BushListener, colors, type BushClientEvents } from '#lib'; import { EmbedBuilder } from 'discord.js'; export default class BushUpdateSettingsListener extends BushListener { @@ -25,8 +25,8 @@ export default class BushUpdateSettingsListener extends BushListener { if (moderator) logEmbed.addFields([{ name: '**Moderator**', value: `${moderator} (${moderator.user.tag})` }]); logEmbed.addFields([ { name: '**Setting Changed**', value: setting }, - { name: '**Old Value**', value: await inspectCleanRedactCodeblock(oldSettings, 'js', undefined, 1024) }, - { name: '**New Value**', value: await inspectCleanRedactCodeblock(newSettings, 'js', undefined, 1024) } + { name: '**Old Value**', value: await this.client.utils.inspectCleanRedactCodeblock(oldSettings, 'js', undefined, 1024) }, + { name: '**New Value**', value: await this.client.utils.inspectCleanRedactCodeblock(newSettings, 'js', undefined, 1024) } ]); return await logChannel.send({ embeds: [logEmbed] }); diff --git a/src/listeners/message/autoPublisher.ts b/src/listeners/message/autoPublisher.ts index c669930..a6fb7e0 100644 --- a/src/listeners/message/autoPublisher.ts +++ b/src/listeners/message/autoPublisher.ts @@ -18,10 +18,11 @@ export default class autoPublisherListener extends BushListener { await message .crosspost() .then( - () => void client.logger.log('autoPublisher', `Published message <<${message.id}>> in <<${message.guild!.name}>>.`) + () => + void this.client.logger.log('autoPublisher', `Published message <<${message.id}>> in <<${message.guild!.name}>>.`) ) .catch(() => { - void client.console.log('autoPublisher', `Failed to publish <<${message.id}>> in <<${message.guild!.name}>>.`); + void this.client.console.log('autoPublisher', `Failed to publish <<${message.id}>> in <<${message.guild!.name}>>.`); void message.guild?.error('autoPublisher', `Unable to publish message id ${message.id} in <#${message.channel.id}>.`); }); } diff --git a/src/listeners/message/blacklistedFile.ts b/src/listeners/message/blacklistedFile.ts index 15d97e3..3d66f38 100644 --- a/src/listeners/message/blacklistedFile.ts +++ b/src/listeners/message/blacklistedFile.ts @@ -122,7 +122,7 @@ export default class BlacklistedFileListener extends BushListener { if (foundFiles.length > 0) { try { for (let i = 0; i < foundFiles.length; i++) { - if (foundFiles[i].name === 'Discord crash video' && !client.ownerID.includes(message.author.id)) { + if (foundFiles[i].name === 'Discord crash video' && !this.client.ownerID.includes(message.author.id)) { await message.member?.roles.add('748912426581229690'); } } @@ -132,7 +132,7 @@ export default class BlacklistedFileListener extends BushListener { `<@!${message.author.id}>, please do not send ${foundFiles.map((f) => f.description).join(' or ')}.` ); if (message.channel.type === ChannelType.DM) return; - void client.console.info( + void this.client.console.info( 'blacklistedFile', `Deleted <<${foundFiles.map((f) => f.description).join(' and ')}>> sent by <<${message.author.tag}>> in ${ message.channel.name @@ -142,7 +142,7 @@ export default class BlacklistedFileListener extends BushListener { void message.util!.send( `<@!${message.author.id}>, please do not send ${foundFiles.map((f) => f.description).join(' or ')}.` ); - void client.console.warn( + void this.client.console.warn( 'blacklistedFile', `Failed to delete <<${foundFiles.map((f) => f.description).join(' and ')}>> sent by <<${message.author.tag}>> in <<${ message.channel.type === ChannelType.DM ? `${message.channel.recipient?.tag}'s DMs` : message.channel.name diff --git a/src/listeners/message/boosterMessage.ts b/src/listeners/message/boosterMessage.ts index e33abfb..1a4d3c3 100644 --- a/src/listeners/message/boosterMessage.ts +++ b/src/listeners/message/boosterMessage.ts @@ -14,7 +14,7 @@ export default class BoosterMessageListener extends BushListener { if (!message.guild || !(await message.guild?.hasFeature('boosterMessageReact'))) return; if (message.type === MessageType.UserPremiumGuildSubscription) { return await message.react('<:nitroboost:785160348885975062>').catch(() => { - void client.console.warn('boosterMessage', `Failed to react to <<${message.id}>>.`); + void this.client.console.warn('boosterMessage', `Failed to react to <<${message.id}>>.`); }); } } diff --git a/src/listeners/message/directMessage.ts b/src/listeners/message/directMessage.ts index 463e4d8..7b599d9 100644 --- a/src/listeners/message/directMessage.ts +++ b/src/listeners/message/directMessage.ts @@ -1,4 +1,4 @@ -import { BushListener, colors, getConfigChannel, type BushClientEvents } from '#lib'; +import { BushListener, colors, type BushClientEvents } from '#lib'; import { ChannelType, EmbedBuilder } from 'discord.js'; export default class DirectMessageListener extends BushListener { @@ -12,11 +12,11 @@ export default class DirectMessageListener extends BushListener { public async exec(...[message]: BushClientEvents['messageCreate']) { if (message.channel.type === ChannelType.DM) { - if (!(message.author.id == client.user!.id) && message.author.bot) return; - if (client.cache.global.blacklistedUsers.includes(message.author.id)) return; + if (!(message.author.id == this.client.user!.id) && message.author.bot) return; + if (this.client.cache.global.blacklistedUsers.includes(message.author.id)) return; const dmLogEmbed = new EmbedBuilder().setTimestamp().setFooter({ text: `User ID • ${message.channel.recipientId}` }); - if (message.author.id != client.user!.id) { + if (message.author.id != this.client.user!.id) { dmLogEmbed .setAuthor({ name: `From: ${message.author.username}`, @@ -39,7 +39,7 @@ export default class DirectMessageListener extends BushListener { } else if (message.attachments.size > 0) { dmLogEmbed.addFields([{ name: 'Attachments', value: message.attachments.map((a) => a.proxyURL).join('\n') }]); } - const dmChannel = await getConfigChannel('dm'); + const dmChannel = await this.client.utils.getConfigChannel('dm'); await dmChannel.send({ embeds: [dmLogEmbed] }); } } diff --git a/src/listeners/message/highlight.ts b/src/listeners/message/highlight.ts index d68337c..d9d3c0b 100644 --- a/src/listeners/message/highlight.ts +++ b/src/listeners/message/highlight.ts @@ -14,12 +14,12 @@ export default class HighlightListener extends BushListener { if (message.author.bot || message.system) return; if (!(await message.guild.hasFeature('highlight'))) return; // allows highlighting to be disabled on a guild-by-guild basis - client.highlightManager.updateLastTalked(message); - const res = client.highlightManager.checkMessage(message); + this.client.highlightManager.updateLastTalked(message); + const res = this.client.highlightManager.checkMessage(message); for (const [user, hl] of res.entries()) { if (message.author.id === user) continue; - void client.highlightManager.notify(message, user, hl); + void this.client.highlightManager.notify(message, user, hl); } } } diff --git a/src/listeners/message/level.ts b/src/listeners/message/level.ts index a72ae02..526dac9 100644 --- a/src/listeners/message/level.ts +++ b/src/listeners/message/level.ts @@ -1,4 +1,4 @@ -import { BushListener, handleError, Level, type BushCommandHandlerEvents } from '#lib'; +import { BushListener, Level, type BushCommandHandlerEvents } from '#lib'; import { MessageType } from 'discord.js'; export default class LevelListener extends BushListener { @@ -33,13 +33,14 @@ export default class LevelListener extends BushListener { const xpToGive = Level.genRandomizedXp(); user.xp = user.xp + xpToGive; const success = await user.save().catch((e) => { - void handleError('level', e); + void this.client.utils.handleError('level', e); return false; }); const newLevel = Level.convertXpToLevel(user.xp); - if (previousLevel !== newLevel) client.emit('bushLevelUpdate', message.member!, previousLevel, newLevel, user.xp, message); + if (previousLevel !== newLevel) + this.client.emit('bushLevelUpdate', message.member!, previousLevel, newLevel, user.xp, message); if (success) - void client.logger.verbose(`level`, `Gave <<${xpToGive}>> XP to <<${message.author.tag}>> in <<${message.guild}>>.`); + void this.client.logger.verbose(`level`, `Gave <<${xpToGive}>> XP to <<${message.author.tag}>> in <<${message.guild}>>.`); this.#levelCooldowns.add(`${message.guildId}-${message.author.id}`); setTimeout(() => this.#levelCooldowns.delete(`${message.guildId}-${message.author.id}`), 60_000); } diff --git a/src/listeners/message/quoteCreate.ts b/src/listeners/message/quoteCreate.ts index d43eef7..0478bcf 100644 --- a/src/listeners/message/quoteCreate.ts +++ b/src/listeners/message/quoteCreate.ts @@ -1,4 +1,4 @@ -import { BushListener, resolveMessagesFromLinks, type BushClientEvents } from '#lib'; +import { BushListener, type BushClientEvents } from '#lib'; export default class QuoteCreateListener extends BushListener { public constructor() { @@ -10,10 +10,10 @@ export default class QuoteCreateListener extends BushListener { } public async exec(...[message]: BushClientEvents['messageCreate']) { - if (message.author.id !== '322862723090219008' || !client.config.isProduction) return; + if (message.author.id !== '322862723090219008' || !this.client.config.isProduction) return; if (!message.inGuild()) return; - const messages = await resolveMessagesFromLinks(message.content); + const messages = await this.client.utils.resolveMessagesFromLinks(message.content); if (!messages.length) return; for (const msg of messages) { diff --git a/src/listeners/message/verbose.ts b/src/listeners/message/verbose.ts index e3ef04f..f5e94de 100644 --- a/src/listeners/message/verbose.ts +++ b/src/listeners/message/verbose.ts @@ -11,9 +11,9 @@ export default class MessageVerboseListener extends BushListener { } public exec(...[message]: BushClientEvents['messageCreate']): void { - if (client.customReady) { + if (this.client.customReady) { if (message.channel?.type === ChannelType.DM) return; - void client.console.verbose( + void this.client.console.verbose( 'messageVerbose', `A message was sent by <<${message.author.tag}>> in <<${message.channel.name}>> in <<${message.guild!.name}>>.` ); diff --git a/src/listeners/other/consoleListener.ts b/src/listeners/other/consoleListener.ts index 543f459..3e72e9e 100644 --- a/src/listeners/other/consoleListener.ts +++ b/src/listeners/other/consoleListener.ts @@ -15,8 +15,9 @@ import { promisify } from 'util'; if (line.startsWith('eval ') || line.startsWith('ev ')) { /* eslint-disable @typescript-eslint/no-unused-vars */ const sh = promisify(exec), - bot = client, - config = client.config, + bot = this.client, + client = this.client, + config = this.client.config, { ActivePunishment, Global, Guild, Level, ModLog, StickyRole } = await import('#lib'), { ButtonInteraction, diff --git a/src/listeners/other/exit.ts b/src/listeners/other/exit.ts index e16aeb7..ac074df 100644 --- a/src/listeners/other/exit.ts +++ b/src/listeners/other/exit.ts @@ -9,6 +9,6 @@ export default class ExitListener extends BushListener { } public async exec(code: number) { - await client.console.error('processExit', `Process ended with code <<${code}>>.`); + await this.client.console.error('processExit', `Process ended with code <<${code}>>.`); } } diff --git a/src/listeners/other/promiseRejection.ts b/src/listeners/other/promiseRejection.ts index 79bf5de..ab67ad4 100644 --- a/src/listeners/other/promiseRejection.ts +++ b/src/listeners/other/promiseRejection.ts @@ -16,14 +16,18 @@ export default class PromiseRejectionListener extends BushListener { process.removeListener('unhandledRejection', listener); }); - client.sentry.captureException(error, { + this.client.sentry.captureException(error, { level: 'error' }); - void client.console.error('promiseRejection', `An unhanded promise rejection occurred:\n${formatError(error, true)}`, false); + void this.client.console.error( + 'promiseRejection', + `An unhanded promise rejection occurred:\n${formatError(error, true)}`, + false + ); if (!error.message.includes('reason: getaddrinfo ENOTFOUND canary.discord.com')) - void client.console.channelError({ - embeds: await CommandErrorListener.generateErrorEmbed({ type: 'unhandledRejection', error: error }) + void this.client.console.channelError({ + embeds: await CommandErrorListener.generateErrorEmbed(this.client, { type: 'unhandledRejection', error: error }) }); } } diff --git a/src/listeners/other/uncaughtException.ts b/src/listeners/other/uncaughtException.ts index 3e80feb..e06a3b8 100644 --- a/src/listeners/other/uncaughtException.ts +++ b/src/listeners/other/uncaughtException.ts @@ -15,13 +15,13 @@ export default class UncaughtExceptionListener extends BushListener { if (listener.toString() === this.exec.toString()) return; process.removeListener('uncaughtException', listener); }); - client.sentry.captureException(error, { + this.client.sentry.captureException(error, { level: 'error' }); - void client.console.error('uncaughtException', `An uncaught exception occurred:\n${formatError(error, true)}`, false); - void client.console.channelError({ - embeds: await CommandErrorListener.generateErrorEmbed({ type: 'uncaughtException', error: error }) + void this.client.console.error('uncaughtException', `An uncaught exception occurred:\n${formatError(error, true)}`, false); + void this.client.console.channelError({ + embeds: await CommandErrorListener.generateErrorEmbed(this.client, { type: 'uncaughtException', error: error }) }); } } diff --git a/src/listeners/other/warning.ts b/src/listeners/other/warning.ts index ba38f5f..b427e4c 100644 --- a/src/listeners/other/warning.ts +++ b/src/listeners/other/warning.ts @@ -12,15 +12,15 @@ export default class WarningListener extends BushListener { public async exec(error: Error) { if (error.name === 'ExperimentalWarning') return; - client.sentry.captureException(error, { + this.client.sentry.captureException(error, { level: 'warning' }); - void client.console.warn('warning', `A warning occurred:\n${formatError(error, true)}`, false); + void this.client.console.warn('warning', `A warning occurred:\n${formatError(error, true)}`, false); - const embeds = await CommandErrorListener.generateErrorEmbed({ type: 'unhandledRejection', error: error }); + const embeds = await CommandErrorListener.generateErrorEmbed(this.client, { type: 'unhandledRejection', error: error }); embeds[0].setColor(colors.warn).setTitle('A Warning Occurred'); - void client.console.channelError({ embeds }); + void this.client.console.channelError({ embeds }); } } diff --git a/src/listeners/rest/rateLimit.ts b/src/listeners/rest/rateLimit.ts index 5878d81..9071416 100644 --- a/src/listeners/rest/rateLimit.ts +++ b/src/listeners/rest/rateLimit.ts @@ -11,6 +11,6 @@ export default class RateLimitedListener extends BushListener { } public async exec(...[message]: RestEvents['rateLimited']): Promise<void> { - void client.console.superVerboseRaw('rateLimited', message); + void this.client.console.superVerboseRaw('rateLimited', message); } } diff --git a/src/listeners/track-manual-punishments/modlogSyncBan.ts b/src/listeners/track-manual-punishments/modlogSyncBan.ts index 45d6f51..a387897 100644 --- a/src/listeners/track-manual-punishments/modlogSyncBan.ts +++ b/src/listeners/track-manual-punishments/modlogSyncBan.ts @@ -37,6 +37,7 @@ export default class ModlogSyncBanListener extends BushListener { } const { log } = await Moderation.createModLogEntry({ + client: this.client, type: ModLogType.PERM_BAN, user: ban.user, moderator: first.executor, diff --git a/src/listeners/track-manual-punishments/modlogSyncKick.ts b/src/listeners/track-manual-punishments/modlogSyncKick.ts index d901f5f..51d3dd8 100644 --- a/src/listeners/track-manual-punishments/modlogSyncKick.ts +++ b/src/listeners/track-manual-punishments/modlogSyncKick.ts @@ -37,6 +37,7 @@ export default class ModlogSyncKickListener extends BushListener { } const { log } = await Moderation.createModLogEntry({ + client: this.client, type: ModLogType.KICK, user: member.user, moderator: first.executor, diff --git a/src/listeners/track-manual-punishments/modlogSyncTimeout.ts b/src/listeners/track-manual-punishments/modlogSyncTimeout.ts index 4619edd..2ce3db2 100644 --- a/src/listeners/track-manual-punishments/modlogSyncTimeout.ts +++ b/src/listeners/track-manual-punishments/modlogSyncTimeout.ts @@ -41,6 +41,7 @@ export default class ModlogSyncTimeoutListener extends BushListener { const newTime = <string | null>timeOut.new ? new Date(<string>timeOut.new) : null; const { log } = await Moderation.createModLogEntry({ + client: this.client, type: newTime ? ModLogType.TIMEOUT : ModLogType.REMOVE_TIMEOUT, user: newMember.user, moderator: first.executor, diff --git a/src/listeners/track-manual-punishments/modlogSyncUnban.ts b/src/listeners/track-manual-punishments/modlogSyncUnban.ts index 34979a5..2207e78 100644 --- a/src/listeners/track-manual-punishments/modlogSyncUnban.ts +++ b/src/listeners/track-manual-punishments/modlogSyncUnban.ts @@ -36,6 +36,7 @@ export default class ModlogSyncUnbanListener extends BushListener { } const { log } = await Moderation.createModLogEntry({ + client: this.client, type: ModLogType.UNBAN, user: ban.user, moderator: first.executor, diff --git a/src/listeners/ws/INTERACTION_CREATE.ts b/src/listeners/ws/INTERACTION_CREATE.ts index 5f479ad..0e8ee7c 100644 --- a/src/listeners/ws/INTERACTION_CREATE.ts +++ b/src/listeners/ws/INTERACTION_CREATE.ts @@ -62,7 +62,7 @@ export default class WsInteractionCreateListener extends BushListener { string ]; - const guild = client.guilds.resolve(guildId); + const guild = this.client.guilds.resolve(guildId); if (!guild) return respond({ type: InteractionResponseType.ChannelMessageWithSource, @@ -137,8 +137,8 @@ export default class WsInteractionCreateListener extends BushListener { ]; if (action === 'appeal_deny') { - await client.users - .send(userId, `Your ${punishment} appeal has been denied in ${client.guilds.resolve(guildId)!}.`) + await this.client.users + .send(userId, `Your ${punishment} appeal has been denied in ${this.client.guilds.resolve(guildId)!}.`) .catch(() => {}); void respond({ @@ -172,7 +172,7 @@ export default class WsInteractionCreateListener extends BushListener { string ]; - const guild = client.guilds.resolve(guildId); + const guild = this.client.guilds.resolve(guildId); if (!guild) return respond({ type: InteractionResponseType.ChannelMessageWithSource, @@ -191,7 +191,7 @@ export default class WsInteractionCreateListener extends BushListener { }); assert(interaction.user); - const user = new User(client, interaction.user); + const user = new User(this.client, interaction.user); assert(user); // const caseId = await ModLog.findOne({ where: { user: userId, guild: guildId, id: modlogCase } }); |