aboutsummaryrefslogtreecommitdiff
path: root/src/lib/extensions/discord-akairo
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-06-17 20:03:05 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-06-17 20:03:05 -0400
commite1c613829950a534d9f45c00a033b83575be3b3c (patch)
tree2de1e5231217211ae4087c46cc74dc46c584507a /src/lib/extensions/discord-akairo
parent0e87bbd3940d89defcb04926587b35c8f4d1947f (diff)
downloadtanzanite-e1c613829950a534d9f45c00a033b83575be3b3c.tar.gz
tanzanite-e1c613829950a534d9f45c00a033b83575be3b3c.tar.bz2
tanzanite-e1c613829950a534d9f45c00a033b83575be3b3c.zip
remove global client variable
Diffstat (limited to 'src/lib/extensions/discord-akairo')
-rw-r--r--src/lib/extensions/discord-akairo/BushClient.ts89
-rw-r--r--src/lib/extensions/discord-akairo/BushCommand.ts8
-rw-r--r--src/lib/extensions/discord-akairo/BushCommandHandler.ts7
-rw-r--r--src/lib/extensions/discord-akairo/BushInhibitor.ts8
4 files changed, 73 insertions, 39 deletions
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.