aboutsummaryrefslogtreecommitdiff
path: root/src/lib/extensions
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/extensions')
-rw-r--r--src/lib/extensions/discord-akairo/BushClient.ts26
-rw-r--r--src/lib/extensions/discord-akairo/BushClientUtil.ts36
-rw-r--r--src/lib/extensions/discord-akairo/BushCommand.ts12
-rw-r--r--src/lib/extensions/discord.js/BushBaseGuildTextChannel.ts9
-rw-r--r--src/lib/extensions/discord.js/BushGuild.ts6
-rw-r--r--src/lib/extensions/discord.js/BushGuildManager.d.ts3
-rw-r--r--src/lib/extensions/discord.js/BushGuildMemberManager.d.ts9
-rw-r--r--src/lib/extensions/discord.js/BushMessageManager.d.ts39
-rw-r--r--src/lib/extensions/discord.js/BushThreadManager.d.ts42
-rw-r--r--src/lib/extensions/discord.js/BushThreadMemberManager.d.ts10
10 files changed, 89 insertions, 103 deletions
diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts
index 93ed9d7..59aea26 100644
--- a/src/lib/extensions/discord-akairo/BushClient.ts
+++ b/src/lib/extensions/discord-akairo/BushClient.ts
@@ -10,6 +10,7 @@ import type {
BushUserManager,
Config
} from '#lib';
+import { patch, type PatchedElements } from '@notenoughupdates/events-intercept';
import * as Sentry from '@sentry/node';
import { AkairoClient, ContextMenuCommandHandler, version as akairoVersion } from 'discord-akairo';
import {
@@ -18,7 +19,9 @@ import {
Structures,
version as discordJsVersion,
type Awaitable,
- type Collection, type DMChannel, type InteractionReplyOptions,
+ type Collection,
+ type DMChannel,
+ type InteractionReplyOptions,
type Message,
type MessageEditOptions,
type MessageOptions,
@@ -28,8 +31,6 @@ import {
type Snowflake,
type WebhookEditMessageOptions
} from 'discord.js';
-//@ts-ignore: no typings
-import eventsIntercept from 'events-intercept';
import path from 'path';
import readline from 'readline';
import type { Sequelize as SequelizeType } from 'sequelize';
@@ -92,7 +93,7 @@ export type BushThreadMemberResolvable = BushThreadMember | BushUserResolvable;
export type BushUserResolvable = BushUser | Snowflake | BushMessage | BushGuildMember | BushThreadMember;
export type BushGuildMemberResolvable = BushGuildMember | BushUserResolvable;
export type BushRoleResolvable = BushRole | Snowflake;
-export type BushMessageResolvable = Message| BushMessage | Snowflake;
+export type BushMessageResolvable = Message | BushMessage | Snowflake;
export type BushEmojiResolvable = Snowflake | BushGuildEmoji | BushReactionEmoji;
export type BushEmojiIdentifierResolvable = string | BushEmojiResolvable;
export type BushThreadChannelResolvable = BushThreadChannel | Snowflake;
@@ -157,6 +158,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re
makeCache: Options.cacheWithLimits({}),
failIfNotExists: false
});
+ patch(this);
this.token = config.token as If<Ready, string, string | null>;
this.config = config;
@@ -344,8 +346,6 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re
* Starts the bot
*/
public async start() {
- eventsIntercept.patch(this);
- //@ts-expect-error: no typings
this.intercept('ready', async (arg, done) => {
await this.guilds.fetch();
const promises = this.guilds.cache.map((guild) => {
@@ -386,23 +386,21 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re
const userID = this.users.resolveId(user)!;
return !!client.cache?.global?.superUsers?.includes(userID) || this.config.owners.includes(userID);
}
-
-
}
-export interface BushClient {
+export interface BushClient extends PatchedElements {
on<K extends keyof BushClientEvents>(event: K, listener: (...args: BushClientEvents[K]) => Awaitable<void>): this;
- on<S extends string | symbol>(event: Exclude<S, keyof BushClientEvents>, listener: (...args: any[]) => Awaitable<void>): this
+ on<S extends string | symbol>(event: Exclude<S, keyof BushClientEvents>, listener: (...args: any[]) => Awaitable<void>): this;
once<K extends keyof BushClientEvents>(event: K, listener: (...args: BushClientEvents[K]) => Awaitable<void>): this;
- once<S extends string | symbol>(event: Exclude<S, keyof BushClientEvents>, listener: (...args: any[]) => Awaitable<void>): this
+ once<S extends string | symbol>(event: Exclude<S, keyof BushClientEvents>, listener: (...args: any[]) => Awaitable<void>): this;
emit<K extends keyof BushClientEvents>(event: K, ...args: BushClientEvents[K]): boolean;
- emit<S extends string | symbol>(event: Exclude<S, keyof BushClientEvents>, ...args: unknown[]): boolean
+ emit<S extends string | symbol>(event: Exclude<S, keyof BushClientEvents>, ...args: unknown[]): boolean;
off<K extends keyof BushClientEvents>(event: K, listener: (...args: BushClientEvents[K]) => Awaitable<void>): this;
- off<S extends string | symbol>(event: Exclude<S, keyof BushClientEvents>, listener: (...args: any[]) => Awaitable<void>): this
+ off<S extends string | symbol>(event: Exclude<S, keyof BushClientEvents>, listener: (...args: any[]) => Awaitable<void>): this;
removeAllListeners<K extends keyof BushClientEvents>(event?: K): this;
- removeAllListeners<S extends string | symbol>(event?: Exclude<S, keyof BushClientEvents>): this
+ removeAllListeners<S extends string | symbol>(event?: Exclude<S, keyof BushClientEvents>): this;
}
diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts
index f21d104..8f1e67a 100644
--- a/src/lib/extensions/discord-akairo/BushClientUtil.ts
+++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts
@@ -16,6 +16,7 @@ import {
type Pronoun,
type PronounCode
} from '#lib';
+import { humanizeDuration } from '@notenoughupdates/humanize-duration';
import { exec } from 'child_process';
import { ClientUtil, Util as AkairoUtil } from 'discord-akairo';
import { APIMessage } from 'discord-api-types';
@@ -40,7 +41,6 @@ import moment from 'moment';
import { inspect, promisify } from 'util';
import CommandErrorListener from '../../../listeners/commands/commandError.js';
import { Format } from '../../common/Format.js';
-const { default: humanizeDuration } = await import ('humanize-duration')
export class BushClientUtil extends ClientUtil {
/**
@@ -255,11 +255,11 @@ export class BushClientUtil extends ClientUtil {
* @param options - The options you would like to use to inspect the object
*/
public inspect(object: any, options?: BushInspectOptions): string {
- const optionsWithDefaults = this.getDefaultInspectOptions(options)
+ const optionsWithDefaults = this.getDefaultInspectOptions(options);
return inspect(object, optionsWithDefaults);
}
- private getDefaultInspectOptions(options?:BushInspectOptions): BushInspectOptions {
+ private getDefaultInspectOptions(options?: BushInspectOptions): BushInspectOptions {
const {
showHidden = false,
depth = 2,
@@ -274,18 +274,18 @@ export class BushClientUtil extends ClientUtil {
getters = true
} = options ?? {};
return {
- showHidden,
- depth,
- colors,
- customInspect,
- showProxy,
- maxArrayLength,
- maxStringLength,
- breakLength,
- compact,
- sorted,
+ showHidden,
+ depth,
+ colors,
+ customInspect,
+ showProxy,
+ maxArrayLength,
+ maxStringLength,
+ breakLength,
+ compact,
+ sorted,
getters
- }
+ };
}
#mapCredential(old: string): string {
@@ -331,9 +331,7 @@ export class BushClientUtil extends ClientUtil {
length = 1024
) {
input =
- !inspectOptions?.inspectStrings && typeof input === 'string'
- ? input
- : this.inspect(input, inspectOptions ?? undefined);
+ !inspectOptions?.inspectStrings && typeof input === 'string' ? input : this.inspect(input, inspectOptions ?? undefined);
if (inspectOptions) inspectOptions.inspectStrings = undefined;
input = this.discord.cleanCodeBlockContent(input);
input = this.redact(input);
@@ -449,8 +447,8 @@ export class BushClientUtil extends ClientUtil {
}
public humanizeDuration(duration: number, largest?: number): string {
- if (largest) return humanizeDuration(duration, { language: 'en', maxDecimalPoints: 2, largest });
- else return humanizeDuration(duration, { language: 'en', maxDecimalPoints: 2 });
+ if (largest) return humanizeDuration(duration, { language: 'en', maxDecimalPoints: 2, largest })!;
+ else return humanizeDuration(duration, { language: 'en', maxDecimalPoints: 2 })!;
}
public timestampDuration(duration: number): string {
diff --git a/src/lib/extensions/discord-akairo/BushCommand.ts b/src/lib/extensions/discord-akairo/BushCommand.ts
index 03f6606..11f5ee3 100644
--- a/src/lib/extensions/discord-akairo/BushCommand.ts
+++ b/src/lib/extensions/discord-akairo/BushCommand.ts
@@ -1,10 +1,16 @@
import { type BushClient, type BushCommandHandler, type BushMessage, type BushSlashMessage } from '#lib';
-import { Command, type ArgumentOptions, type ArgumentPromptOptions, type ArgumentTypeCaster, type CommandOptions } from 'discord-akairo';
+import {
+ Command,
+ type ArgumentOptions,
+ type ArgumentPromptOptions,
+ type ArgumentTypeCaster,
+ type CommandOptions
+} from 'discord-akairo';
import { BaseArgumentType } from 'discord-akairo/dist/src/struct/commands/arguments/Argument';
import { type PermissionResolvable, type Snowflake } from 'discord.js';
-export type BaseBushArgumentType =
- | BaseArgumentType
+export type BaseBushArgumentType =
+ | BaseArgumentType
| 'duration'
| 'contentWithDuration'
| 'permission'
diff --git a/src/lib/extensions/discord.js/BushBaseGuildTextChannel.ts b/src/lib/extensions/discord.js/BushBaseGuildTextChannel.ts
index 652a50f..c3c279e 100644
--- a/src/lib/extensions/discord.js/BushBaseGuildTextChannel.ts
+++ b/src/lib/extensions/discord.js/BushBaseGuildTextChannel.ts
@@ -1,11 +1,4 @@
-import type {
- BushCategoryChannel,
- BushClient,
- BushGuild,
- BushGuildMember,
- BushMessageManager,
- BushThreadManager
-} from '#lib';
+import type { BushCategoryChannel, BushClient, BushGuild, BushGuildMember, BushMessageManager, BushThreadManager } from '#lib';
import {
BaseGuildTextChannel,
type AllowedThreadTypeForNewsChannel,
diff --git a/src/lib/extensions/discord.js/BushGuild.ts b/src/lib/extensions/discord.js/BushGuild.ts
index 5849749..ff920ce 100644
--- a/src/lib/extensions/discord.js/BushGuild.ts
+++ b/src/lib/extensions/discord.js/BushGuild.ts
@@ -191,7 +191,11 @@ export class BushGuild extends Guild {
const userObject = client.users.cache.get(user.id);
const dmSuccess = await userObject
- ?.send(`You have been unbanned from **${util.discord.escapeMarkdown(this.toString())}** for **${options.reason ?? 'No reason provided'}**.`)
+ ?.send(
+ `You have been unbanned from **${util.discord.escapeMarkdown(this.toString())}** for **${
+ options.reason ?? 'No reason provided'
+ }**.`
+ )
.catch(() => false);
dmSuccessEvent = !!dmSuccess;
diff --git a/src/lib/extensions/discord.js/BushGuildManager.d.ts b/src/lib/extensions/discord.js/BushGuildManager.d.ts
index 5bb8822..4dd0750 100644
--- a/src/lib/extensions/discord.js/BushGuildManager.d.ts
+++ b/src/lib/extensions/discord.js/BushGuildManager.d.ts
@@ -3,7 +3,8 @@ import {
CachedManager,
type Collection,
type FetchGuildOptions,
- type FetchGuildsOptions, type GuildCreateOptions,
+ type FetchGuildsOptions,
+ type GuildCreateOptions,
type OAuth2Guild,
type Snowflake
} from 'discord.js';
diff --git a/src/lib/extensions/discord.js/BushGuildMemberManager.d.ts b/src/lib/extensions/discord.js/BushGuildMemberManager.d.ts
index 8b1248c..0866fce 100644
--- a/src/lib/extensions/discord.js/BushGuildMemberManager.d.ts
+++ b/src/lib/extensions/discord.js/BushGuildMemberManager.d.ts
@@ -1,11 +1,4 @@
-import type {
- BushClient,
- BushGuild,
- BushGuildMember,
- BushGuildMemberResolvable,
- BushUser,
- BushUserResolvable
-} from '#lib';
+import type { BushClient, BushGuild, BushGuildMember, BushGuildMemberResolvable, BushUser, BushUserResolvable } from '#lib';
import {
CachedManager,
type AddGuildMemberOptions,
diff --git a/src/lib/extensions/discord.js/BushMessageManager.d.ts b/src/lib/extensions/discord.js/BushMessageManager.d.ts
index 9ded94c..f6bc8e7 100644
--- a/src/lib/extensions/discord.js/BushMessageManager.d.ts
+++ b/src/lib/extensions/discord.js/BushMessageManager.d.ts
@@ -1,26 +1,27 @@
import { BushMessageResolvable, type BushMessage, type BushTextBasedChannels } from '#lib';
import {
- CachedManager,
- type BaseFetchOptions,
- type ChannelLogsQueryOptions,
- type Collection,
- type EmojiIdentifierResolvable,
- type MessageEditOptions,
- type MessagePayload, type Snowflake
+ CachedManager,
+ type BaseFetchOptions,
+ type ChannelLogsQueryOptions,
+ type Collection,
+ type EmojiIdentifierResolvable,
+ type MessageEditOptions,
+ type MessagePayload,
+ type Snowflake
} from 'discord.js';
import type { RawMessageData } from 'discord.js/typings/rawDataTypes';
export class BushMessageManager extends CachedManager<Snowflake, BushMessage, BushMessageResolvable> {
- public constructor(channel: BushTextBasedChannels, iterable?: Iterable<RawMessageData>);
- public channel: BushTextBasedChannels;
- public cache: Collection<Snowflake, BushMessage>;
- public crosspost(message: BushMessageResolvable): Promise<BushMessage>;
- public delete(message: BushMessageResolvable): Promise<void>;
- public edit(message: BushMessageResolvable, options: MessagePayload | MessageEditOptions): Promise<BushMessage>;
- public fetch(message: Snowflake, options?: BaseFetchOptions): Promise<BushMessage>;
- public fetch(options?: ChannelLogsQueryOptions, cacheOptions?: BaseFetchOptions): Promise<Collection<Snowflake, BushMessage>>;
- public fetchPinned(cache?: boolean): Promise<Collection<Snowflake, BushMessage>>;
- public react(message: BushMessageResolvable, emoji: EmojiIdentifierResolvable): Promise<void>;
- public pin(message: BushMessageResolvable): Promise<void>;
- public unpin(message: BushMessageResolvable): Promise<void>;
+ public constructor(channel: BushTextBasedChannels, iterable?: Iterable<RawMessageData>);
+ public channel: BushTextBasedChannels;
+ public cache: Collection<Snowflake, BushMessage>;
+ public crosspost(message: BushMessageResolvable): Promise<BushMessage>;
+ public delete(message: BushMessageResolvable): Promise<void>;
+ public edit(message: BushMessageResolvable, options: MessagePayload | MessageEditOptions): Promise<BushMessage>;
+ public fetch(message: Snowflake, options?: BaseFetchOptions): Promise<BushMessage>;
+ public fetch(options?: ChannelLogsQueryOptions, cacheOptions?: BaseFetchOptions): Promise<Collection<Snowflake, BushMessage>>;
+ public fetchPinned(cache?: boolean): Promise<Collection<Snowflake, BushMessage>>;
+ public react(message: BushMessageResolvable, emoji: EmojiIdentifierResolvable): Promise<void>;
+ public pin(message: BushMessageResolvable): Promise<void>;
+ public unpin(message: BushMessageResolvable): Promise<void>;
}
diff --git a/src/lib/extensions/discord.js/BushThreadManager.d.ts b/src/lib/extensions/discord.js/BushThreadManager.d.ts
index 6822a80..c824ae7 100644
--- a/src/lib/extensions/discord.js/BushThreadManager.d.ts
+++ b/src/lib/extensions/discord.js/BushThreadManager.d.ts
@@ -1,27 +1,25 @@
-import type {
- BushThreadChannel
-} from '#lib';
+import type { BushThreadChannel } from '#lib';
import {
- CachedManager,
- FetchedThreads,
- NewsChannel,
- TextChannel,
- ThreadChannel,
- type BaseFetchOptions,
- type FetchArchivedThreadOptions,
- type FetchThreadsOptions,
- type Snowflake,
- type ThreadChannelResolvable,
- type ThreadCreateOptions
+ CachedManager,
+ FetchedThreads,
+ NewsChannel,
+ TextChannel,
+ ThreadChannel,
+ type BaseFetchOptions,
+ type FetchArchivedThreadOptions,
+ type FetchThreadsOptions,
+ type Snowflake,
+ type ThreadChannelResolvable,
+ type ThreadCreateOptions
} from 'discord.js';
import type { RawThreadChannelData } from 'discord.js/typings/rawDataTypes';
export class BushThreadManager<AllowedThreadType> extends CachedManager<Snowflake, BushThreadChannel, ThreadChannelResolvable> {
- public constructor(channel: TextChannel | NewsChannel, iterable?: Iterable<RawThreadChannelData>);
- public channel: TextChannel | NewsChannel;
- public create(options: ThreadCreateOptions<AllowedThreadType>): Promise<ThreadChannel>;
- public fetch(options: ThreadChannelResolvable, cacheOptions?: BaseFetchOptions): Promise<ThreadChannel | null>;
- public fetch(options?: FetchThreadsOptions, cacheOptions?: { cache?: boolean }): Promise<FetchedThreads>;
- public fetchArchived(options?: FetchArchivedThreadOptions, cache?: boolean): Promise<FetchedThreads>;
- public fetchActive(cache?: boolean): Promise<FetchedThreads>;
-} \ No newline at end of file
+ public constructor(channel: TextChannel | NewsChannel, iterable?: Iterable<RawThreadChannelData>);
+ public channel: TextChannel | NewsChannel;
+ public create(options: ThreadCreateOptions<AllowedThreadType>): Promise<ThreadChannel>;
+ public fetch(options: ThreadChannelResolvable, cacheOptions?: BaseFetchOptions): Promise<ThreadChannel | null>;
+ public fetch(options?: FetchThreadsOptions, cacheOptions?: { cache?: boolean }): Promise<FetchedThreads>;
+ public fetchArchived(options?: FetchArchivedThreadOptions, cache?: boolean): Promise<FetchedThreads>;
+ public fetchActive(cache?: boolean): Promise<FetchedThreads>;
+}
diff --git a/src/lib/extensions/discord.js/BushThreadMemberManager.d.ts b/src/lib/extensions/discord.js/BushThreadMemberManager.d.ts
index 082d87c..7560c0e 100644
--- a/src/lib/extensions/discord.js/BushThreadMemberManager.d.ts
+++ b/src/lib/extensions/discord.js/BushThreadMemberManager.d.ts
@@ -1,11 +1,5 @@
import type { BushClient, BushThreadChannel, BushThreadMember, BushThreadMemberResolvable } from '#lib';
-import {
- CachedManager,
- type BaseFetchOptions,
- type Collection,
- type Snowflake,
- type UserResolvable
-} from 'discord.js';
+import { CachedManager, type BaseFetchOptions, type Collection, type Snowflake, type UserResolvable } from 'discord.js';
import type { RawThreadMemberData } from 'discord.js/typings/rawDataTypes';
export class BushThreadMemberManager extends CachedManager<Snowflake, BushThreadMember, BushThreadMemberResolvable> {
@@ -14,7 +8,7 @@ export class BushThreadMemberManager extends CachedManager<Snowflake, BushThread
public thread: BushThreadChannel;
public add(member: UserResolvable | '@me', reason?: string): Promise<Snowflake>;
public fetch(member?: UserResolvable, options?: BaseFetchOptions): Promise<BushThreadMember>;
- /** @deprecated Use `fetch(member, options)` instead. */
+ /** @deprecated Use `fetch(member, options)` instead. */
public fetch(cache?: boolean): Promise<Collection<Snowflake, BushThreadMember>>;
public remove(id: Snowflake | '@me', reason?: string): Promise<Snowflake>;
}