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, comma |
