From e1c613829950a534d9f45c00a033b83575be3b3c Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Fri, 17 Jun 2022 20:03:05 -0400 Subject: remove global client variable --- src/lib/extensions/discord-akairo/BushClient.ts | 89 +++++++++++++++------- src/lib/extensions/discord-akairo/BushCommand.ts | 8 +- .../discord-akairo/BushCommandHandler.ts | 7 +- src/lib/extensions/discord-akairo/BushInhibitor.ts | 8 +- 4 files changed, 73 insertions(+), 39 deletions(-) (limited to 'src/lib/extensions/discord-akairo') 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(event: K, listener: (...args: BushClientEvents[K]) => Awaitable): this; once(event: K, listener: (...args: BushClientEvents[K]) => Awaitable): this; emit(event: K, ...args: BushClientEvents[K]): boolean; @@ -126,72 +157,77 @@ export class BushClient extends AkairoClient extends AkairoClient extends AkairoClient; - 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 extends AkairoClient extends AkairoClient>.`, 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 extends AkairoClient; public declare categories: Collection>; - - 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. -- cgit