diff options
| author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-06-17 20:03:05 -0400 |
|---|---|---|
| committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-06-17 20:03:05 -0400 |
| commit | e1c613829950a534d9f45c00a033b83575be3b3c (patch) | |
| tree | 2de1e5231217211ae4087c46cc74dc46c584507a /src/lib | |
| parent | 0e87bbd3940d89defcb04926587b35c8f4d1947f (diff) | |
| download | tanzanite-e1c613829950a534d9f45c00a033b83575be3b3c.tar.gz tanzanite-e1c613829950a534d9f45c00a033b83575be3b3c.tar.bz2 tanzanite-e1c613829950a534d9f45c00a033b83575be3b3c.zip | |
remove global client variable
Diffstat (limited to 'src/lib')
20 files changed, 743 insertions, 629 deletions
diff --git a/src/lib/common/AutoMod.ts b/src/lib/common/AutoMod.ts index 7f19e63..0910352 100644 --- a/src/lib/common/AutoMod.ts +++ b/src/lib/common/AutoMod.ts @@ -1,4 +1,4 @@ -import { banResponse, codeblock, colors, emojis, format, formatError, getShared, Moderation, resolveNonCachedUser } from '#lib'; +import { banResponse, colors, emojis, format, formatError, Moderation } from '#lib'; import assert from 'assert'; import chalk from 'chalk'; import { @@ -31,7 +31,7 @@ export class AutoMod { */ private message: Message ) { - if (message.author.id === client.user?.id) return; + if (message.author.id === message.client.user?.id) return; void this.handle(); } @@ -56,9 +56,9 @@ export class AutoMod { traditional: { if (this.isImmune) break traditional; - const badLinksArray = getShared('badLinks'); - const badLinksSecretArray = getShared('badLinksSecret'); - const badWordsRaw = getShared('badWords'); + const badLinksArray = this.message.client.utils.getShared('badLinks'); + const badLinksSecretArray = this.message.client.utils.getShared('badLinksSecret'); + const badWordsRaw = this.message.client.utils.getShared('badWords'); const customAutomodPhrases = (await this.message.guild.getSetting('autoModPhases')) ?? []; const uniqueLinks = [...new Set([...badLinksArray, ...badLinksSecretArray])]; @@ -167,7 +167,9 @@ export class AutoMod { .setDescription( `**User:** ${this.message.author} (${this.message.author.tag})\n**Sent From:** <#${this.message.channel.id}> [Jump to context](${this.message.url})` ) - .addFields([{ name: 'Message Content', value: `${await codeblock(this.message.content, 1024)}` }]) + .addFields([ + { name: 'Message Content', value: `${await this.message.client.utils.codeblock(this.message.content, 1024)}` } + ]) .setColor(color) .setTimestamp() ], @@ -186,12 +188,12 @@ export class AutoMod { private async checkPerspectiveApi() { return; - if (!client.config.isDevelopment) return; + if (!this.message.client.config.isDevelopment) return; if (!this.message.content) return; - client.perspective.comments.analyze( + this.message.client.perspective.comments.analyze( { - key: client.config.credentials.perspectiveApiKey, + key: this.message.client.config.credentials.perspectiveApiKey, resource: { comment: { text: this.message.content @@ -301,7 +303,7 @@ export class AutoMod { { title: 'AutoMod Error', description: `Unable to delete triggered message.`, - fields: [{ name: 'Error', value: await codeblock(`${formatError(e)}`, 1024, 'js', true) }], + fields: [{ name: 'Error', value: await this.message.client.utils.codeblock(`${formatError(e)}`, 1024, 'js', true) }], color: colors.error } ] @@ -316,7 +318,7 @@ export class AutoMod { * @param offences The other offences that were also matched in the message */ private async log(highestOffence: BadWordDetails, color: number, offences: BadWordDetails[]) { - void client.console.info( + void this.message.client.console.info( 'autoMod', `Severity <<${highestOffence.severity}>> action performed on <<${this.message.author.tag}>> (<<${ this.message.author.id @@ -332,7 +334,9 @@ export class AutoMod { this.message.channel.id }> [Jump to context](${this.message.url})\n**Blacklisted Words:** ${offences.map((o) => `\`${o.match}\``).join(', ')}` ) - .addFields([{ name: 'Message Content', value: `${await codeblock(this.message.content, 1024)}` }]) + .addFields([ + { name: 'Message Content', value: `${await this.message.client.utils.codeblock(this.message.content, 1024)}` } + ]) .setColor(color) .setTimestamp() .setAuthor({ name: this.message.author.tag, url: this.message.author.displayAvatarURL() }) @@ -386,7 +390,7 @@ export class AutoMod { evidence: (interaction.message as Message).url ?? undefined }); - const victimUserFormatted = (await resolveNonCachedUser(userId))?.tag ?? userId; + const victimUserFormatted = (await interaction.client.utils.resolveNonCachedUser(userId))?.tag ?? userId; if (result === banResponse.SUCCESS) return interaction.reply({ content: `${emojis.success} Successfully banned **${victimUserFormatted}**.`, diff --git a/src/lib/common/ButtonPaginator.ts b/src/lib/common/ButtonPaginator.ts index 9560247..708b374 100644 --- a/src/lib/common/ButtonPaginator.ts +++ b/src/lib/common/ButtonPaginator.ts @@ -97,7 +97,7 @@ export class ButtonPaginator { * @param interaction The interaction received */ protected async collect(interaction: MessageComponentInteraction) { - if (interaction.user.id !== this.message.author.id && !client.config.owners.includes(interaction.user.id)) + if (interaction.user.id !== this.message.author.id && !this.message.client.config.owners.includes(interaction.user.id)) return await interaction?.deferUpdate().catch(() => null); switch (interaction.customId) { diff --git a/src/lib/common/ConfirmationPrompt.ts b/src/lib/common/ConfirmationPrompt.ts index 4593d24..38d078a 100644 --- a/src/lib/common/ConfirmationPrompt.ts +++ b/src/lib/common/ConfirmationPrompt.ts @@ -43,7 +43,7 @@ export class ConfirmationPrompt { collector.on('collect', async (interaction: MessageComponentInteraction) => { await interaction.deferUpdate().catch(() => undefined); - if (interaction.user.id == this.message.author.id || client.config.owners.includes(interaction.user.id)) { + if (interaction.user.id == this.message.author.id || this.message.client.config.owners.includes(interaction.user.id)) { if (interaction.customId === 'confirmationPrompt_confirm') { responded = true; collector.stop(); diff --git a/src/lib/common/DeleteButton.ts b/src/lib/common/DeleteButton.ts index b561d94..bc0da17 100644 --- a/src/lib/common/DeleteButton.ts +++ b/src/lib/common/DeleteButton.ts @@ -45,7 +45,7 @@ export class DeleteButton { collector.on('collect', async (interaction: MessageComponentInteraction) => { await interaction.deferUpdate().catch(() => undefined); - if (interaction.user.id == this.message.author.id || client.config.owners.includes(interaction.user.id)) { + if (interaction.user.id == this.message.author.id || this.message.client.config.owners.includes(interaction.user.id)) { if (msg.deletable && !CommandUtil.deletedMessages.has(msg.id)) await msg.delete(); } }); diff --git a/src/lib/common/HighlightManager.ts b/src/lib/common/HighlightManager.ts index caaa6a5..cd89c89 100644 --- a/src/lib/common/HighlightManager.ts +++ b/src/lib/common/HighlightManager.ts @@ -232,10 +232,10 @@ export class HighlightManager { const lastDM = this.lastedDMedUserCooldown.get(user); if (!lastDM) break dmCooldown; - const cooldown = client.ownerID.includes(user) ? OWNER_NOTIFY_COOLDOWN : NOTIFY_COOLDOWN; + const cooldown = message.client.ownerID.includes(user) ? OWNER_NOTIFY_COOLDOWN : NOTIFY_COOLDOWN; if (new Date().getTime() - lastDM.getTime() < cooldown) { - void client.console.verbose('Highlight', `User <<${user}>> has been dmed recently.`); + void message.client.console.verbose('Highlight', `User <<${user}>> has been dmed recently.`); return false; } } @@ -248,7 +248,7 @@ export class HighlightManager { const talked = lastTalked.getTime(); if (now - talked < LAST_MESSAGE_COOLDOWN) { - void client.console.verbose('Highlight', `User <<${user}>> has talked too recently.`); + void message.client.console.verbose('Highlight', `User <<${user}>> has talked too recently.`); setTimeout(() => { const newTalked = this.userLastTalkedCooldown.get(message.guildId)?.get(user)?.getTime(); @@ -268,7 +268,7 @@ export class HighlightManager { .first(4) .reverse(); - return client.users + return message.client.users .send(user, { // eslint-disable-next-line @typescript-eslint/no-base-to-string content: `In ${format.input(message.guild.name)} ${message.channel}, your highlight "${hl.word}" was matched:`, diff --git a/src/lib/common/util/Arg.ts b/src/lib/common/util/Arg.ts index a7795b1..325f821 100644 --- a/src/lib/common/util/Arg.ts +++ b/src/lib/common/util/Arg.ts @@ -18,7 +18,7 @@ export async function cast<T extends ATC>(type: T, message: CommandMessage | Sla export async function cast<T extends KBAT>(type: T, message: CommandMessage | SlashMessage, phrase: string): Promise<BAT[T]>; export async function cast(type: AT | ATC, message: CommandMessage | SlashMessage, phrase: string): Promise<any>; export async function cast(type: ATC | AT, message: CommandMessage | SlashMessage, phrase: string): Promise<any> { - return Argument.cast(type as any, client.commandHandler.resolver, message as Message, phrase); + return Argument.cast(type as any, message.client.commandHandler.resolver, message as Message, phrase); } /** diff --git a/src/lib/common/util/Moderation.ts b/src/lib/common/util/Moderation.ts index a08dfa4..cb6b4db 100644 --- a/src/lib/common/util/Moderation.ts +++ b/src/lib/common/util/Moderation.ts @@ -5,10 +5,8 @@ import { emojis, format, Guild as GuildDB, - handleError, humanizeDuration, ModLog, - resolveNonCachedUser, type ModLogType } from '#lib'; import assert from 'assert'; @@ -16,6 +14,7 @@ import { ActionRowBuilder, ButtonBuilder, ButtonStyle, + Client, EmbedBuilder, PermissionFlagsBits, type Guild, @@ -129,9 +128,9 @@ export async function createModLogEntry( options: CreateModLogEntryOptions, getCaseNumber = false ): Promise<{ log: ModLog | null; caseNum: number | null }> { - const user = (await resolveNonCachedUser(options.user))!.id; - const moderator = (await resolveNonCachedUser(options.moderator))!.id; - const guild = client.guilds.resolveId(options.guild)!; + const user = (await options.client.utils.resolveNonCachedUser(options.user))!.id; + const moderator = (await options.client.utils.resolveNonCachedUser(options.moderator))!.id; + const guild = options.client.guilds.resolveId(options.guild)!; return createModLogEntrySimple( { @@ -172,7 +171,7 @@ export async function createModLogEntrySimple( hidden: options.hidden ?? false }); const saveResult: ModLog | null = await modLogEntry.save().catch(async (e) => { - await handleError('createModLogEntry', e); + await options.client.utils.handleError('createModLogEntry', e); return null; }); @@ -191,8 +190,8 @@ export async function createModLogEntrySimple( */ export async function createPunishmentEntry(options: CreatePunishmentEntryOptions): Promise<ActivePunishment | null> { const expires = options.duration ? new Date(+new Date() + options.duration ?? 0) : undefined; - const user = (await resolveNonCachedUser(options.user))!.id; - const guild = client.guilds.resolveId(options.guild)!; + const user = (await options.client.utils.resolveNonCachedUser(options.user))!.id; + const guild = options.client.guilds.resolveId(options.guild)!; const type = findTypeEnum(options.type)!; const entry = ActivePunishment.build( @@ -201,7 +200,7 @@ export async function createPunishmentEntry(options: CreatePunishmentEntryOption : { user, type, guild, expires, modlog: options.modlog } ); return await entry.save().catch(async (e) => { - await handleError('createPunishmentEntry', e); + await options.client.utils.handleError('createPunishmentEntry', e); return null; }); } @@ -212,8 +211,8 @@ export async function createPunishmentEntry(options: CreatePunishmentEntryOption * @returns Whether or not the entry was destroyed. */ export async function removePunishmentEntry(options: RemovePunishmentEntryOptions): Promise<boolean> { - const user = await resolveNonCachedUser(options.user); - const guild = client.guilds.resolveId(options.guild); + const user = await options.client.utils.resolveNonCachedUser(options.user); + const guild = options.client.guilds.resolveId(options.guild); const type = findTypeEnum(options.type); if (!user || !guild) return false; @@ -226,13 +225,13 @@ export async function removePunishmentEntry(options: RemovePunishmentEntryOption ? { user: user.id, guild: guild, type, extraInfo: options.extraInfo } : { user: user.id, guild: guild, type } }).catch(async (e) => { - await handleError('removePunishmentEntry', e); + await options.client.utils.handleError('removePunishmentEntry', e); success = false; }); if (entries) { const promises = entries.map(async (entry) => entry.destroy().catch(async (e) => { - await handleError('removePunishmentEntry', e); + await options.client.utils.handleError('removePunishmentEntry', e); success = false; }) ); @@ -298,9 +297,9 @@ export async function punishDM(options: PunishDMOptions): Promise<boolean> { new ActionRowBuilder<ButtonBuilder>({ components: [ new ButtonBuilder({ - customId: `appeal;${punishmentToPresentTense(options.punishment)};${options.guild.id};${client.users.resolveId( - options.user - )};${options.modlog}`, + customId: `appeal;${punishmentToPresentTense(options.punishment)};${ + options.guild.id + };${options.client.users.resolveId(options.user)};${options.modlog}`, style: ButtonStyle.Primary, label: 'Appeal' }).toJSON() @@ -308,7 +307,7 @@ export async function punishDM(options: PunishDMOptions): Promise<boolean> { }) ]; - const dmSuccess = await client.users + const dmSuccess = await options.client.users .send(options.user, { content, embeds: dmEmbed ? [dmEmbed] : undefined, @@ -318,7 +317,7 @@ export async function punishDM(options: PunishDMOptions): Promise<boolean> { return !!dmSuccess; } -interface BaseCreateModLogEntryOptions { +interface BaseCreateModLogEntryOptions extends BaseOptions { /** * The type of modlog entry. */ @@ -355,6 +354,11 @@ interface BaseCreateModLogEntryOptions { */ export interface CreateModLogEntryOptions extends BaseCreateModLogEntryOptions { /** + * The client. + */ + client: Client; + + /** * The user that a modlog entry is created for. */ user: GuildMemberResolvable; @@ -393,7 +397,7 @@ export interface SimpleCreateModLogEntryOptions extends BaseCreateModLogEntryOpt /** * Options for creating a punishment entry. */ -export interface CreatePunishmentEntryOptions { +export interface CreatePunishmentEntryOptions extends BaseOptions { /** * The type of punishment. */ @@ -428,7 +432,7 @@ export interface CreatePunishmentEntryOptions { /** * Options for removing a punishment entry. */ -export interface RemovePunishmentEntryOptions { +export interface RemovePunishmentEntryOptions extends BaseOptions { /** * The type of punishment. */ @@ -453,7 +457,7 @@ export interface RemovePunishmentEntryOptions { /** * Options for sending a user a punishment dm. */ -export interface PunishDMOptions { +export interface PunishDMOptions extends BaseOptions { /** * The modlog case id so the user can make an appeal. */ @@ -496,6 +500,13 @@ export interface PunishDMOptions { channel?: Snowflake; } +interface BaseOptions { + /** + * The client. + */ + client: Client; +} + export type PunishmentTypeDM = | 'warned' | 'muted' diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts index b382121..68b2599 100644 --- a/src/lib/extensions/discord-akairo/BushClient.ts +++ b/src/lib/extensions/discord-akairo/BushClient.ts @@ -63,7 +63,8 @@ import { Shared } from '../../models/shared/Shared.js'; import { Stat } from '../../models/shared/Stat.js'; import { AllowedMentions } from '../../utils/AllowedMentions.js'; import { BushCache } from '../../utils/BushCache.js'; -import BushLogger from '../../utils/BushLogger.js'; +import { BushClientUtils } from '../../utils/BushClientUtils.js'; +import { BushLogger } from '../../utils/BushLogger.js'; import { ExtendedGuild } from '../discord.js/ExtendedGuild.js'; import { ExtendedGuildMember } from '../discord.js/ExtendedGuildMember.js'; import { ExtendedMessage } from '../discord.js/ExtendedMessage.js'; @@ -76,14 +77,44 @@ const { Sequelize } = (await import('sequelize')).default; declare module 'discord.js' { export interface Client extends EventEmitter { - /** - * The ID of the owner(s). - */ + /** The ID of the owner(s). */ ownerID: Snowflake | Snowflake[]; - /** - * The ID of the superUser(s). - */ + /** The ID of the superUser(s). */ superUserID: Snowflake | Snowflake[]; + /** Whether or not the client is ready. */ + customReady: boolean; + /** The configuration for the client. */ + config: Config; + /** Stats for the client. */ + stats: BushStats; + /** The handler for the bot's listeners. */ + listenerHandler: BushListenerHandler; + /** The handler for the bot's command inhibitors. */ + inhibitorHandler: BushInhibitorHandler; + /** The handler for the bot's commands. */ + commandHandler: BushCommandHandler; + /** The handler for the bot's tasks. */ + taskHandler: BushTaskHandler; + /** The handler for the bot's context menu commands. */ + contextMenuCommandHandler: ContextMenuCommandHandler; + /** The database connection for this instance of the bot (production, beta, or development). */ + instanceDB: SequelizeType; + /** The database connection that is shared between all instances of the bot. */ + sharedDB: SequelizeType; + /** A custom logging system for the bot. */ + logger: BushLogger; + /** Cached global and guild database data. */ + cache: BushCache; + /** Sentry error reporting for the bot. */ + sentry: typeof Sentry; + /** Manages most aspects of the highlight command */ + highlightManager: HighlightManager; + /** The perspective api */ + perspective: any; + /** Client utilities. */ + utils: BushClientUtils; + /** A custom logging system for the bot. */ + get console(): BushLogger; on<K extends keyof BushClientEvents>(event: K, listener: (...args: BushClientEvents[K]) => Awaitable<void>): this; once<K extends keyof BushClientEvents>(event: K, listener: (...args: BushClientEvents[K]) => Awaitable<void>): this; emit<K extends keyof BushClientEvents>(event: K, ...args: BushClientEvents[K]): boolean; @@ -126,72 +157,77 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re /** * Whether or not the client is ready. */ - public customReady = false; + public override customReady = false; /** * Stats for the client. */ - public stats: BushStats = { cpu: undefined, commandsUsed: 0n, slashCommandsUsed: 0n }; + public override stats: BushStats = { cpu: undefined, commandsUsed: 0n, slashCommandsUsed: 0n }; /** * The handler for the bot's listeners. */ - public listenerHandler: BushListenerHandler; + public override listenerHandler: BushListenerHandler; /** * The handler for the bot's command inhibitors. */ - public inhibitorHandler: BushInhibitorHandler; + public override inhibitorHandler: BushInhibitorHandler; /** * The handler for the bot's commands. */ - public commandHandler: BushCommandHandler; + public override commandHandler: BushCommandHandler; /** * The handler for the bot's tasks. */ - public taskHandler: BushTaskHandler; + public override taskHandler: BushTaskHandler; /** * The handler for the bot's context menu commands. */ - public contextMenuCommandHandler: ContextMenuCommandHandler; + public override contextMenuCommandHandler: ContextMenuCommandHandler; /** * The database connection for this instance of the bot (production, beta, or development). */ - public instanceDB: SequelizeType; + public override instanceDB: SequelizeType; /** * The database connection that is shared between all instances of the bot. */ - public sharedDB: SequelizeType; + public override sharedDB: SequelizeType; /** * A custom logging system for the bot. */ - public logger = BushLogger; + public override logger: BushLogger; /** * Cached global and guild database data. */ - public cache = new BushCache(); + public override cache = new BushCache(); /** * Sentry error reporting for the bot. */ - public sentry!: typeof Sentry; + public override sentry!: typeof Sentry; /** * Manages most aspects of the highlight command */ - public highlightManager = new HighlightManager(); + public override highlightManager = new HighlightManager(); /** * The perspective api */ - public perspective: any; + public override perspective: any; + + /** + * Client utilities. + */ + public override utils: BushClientUtils; /** * @param config The configuration for the bot. @@ -200,7 +236,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re /** * The configuration for the client. */ - public config: Config + public override config: Config ) { super({ ownerID: config.owners, @@ -220,7 +256,8 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re patch(this); this.token = config.token as If<Ready, string, string | null>; - this.config = config; + this.logger = new BushLogger(this); + this.utils = new BushClientUtils(this); /* =-=-= handlers =-=-= */ this.listenerHandler = new BushListenerHandler(this, { @@ -320,7 +357,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re /** * A custom logging system for the bot. */ - public get console(): typeof BushLogger { + public override get console(): BushLogger { return this.logger; } @@ -474,7 +511,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re await this.highlightManager.syncCache(); await UpdateCacheTask.init(this); void this.console.success('startup', `Successfully created <<cache>>.`, false); - const stats = await UpdateStatsTask.init(); + const stats = await UpdateStatsTask.init(this); this.stats.commandsUsed = stats.commandsUsed; this.stats.slashCommandsUsed = stats.slashCommandsUsed; await this.login(this.token!); @@ -500,7 +537,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re public override isSuperUser(user: UserResolvable): boolean { const userID = this.users.resolveId(user)!; - return client.cache.shared.superUsers.includes(userID) || this.config.owners.includes(userID); + return this.cache.shared.superUsers.includes(userID) || this.config.owners.includes(userID); } } diff --git a/src/lib/extensions/discord-akairo/BushCommand.ts b/src/lib/extensions/discord-akairo/BushCommand.ts index 5fb4e06..414da09 100644 --- a/src/lib/extensions/discord-akairo/BushCommand.ts +++ b/src/lib/extensions/discord-akairo/BushCommand.ts @@ -34,6 +34,8 @@ import { Message, User, type ApplicationCommandOptionChoiceData, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + type ApplicationCommandOptionType, type PermissionResolvable, type PermissionsString, type Snowflake @@ -93,7 +95,7 @@ interface BaseBushArgumentOptions extends Omit<ArgumentOptions, 'type' | 'prompt /** * Allows you to get a discord resolved object * - * ex. get the resolved member object when the type is `USER` + * ex. get the resolved member object when the type is {@link ApplicationCommandOptionType.User User} */ slashResolve?: SlashResolveType; @@ -113,12 +115,12 @@ interface BaseBushArgumentOptions extends Omit<ArgumentOptions, 'type' | 'prompt channelTypes?: AkairoApplicationCommandChannelOptionData['channelTypes']; /** - * The minimum value for an `INTEGER` or `NUMBER` option + * The minimum value for an {@link ApplicationCommandOptionType.Integer Integer} or {@link ApplicationCommandOptionType.Number Number} option */ minValue?: number; /** - * The maximum value for an `INTEGER` or `NUMBER` option + * The maximum value for an {@link ApplicationCommandOptionType.Integer Integer} or {@link ApplicationCommandOptionType.Number Number} option */ maxValue?: number; } diff --git a/src/lib/extensions/discord-akairo/BushCommandHandler.ts b/src/lib/extensions/discord-akairo/BushCommandHandler.ts index f095356..da49af9 100644 --- a/src/lib/extensions/discord-akairo/BushCommandHandler.ts +++ b/src/lib/extensions/discord-akairo/BushCommandHandler.ts @@ -1,4 +1,4 @@ -import { type BushClient, type BushCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { type BushCommand, type CommandMessage, type SlashMessage } from '#lib'; import { CommandHandler, type Category, type CommandHandlerEvents, type CommandHandlerOptions } from 'discord-akairo'; import { type Collection, type Message, type PermissionsString } from 'discord.js'; @@ -28,13 +28,8 @@ export interface BushCommandHandlerEvents extends CommandHandlerEvents { } export class BushCommandHandler extends CommandHandler { - public declare client: BushClient; public declare modules: Collection<string, BushCommand>; public declare categories: Collection<string, Category<string, BushCommand>>; - - public constructor(client: BushClient, options: CommandHandlerOptions) { - super(client, options); - } } export interface BushCommandHandler extends CommandHandler { diff --git a/src/lib/extensions/discord-akairo/BushInhibitor.ts b/src/lib/extensions/discord-akairo/BushInhibitor.ts index b4e6797..be396cf 100644 --- a/src/lib/extensions/discord-akairo/BushInhibitor.ts +++ b/src/lib/extensions/discord-akairo/BushInhibitor.ts @@ -1,15 +1,15 @@ -import { type BushClient, type BushCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { type BushCommand, type CommandMessage, type SlashMessage } from '#lib'; import { Inhibitor } from 'discord-akairo'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import { Message } from 'discord.js'; export abstract class BushInhibitor extends Inhibitor { - public declare client: BushClient; - /** * Checks if message should be blocked. * A return value of true will block the message. * If returning a Promise, a resolved value of true will block the message. * - * **Note:** `all` type inhibitors do not have `message.util` defined. + * **Note:** `'all'` type inhibitors do not have {@link Message.util} defined. * * @param message - Message being handled. * @param command - Command to check. diff --git a/src/lib/extensions/discord.js/ExtendedGuild.ts b/src/lib/extensions/discord.js/ExtendedGuild.ts index c199899..c58916c 100644 --- a/src/lib/extensions/discord.js/ExtendedGuild.ts +++ b/src/lib/extensions/discord.js/ExtendedGuild.ts @@ -41,7 +41,7 @@ import _ from 'lodash'; import * as Moderation from '../../common/util/Moderation.js'; import { Guild as GuildDB } from '../../models/instance/Guild.js'; import { ModLogType } from '../../models/instance/ModLog.js'; -import { addOrRemoveFromArray, resolveNonCachedUser } from '../../utils/BushUtils.js'; +import { addOrRemoveFromArray } from '../../utils/BushUtils.js'; declare module 'discord.js' { export interface Guild { @@ -187,7 +187,7 @@ export class ExtendedGuild extends Guild { */ public override async getSetting<K extends keyof GuildModel>(setting: K): Promise<GuildModel[K]> { return ( - client.cache.guilds.get(this.id)?.[setting] ?? + this.client.cache.guilds.get(this.id)?.[setting] ?? ((await GuildDB.findByPk(this.id)) ?? GuildDB.build({ id: this.id }))[setting] ); } @@ -206,8 +206,8 @@ export class ExtendedGuild extends Guild { const row = (await GuildDB.findByPk(this.id)) ?? GuildDB.build({ id: this.id }); const oldValue = row[setting] as GuildDB[K]; row[setting] = value; - client.cache.guilds.set(this.id, row.toJSON() as GuildDB); - client.emit('bushUpdateSettings', setting, this, oldValue, row[setting], moderator); + this.client.cache.guilds.set(this.id, row.toJSON() as GuildDB); + this.client.emit('bushUpdateSettings', setting, this, oldValue, row[setting], moderator); return await row.save(); } @@ -253,7 +253,7 @@ export class ExtendedGuild extends Guild { * @param message The description of the error embed */ public override async error(title: string, message: string): Promise<void> { - void 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 }] }); } @@ -268,8 +268,8 @@ export class ExtendedGuild extends Guild { let caseID: string | undefined = undefined; let dmSuccessEvent: boolean | undefined = undefined; - const user = await resolveNonCachedUser(options.user); - const moderator = client.users.resolve(options.moderator ?? client.user!); + const user = await this.client.utils.resolveNonCachedUser(options.user); + const moderator = this.client.users.resolve(options.moderator ?? this.client.user!); if (!user || !moderator) return banResponse.CANNOT_RESOLVE_USER; if ((await this.bans.fetch()).has(user.id)) return banResponse.ALREADY_BANNED; @@ -277,6 +277,7 @@ export class ExtendedGuild extends Guild { const ret = await (async () => { // add modlog entry const { log: modlog } = await Moderation.createModLogEntry({ + client: this.client, type: options.duration ? ModLogType.TEMP_BAN : ModLogType.PERM_BAN, user: user, moderator: moderator.id, @@ -290,6 +291,7 @@ export class ExtendedGuild extends Guild { // dm user dmSuccessEvent = await Moderation.punishDM({ + client: this.client, modlog: modlog.id, guild: this, user: user, @@ -310,6 +312,7 @@ export class ExtendedGuild extends Guild { // add punishment entry so they can be unbanned later const punishmentEntrySuccess = await Moderation.createPunishmentEntry({ + client: this.client, type: 'ban', user: user, guild: this, @@ -323,7 +326,7 @@ export class ExtendedGuild extends Guild { })(); if (!([banResponse.ACTION_ERROR, banResponse.MODLOG_ERROR, banResponse.PUNISHMENT_ENTRY_ADD_ERROR] as const).includes(ret)) - client.emit( + this.client.emit( 'bushBan', user, moderator, @@ -352,6 +355,7 @@ export class ExtendedGuild extends Guild { const ret = await (async () => { // add modlog entry const { log: modlog } = await Moderation.createModLogEntrySimple({ + client: this.client, type: ModLogType.PERM_BAN, user: options.user, moderator: options.moderator, @@ -365,6 +369,7 @@ export class ExtendedGuild extends Guild { // dm user if (this.members.cache.has(options.user)) { dmSuccessEvent = await Moderation.punishDM({ |
