diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-06-14 12:47:57 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-06-14 12:47:57 -0400 |
commit | 661e4c9935aeb8760dafc7ced4bbec6cc356a033 (patch) | |
tree | bb4c12bdef067d203f100e13e05ccb705b299834 /src/lib/extensions/discord.js | |
parent | eaf592b72eb5b1d66aa2bde5151a8947570a506c (diff) | |
download | tanzanite-661e4c9935aeb8760dafc7ced4bbec6cc356a033.tar.gz tanzanite-661e4c9935aeb8760dafc7ced4bbec6cc356a033.tar.bz2 tanzanite-661e4c9935aeb8760dafc7ced4bbec6cc356a033.zip |
remove the war crimes that I previously committed
- Remove custom typings and replace with declaration merging
- Fix the typings for args
- Replace all discord-api-types imports with discord.js imports
- Fix discord.js breaking changes
Diffstat (limited to 'src/lib/extensions/discord.js')
50 files changed, 393 insertions, 2803 deletions
diff --git a/src/lib/extensions/discord.js/BushActivity.ts b/src/lib/extensions/discord.js/BushActivity.ts deleted file mode 100644 index 3f19232..0000000 --- a/src/lib/extensions/discord.js/BushActivity.ts +++ /dev/null @@ -1,14 +0,0 @@ -import type { BushEmoji, BushPresence } from '#lib'; -import { Activity } from 'discord.js'; -import type { RawActivityData } from 'discord.js/typings/rawDataTypes'; - -/** - * Represents an activity that is part of a user's presence. - */ -export class BushActivity extends Activity { - public declare emoji: BushEmoji | null; - - public constructor(presence: BushPresence, data?: RawActivityData) { - super(presence, data); - } -} diff --git a/src/lib/extensions/discord.js/BushApplicationCommand.ts b/src/lib/extensions/discord.js/BushApplicationCommand.ts deleted file mode 100644 index 8298830..0000000 --- a/src/lib/extensions/discord.js/BushApplicationCommand.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* eslint-disable @typescript-eslint/ban-types */ -import type { BushClient, BushGuild } from '#lib'; -import { ApplicationCommand, type Snowflake } from 'discord.js'; -import type { RawApplicationCommandData } from 'discord.js/typings/rawDataTypes'; - -/** - * Represents an application command. - */ -export class BushApplicationCommand<PermissionsFetchType = {}> extends ApplicationCommand<PermissionsFetchType> { - public declare readonly client: BushClient; - public declare guild: BushGuild | null; - - public constructor(client: BushClient, data: RawApplicationCommandData, guild?: BushGuild, guildID?: Snowflake) { - super(client, data, guild, guildID); - } -} diff --git a/src/lib/extensions/discord.js/BushApplicationCommandManager.ts b/src/lib/extensions/discord.js/BushApplicationCommandManager.ts deleted file mode 100644 index dc27dbf..0000000 --- a/src/lib/extensions/discord.js/BushApplicationCommandManager.ts +++ /dev/null @@ -1,151 +0,0 @@ -import type { - BushApplicationCommand, - BushApplicationCommandPermissionsManager, - BushApplicationCommandResolvable, - BushClient, - BushGuildResolvable, - StripPrivate -} from '#lib'; -import type { APIApplicationCommand } from 'discord-api-types/v10'; -import { - ApplicationCommandManager, - CachedManager, - type ApplicationCommandData, - type Collection, - type FetchApplicationCommandOptions, - type Snowflake -} from 'discord.js'; - -/** - * Manages API methods for application commands and stores their cache. - */ -export declare class BushApplicationCommandManager< - ApplicationCommandScope = BushApplicationCommand<{ guild: BushGuildResolvable }>, - PermissionsOptionsExtras = { guild: BushGuildResolvable }, - PermissionsGuildType = null - > - extends CachedManager<Snowflake, ApplicationCommandScope, BushApplicationCommandResolvable> - implements StripPrivate<ApplicationCommandManager<ApplicationCommandScope, PermissionsOptionsExtras, PermissionsGuildType>> -{ - public constructor(client: BushClient, iterable?: Iterable<unknown>); - - /** - * The manager for permissions of arbitrary commands on arbitrary guilds - */ - public permissions: BushApplicationCommandPermissionsManager< - { command?: BushApplicationCommandResolvable } & PermissionsOptionsExtras, - { command: BushApplicationCommandResolvable } & PermissionsOptionsExtras, - PermissionsOptionsExtras, - PermissionsGuildType, - null - >; - - /** - * The APIRouter path to the commands - * @param id The application command's id - * @param guildId The guild's id to use in the path, - * ignored when using a {@link GuildApplicationCommandManager} - */ - private commandPath({ id, guildId }: { id?: Snowflake; guildId?: Snowflake }): unknown; - - /** - * Creates an application command. - * @param command The command - * @param guildId The guild's id to create this command in, ignored when using a {@link GuildApplicationCommandManager} - * @example - * // Create a new command - * client.application.commands.create({ - * name: 'test', - * description: 'A test command', - * }) - * .then(console.log) - * .catch(console.error); - */ - public create(command: BushApplicationCommandResolvable, guildId?: Snowflake): Promise<ApplicationCommandScope>; - - /** - * Deletes an application command. - * @param command The command to delete - * @param guildId The guild's id where the command is registered, - * ignored when using a {@link GuildApplicationCommandManager} - * @example - * // Delete a command - * guild.commands.delete('123456789012345678') - * .then(console.log) - * .catch(console.error); - */ - public delete(command: BushApplicationCommandResolvable, guildId?: Snowflake): Promise<ApplicationCommandScope | null>; - - /** - * Edits an application command. - * @param command The command to edit - * @param data The data to update the command with - * @param guildId The guild's id where the command registered, - * ignored when using a {@link GuildApplicationCommandManager} - * @example - * // Edit an existing command - * client.application.commands.edit('123456789012345678', { - * description: 'New description', - * }) - * .then(console.log) - * .catch(console.error); - */ - public edit(command: BushApplicationCommandResolvable, data: ApplicationCommandData): Promise<ApplicationCommandScope>; - public edit( - command: BushApplicationCommandResolvable, - data: ApplicationCommandData, - guildId: Snowflake - ): Promise<BushApplicationCommand>; - - /** - * Obtains one or multiple application commands from Discord, or the cache if it's already available. - * @param id The application command's id - * @param options Additional options for this fetch - * @example - * // Fetch a single command - * client.application.commands.fetch('123456789012345678') - * .then(command => console.log(`Fetched command ${command.name}`)) - * .catch(console.error); - * @example - * // Fetch all commands - * guild.commands.fetch() - * .then(commands => console.log(`Fetched ${commands.size} commands`)) - * .catch(console.error); - */ - public fetch(id: Snowflake, options: FetchApplicationCommandOptions & { guildId: Snowflake }): Promise<BushApplicationCommand>; - public fetch(options: FetchApplicationCommandOptions): Promise<Collection<string, ApplicationCommandScope>>; - public fetch(id: Snowflake, options?: FetchApplicationCommandOptions): Promise<ApplicationCommandScope>; - public fetch(id?: Snowflake, options?: FetchApplicationCommandOptions): Promise<Collection<Snowflake, ApplicationCommandScope>>; - - /** - * Sets all the commands for this application or guild. - * @param commands The commands - * @param guildId The guild's id to create the commands in, - * ignored when using a {@link GuildApplicationCommandManager} - * @example - * // Set all commands to just this one - * client.application.commands.set([ - * { - * name: 'test', - * description: 'A test command', - * }, - * ]) - * .then(console.log) - * .catch(console.error); - * @example - * // Remove all commands - * guild.commands.set([]) - * .then(console.log) - * .catch(console.error); - */ - public set(commands: ApplicationCommandData[]): Promise<Collection<Snowflake, ApplicationCommandScope>>; - public set(commands: ApplicationCommandData[], guildId: Snowflake): Promise<Collection<Snowflake, BushApplicationCommand>>; - - /** - * Transforms an {@link ApplicationCommandData} object into something that can be used with the API. - * @param command The command to transform - */ - private static transformCommand( - command: ApplicationCommandData - ): Omit<APIApplicationCommand, 'id' | 'application_id' | 'guild_id'>; -} diff --git a/src/lib/extensions/discord.js/BushApplicationCommandPermissionsManager.ts b/src/lib/extensions/discord.js/BushApplicationCommandPermissionsManager.ts deleted file mode 100644 index 401f3e2..0000000 --- a/src/lib/extensions/discord.js/BushApplicationCommandPermissionsManager.ts +++ /dev/null @@ -1,184 +0,0 @@ -import type { BushClient, BushRoleResolvable, BushUserResolvable } from '#lib'; -import type { APIApplicationCommandPermission } from 'discord-api-types/v10'; -import { - ApplicationCommandPermissionType, - BaseManager, - type ApplicationCommand, - type ApplicationCommandManager, - type ApplicationCommandPermissionData, - type ApplicationCommandPermissions, - type Collection, - type GuildApplicationCommandManager, - type GuildApplicationCommandPermissionData, - type Snowflake -} from 'discord.js'; - -/** - * Manages API methods for permissions of Application Commands. - */ -export declare class BushApplicationCommandPermissionsManager< - BaseOptions, - FetchSingleOptions, - FullPermissionsOptions, - GuildType, - CommandIdType -> extends BaseManager { - public constructor(manager: ApplicationCommandManager | GuildApplicationCommandManager | ApplicationCommand); - - /** - * The manager or command that this manager belongs to - */ - private manager: ApplicationCommandManager | GuildApplicationCommandManager | ApplicationCommand; - - /** - * The client that instantiated this Manager - */ - public client: BushClient; - - /** - * The id of the command this manager acts on - */ - public commandId: CommandIdType; - - /** - * The guild that this manager acts on - */ - public guild: GuildType; - - /** - * The id of the guild that this manager acts on - */ - public guildId: Snowflake | null; - - /** - * Add permissions to a command. - * @param options Options used to add permissions - * @example - * // Block a role from the command permissions - * guild.commands.permissions.add({ command: '123456789012345678', permissions: [ - * { - * id: '876543211234567890', - * type: 'ROLE', - * permission: false - * }, - * ]}) - * .then(console.log) - * .catch(console.error); - */ - public add( - options: FetchSingleOptions & { permissions: ApplicationCommandPermissionData[] } - ): Promise<ApplicationCommandPermissions[]>; - - /** - * Check whether a permission exists for a user or role - * @param options Options used to check permissions - * @example - * // Check whether a user has permission to use a command - * guild.commands.permissions.has({ command: '123456789012345678', permissionId: '876543210123456789' }) - * .then(console.log) - * .catch(console.error); - */ - public has(options: FetchSingleOptions & { permissionId: BushUserResolvable | BushRoleResolvable }): Promise<boolean>; - - /** - * Fetches the permissions for one or multiple commands. - * @param options Options used to fetch permissions - * @example - * // Fetch permissions for one command - * guild.commands.permissions.fetch({ command: '123456789012345678' }) - * .then(perms => console.log(`Fetched permissions for ${perms.length} users`)) - * .catch(console.error); - * @example - * // Fetch permissions for all commands in a guild - * client.application.commands.permissions.fetch({ guild: '123456789012345678' }) - * .then(perms => console.log(`Fetched permissions for ${perms.size} commands`)) - * .catch(console.error); - */ - public fetch(options: FetchSingleOptions): Promise<ApplicationCommandPermissions[]>; - public fetch(options: BaseOptions): Promise<Collection<Snowflake, ApplicationCommandPermissions[]>>; - - /** - * Remove permissions from a command. - * @param options Options used to remove permissions - * @example - * // Remove a user permission from this command - * guild.commands.permissions.remove({ command: '123456789012345678', users: '876543210123456789' }) - * .then(console.log) - * .catch(console.error); - * @example - * // Remove multiple roles from this command - * guild.commands.permissions.remove({ - * command: '123456789012345678', roles: ['876543210123456789', '765432101234567890'] - * }) - * .then(console.log) - * .catch(console.error); - */ - public remove( - options: - | (FetchSingleOptions & { - users: BushUserResolvable | BushUserResolvable[]; - roles?: BushRoleResolvable | BushRoleResolvable[]; - }) - | (FetchSingleOptions & { - users?: BushUserResolvable | BushUserResolvable[]; - roles: BushRoleResolvable | BushRoleResolvable[]; - }) - ): Promise<ApplicationCommandPermissions[]>; - - /** - * Sets the permissions for one or more commands. - * @param options Options used to set permissions - * @example - * // Set the permissions for one command - * client.application.commands.permissions.set({ guild: '892455839386304532', command: '123456789012345678', - * permissions: [ - * { - * id: '876543210987654321', - * type: 'USER', - * permission: false, - * }, - * ]}) - * .then(console.log) - * .catch(console.error); - * @example - * // Set the permissions for all commands - * guild.commands.permissions.set({ fullPermissions: [ - * { - * id: '123456789012345678', - * permissions: [{ - * id: '876543210987654321', - * type: 'USER', - * permission: false, - * }], - * }, - * ]}) - * .then(console.log) - * .catch(console.error); - */ - public set( - options: FetchSingleOptions & { permissions: ApplicationCommandPermissionData[] } - ): Promise<ApplicationCommandPermissions[]>; - public set( - options: FullPermissionsOptions & { - fullPermissions: GuildApplicationCommandPermissionData[]; - } - ): Promise<Collection<Snowflake, ApplicationCommandPermissions[]>>; - - /** - * The APIRouter path to the commands - * @param guildId The guild's id to use in the path, - * @param commandId The application command's id - */ - private permissionsPath(guildId: Snowflake, commandId?: Snowflake): unknown; - - /** - * Transforms an {@link ApplicationCommandPermissionData} object into something that can be used with the API. - * @param permissions The permissions to transform - * @param received Whether these permissions have been received from Discord - */ - private static transformPermissions( - permissions: ApplicationCommandPermissionData, - received: true - ): Omit<APIApplicationCommandPermission, 'type'> & { type: keyof ApplicationCommandPermissionType }; - private static transformPermissions(permissions: ApplicationCommandPermissionData): APIApplicationCommandPermission; -} diff --git a/src/lib/extensions/discord.js/BushBaseGuildEmojiManager.ts b/src/lib/extensions/discord.js/BushBaseGuildEmojiManager.ts deleted file mode 100644 index 66abbc2..0000000 --- a/src/lib/extensions/discord.js/BushBaseGuildEmojiManager.ts +++ /dev/null @@ -1,19 +0,0 @@ -import type { BushClient, BushEmojiIdentifierResolvable, BushEmojiResolvable, BushGuildEmoji } from '#lib'; -import { BaseGuildEmojiManager, CachedManager, type Snowflake } from 'discord.js'; -import { type RawGuildEmojiData } from 'discord.js/typings/rawDataTypes'; - -/** - * Holds methods to resolve GuildEmojis and stores their cache. - */ -export declare class BushBaseGuildEmojiManager - extends CachedManager<Snowflake, BushGuildEmoji, BushEmojiResolvable> - implements BaseGuildEmojiManager -{ - public constructor(client: BushClient, iterable?: Iterable<RawGuildEmojiData>); - - /** - * Resolves an EmojiResolvable to an emoji identifier. - * @param emoji The emoji resolvable to resolve - */ - public resolveIdentifier(emoji: BushEmojiIdentifierResolvable): string | null; -} diff --git a/src/lib/extensions/discord.js/BushBaseGuildTextChannel.ts b/src/lib/extensions/discord.js/BushBaseGuildTextChannel.ts deleted file mode 100644 index 5cc74c4..0000000 --- a/src/lib/extensions/discord.js/BushBaseGuildTextChannel.ts +++ /dev/null @@ -1,28 +0,0 @@ -import type { BushCategoryChannel, BushClient, BushGuild, BushGuildMember, BushMessageManager, BushThreadManager } from '#lib'; -import { - BaseGuildTextChannel, - type AllowedThreadTypeForNewsChannel, - type AllowedThreadTypeForTextChannel, - type Collection, - type Snowflake -} from 'discord.js'; -import type { RawGuildChannelData } from 'discord.js/typings/rawDataTypes'; - -/** - * Represents a text-based guild channel on Discord. - */ -export class BushBaseGuildTextChannel extends BaseGuildTextChannel { - public declare messages: BushMessageManager; - public declare threads: BushThreadManager<AllowedThreadTypeForTextChannel | AllowedThreadTypeForNewsChannel>; - public declare readonly client: BushClient; - public declare guild: BushGuild; - - public constructor(guild: BushGuild, data?: RawGuildChannelData, client?: BushClient, immediatePatch?: boolean) { - super(guild, data, client, immediatePatch); - } -} - -export interface BushBaseGuildTextChannel extends BaseGuildTextChannel { - get members(): Collection<Snowflake, BushGuildMember>; - get parent(): BushCategoryChannel | null; -} diff --git a/src/lib/extensions/discord.js/BushBaseGuildVoiceChannel.ts b/src/lib/extensions/discord.js/BushBaseGuildVoiceChannel.ts deleted file mode 100644 index ba41cfe..0000000 --- a/src/lib/extensions/discord.js/BushBaseGuildVoiceChannel.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { BaseGuildVoiceChannel, Collection, Snowflake } from 'discord.js'; -import { BushCategoryChannel } from './BushCategoryChannel.js'; -import { BushGuild } from './BushGuild.js'; -import { BushGuildMember } from './BushGuildMember.js'; - -/** - * Represents a voice-based guild channel on Discord. - */ -export declare class BushBaseGuildVoiceChannel extends BaseGuildVoiceChannel { - public get members(): Collection<Snowflake, BushGuildMember>; - public guild: BushGuild; - public get parent(): BushCategoryChannel | null; -} diff --git a/src/lib/extensions/discord.js/BushButtonInteraction.ts b/src/lib/extensions/discord.js/BushButtonInteraction.ts deleted file mode 100644 index 368d19d..0000000 --- a/src/lib/extensions/discord.js/BushButtonInteraction.ts +++ /dev/null @@ -1,30 +0,0 @@ -import type { BushClient, BushGuild, BushGuildMember, BushGuildTextBasedChannel, BushTextBasedChannel, BushUser } from '#lib'; -import type { APIInteractionGuildMember } from 'discord-api-types/v10'; -import { ButtonInteraction, type CacheType, type CacheTypeReducer } from 'discord.js'; -import type { RawMessageButtonInteractionData } from 'discord.js/typings/rawDataTypes'; - -/** - * Represents a button interaction. - */ -export class BushButtonInteraction<Cached extends CacheType = CacheType> extends ButtonInteraction<Cached> { - public declare member: CacheTypeReducer<Cached, BushGuildMember, APIInteractionGuildMember>; - public declare user: BushUser; - - public constructor(client: BushClient, data: RawMessageButtonInteractionData) { - super(client, data); - } -} - -export interface BushButtonInteraction<Cached extends CacheType = CacheType> extends ButtonInteraction<Cached> { - get channel(): CacheTypeReducer< - Cached, - BushGuildTextBasedChannel | null, - BushGuildTextBasedChannel | null, - BushGuildTextBasedChannel | null, - BushTextBasedChannel | null - >; - get guild(): CacheTypeReducer<Cached, BushGuild, null>; - inGuild(): this is BushButtonInteraction<'raw' | 'cached'>; - inCachedGuild(): this is BushButtonInteraction<'cached'>; - inRawGuild(): this is BushButtonInteraction<'raw'>; -} diff --git a/src/lib/extensions/discord.js/BushCategoryChannel.ts b/src/lib/extensions/discord.js/BushCategoryChannel.ts deleted file mode 100644 index a2e1e1c..0000000 --- a/src/lib/extensions/discord.js/BushCategoryChannel.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { - BushDMChannel, - BushGuildBasedChannel, - BushNewsChannel, - BushStageChannel, - BushTextBasedChannel, - BushTextChannel, - BushThreadChannel, - BushVoiceBasedChannel, - BushVoiceChannel, - type BushCategoryChannelChildManager, - type BushClient, - type BushGuild -} from '#lib'; -import { CategoryChannel } from 'discord.js'; -import { type RawGuildChannelData } from 'discord.js/typings/rawDataTypes'; - -/** - * Represents a guild category channel on Discord. - */ -export class BushCategoryChannel extends CategoryChannel { - public declare readonly client: BushClient; - public declare guild: BushGuild; - - public constructor(guild: BushGuild, data?: RawGuildChannelData, client?: BushClient, immediatePatch?: boolean) { - super(guild, data, client, immediatePatch); - } -} - -export interface BushCategoryChannel extends CategoryChannel { - get children(): BushCategoryChannelChildManager; - isText(): this is BushTextChannel; - isDM(): this is BushDMChannel; - isVoice(): this is BushVoiceChannel; - isCategory(): this is BushCategoryChannel; - isNews(): this is BushNewsChannel; - isThread(): this is BushThreadChannel; - isStage(): this is BushStageChannel; - isTextBased(): this is BushGuildBasedChannel & BushTextBasedChannel; - isVoiceBased(): this is BushVoiceBasedChannel; -} diff --git a/src/lib/extensions/discord.js/BushCategoryChannelChildManager.ts b/src/lib/extensions/discord.js/BushCategoryChannelChildManager.ts deleted file mode 100644 index 2b0d56b..0000000 --- a/src/lib/extensions/discord.js/BushCategoryChannelChildManager.ts +++ /dev/null @@ -1,44 +0,0 @@ -import type { - BushCategoryChannel, - BushGuild, - BushGuildChannelResolvable, - BushMappedChannelCategoryTypes, - BushNonCategoryGuildBasedChannel, - BushTextChannel -} from '#lib'; -import type { - CategoryChannelChildManager, - CategoryChannelType, - CategoryCreateChannelOptions, - DataManager, - Snowflake -} from 'discord.js'; - -export declare class BushCategoryChannelChildManager - extends DataManager<Snowflake, BushNonCategoryGuildBasedChannel, BushGuildChannelResolvable> - implements CategoryChannelChildManager -{ - private constructor(channel: BushCategoryChannel); - - /** - * The category channel this manager belongs to - */ - public channel: BushCategoryChannel; - - /** - * The guild this manager belongs to - */ - public readonly guild: BushGuild; - - /** - * Creates a new channel within this category. - * <info>You cannot create a channel of type {@link ChannelType.GuildCategory} inside a CategoryChannel.</info> - * @param name The name of the new channel - * @param options Options for creating the new channel - */ - public create<T extends CategoryChannelType>( - name: string, - options: CategoryCreateChannelOptions & { type: T } - ): Promise<BushMappedChannelCategoryTypes[T]>; - public create(name: string, options?: CategoryCreateChannelOptions): Promise<BushTextChannel>; -} diff --git a/src/lib/extensions/discord.js/BushChannel.ts b/src/lib/extensions/discord.js/BushChannel.ts deleted file mode 100644 index e66135c..0000000 --- a/src/lib/extensions/discord.js/BushChannel.ts +++ /dev/null @@ -1,39 +0,0 @@ -import type { - BushCategoryChannel, - BushClient, - BushDMChannel, - BushNewsChannel, - BushStageChannel, - BushTextBasedChannel, - BushTextChannel, - BushThreadChannel, - BushVoiceBasedChannel, - BushVoiceChannel -} from '#lib'; -import { Channel, ChannelType, PartialGroupDMChannel, type Snowflake } from 'discord.js'; -import type { RawChannelData } from 'discord.js/typings/rawDataTypes'; - -/** - * Represents any channel on Discord. - */ -export declare class BushChannel extends Channel { - public constructor(client: BushClient, data?: RawChannelData, immediatePatch?: boolean); - public get createdAt(): Date | null; - public get createdTimestamp(): number | null; - public deleted: boolean; - public id: Snowflake; - public get partial(): false; - public type: ChannelType; - public delete(): Promise<this>; - public fetch(force?: boolean): Promise<this>; - public isText(): this is BushTextChannel; - public isDM(): this is BushDMChannel; - public isDMBased(): this is PartialGroupDMChannel | BushDMChannel; - public isVoice(): this is BushVoiceChannel; - public isCategory(): this is BushCategoryChannel; - public isNews(): this is BushNewsChannel; - public isThread(): this is BushThreadChannel; - public isStage(): this is BushStageChannel; - public isTextBased(): this is BushTextBasedChannel; - public isVoiceBased(): this is BushVoiceBasedChannel; -} diff --git a/src/lib/extensions/discord.js/BushChannelManager.ts b/src/lib/extensions/discord.js/BushChannelManager.ts deleted file mode 100644 index ff93209..0000000 --- a/src/lib/extensions/discord.js/BushChannelManager.ts +++ /dev/null @@ -1,25 +0,0 @@ -import type { BushAnyChannel, BushChannelResolvable } from '#lib'; -import { CachedManager, ChannelManager, type Client, type FetchChannelOptions, type Snowflake } from 'discord.js'; -import type { RawChannelData } from 'discord.js/typings/rawDataTypes'; - -/** - * A manager of channels belonging to a client - */ -export declare class BushChannelManager - extends CachedManager<Snowflake, BushAnyChannel, BushChannelResolvable> - implements ChannelManager -{ - public constructor(client: Client, iterable: Iterable<RawChannelData>); - - /** - * Obtains a channel from Discord, or the channel cache if it's already available. - * @param id The channel's id - * @param options Additional options for this fetch - * @example - * // Fetch a channel by its id - * client.channels.fetch('222109930545610754') - * .then(channel => console.log(channel.name)) - * .catch(console.error); - */ - public fetch(id: Snowflake, options?: FetchChannelOptions): Promise<BushAnyChannel | null>; -} diff --git a/src/lib/extensions/discord.js/BushChatInputCommandInteraction.ts b/src/lib/extensions/discord.js/BushChatInputCommandInteraction.ts deleted file mode 100644 index 2491a68..0000000 --- a/src/lib/extensions/discord.js/BushChatInputCommandInteraction.ts +++ /dev/null @@ -1,49 +0,0 @@ -import type { - BushApplicationCommand, - BushClient, - BushGuild, - BushGuildEmoji, - BushGuildMember, - BushGuildTextBasedChannel, - BushNonThreadGuildBasedChannel, - BushRole, - BushTextBasedChannel, - BushUser -} from '#lib'; -import type { APIInteractionGuildMember } from 'discord-api-types/v10'; -import { ChatInputCommandInteraction, type CacheType, type CacheTypeReducer, type Invite, type Snowflake } from 'discord.js'; -import type { RawCommandInteractionData } from 'discord.js/typings/rawDataTypes'; - -export type BushGuildResolvable = - | BushGuild - | BushNonThreadGuildBasedChannel - | BushGuildMember - | BushGuildEmoji - | Invite - | BushRole - | Snowflake; - -/** - * Represents a command interaction. - */ -export class BushChatInputCommandInteraction<Cached extends CacheType = CacheType> extends ChatInputCommandInteraction<Cached> { - public declare readonly client: BushClient; - public declare member: CacheTypeReducer<Cached, BushGuildMember, APIInteractionGuildMember>; - public declare user: BushUser; - - public constructor(client: BushClient, data: RawCommandInteractionData) { - super(client, data); - } -} - -export interface BushChatInputCommandInteraction<Cached extends CacheType = CacheType> { - get command(): BushApplicationCommand | BushApplicationCommand<{ guild: BushGuildResolvable }> | null; - get channel(): CacheTypeReducer< - Cached, - BushGuildTextBasedChannel | null, - BushGuildTextBasedChannel | null, - BushGuildTextBasedChannel | null, - BushTextBasedChannel | null - >; - get guild(): CacheTypeReducer<Cached, BushGuild, null>; -} diff --git a/src/lib/extensions/discord.js/BushClientEvents.ts b/src/lib/extensions/discord.js/BushClientEvents.ts index e1a9954..22bae65 100644 --- a/src/lib/extensions/discord.js/BushClientEvents.ts +++ b/src/lib/extensions/discord.js/BushClientEvents.ts @@ -1,176 +1,29 @@ import type { BanResponse, - BushApplicationCommand, - BushButtonInteraction, - BushClient, - BushDMChannel, - BushGuild, - BushGuildBan, - BushGuildEmoji, - BushGuildMember, - BushGuildTextBasedChannel, - BushMessage, - BushMessageReaction, - BushModalSubmitInteraction, - BushNewsChannel, - BushNonThreadGuildBasedChannel, - BushPresence, - BushRole, - BushSelectMenuInteraction, - BushStageInstance, - BushTextBasedChannel, - BushTextChannel, - BushThreadChannel, - BushThreadMember, - BushUser, - BushVoiceState, - Guild, - GuildSettings, - PartialBushGuildMember, - PartialBushMessage, - PartialBushMessageReaction, - PartialBushUser + CommandMessage, + Guild as GuildDB, + GuildSettings } from '#lib'; import type { AkairoClientEvents } from 'discord-akairo'; import type { + ButtonInteraction, Collection, - GuildScheduledEvent, - Interaction, - Invite, + Guild, + GuildMember, + GuildTextBasedChannel, + Message, + ModalSubmitInteraction, + Role, + SelectMenuInteraction, Snowflake, - Sticker, - Typing + User } from 'discord.js'; export interface BushClientEvents extends AkairoClientEvents { - applicationCommandCreate: [command: BushApplicationCommand]; - applicationCommandDelete: [command: BushApplicationCommand]; - applicationCommandUpdate: [ - oldCommand: BushApplicationCommand | null, - newCommand: BushApplicationCommand - ]; - channelCreate: [channel: BushNonThreadGuildBasedChannel]; - channelDelete: [channel: BushDMChannel | BushNonThreadGuildBasedChannel]; - channelPinsUpdate: [channel: BushTextBasedChannel, date: Date]; - channelUpdate: [ - oldChannel: BushDMChannel | BushNonThreadGuildBasedChannel, - newChannel: BushDMChannel | BushNonThreadGuildBasedChannel - ]; - debug: [message: string]; - warn: [message: string]; - emojiCreate: [emoji: BushGuildEmoji]; - emojiDelete: [emoji: BushGuildEmoji]; - emojiUpdate: [oldEmoji: BushGuildEmoji, newEmoji: BushGuildEmoji]; - error: [error: Error]; - guildBanAdd: [ban: BushGuildBan]; - guildBanRemove: [ban: BushGuildBan]; - guildCreate: [guild: BushGuild]; - guildDelete: [guild: BushGuild]; - guildUnavailable: [guild: BushGuild]; - guildIntegrationsUpdate: [guild: BushGuild]; - guildMemberAdd: [member: BushGuildMember]; - guildMemberAvailable: [member: BushGuildMember | PartialBushGuildMember]; - guildMemberRemove: [member: BushGuildMember | PartialBushGuildMember]; - guildMembersChunk: [ - members: Collection<Snowflake, BushGuildMember>, - guild: BushGuild, - data: { - count: number; - index: number; - nonce: string | undefined; - } - ]; - guildMemberUpdate: [ - oldMember: BushGuildMember | PartialBushGuildMember, - newMember: BushGuildMember - ]; - guildUpdate: [oldGuild: BushGuild, newGuild: BushGuild]; - inviteCreate: [invite: Invite]; - inviteDelete: [invite: Invite]; - messageCreate: [message: BushMessage]; - messageDelete: [message: BushMessage | PartialBushMessage]; - messageReactionRemoveAll: [ - message: BushMessage | PartialBushMessage, - reactions: Collection<string, BushMessageReaction> - ]; - messageReactionRemoveEmoji: [ - reaction: BushMessageReaction | PartialBushMessageReaction - ]; - messageDeleteBulk: [ - messages: Collection<Snowflake, BushMessage | PartialBushMessage>, - channel: BushTextBasedChannel - ]; - messageReactionAdd: [ - reaction: BushMessageReaction | PartialBushMessageReaction, - user: BushUser | PartialBushUser - ]; - messageReactionRemove: [ - reaction: BushMessageReaction | PartialBushMessageReaction, - user: BushUser | PartialBushUser - ]; - messageUpdate: [ - oldMessage: BushMessage | PartialBushMessage, - newMessage: BushMessage | PartialBushMessage - ]; - presenceUpdate: [oldPresence: BushPresence | null, newPresence: BushPresence]; - ready: [client: BushClient<true>]; - invalidated: []; - roleCreate: [role: BushRole]; - roleDelete: [role: BushRole]; - roleUpdate: [oldRole: BushRole, newRole: BushRole]; - threadCreate: [thread: BushThreadChannel, newlyCreated: boolean]; - threadDelete: [thread: BushThreadChannel]; - threadListSync: [ - threads: Collection<Snowflake, BushThreadChannel>, - guild: BushGuild - ]; - threadMemberUpdate: [ - oldMember: BushThreadMember, - newMember: BushThreadMember - ]; - threadMembersUpdate: [ - oldMembers: Collection<Snowflake, BushThreadMember>, - newMembers: Collection<Snowflake, BushThreadMember>, - thread: BushThreadChannel - ]; - threadUpdate: [oldThread: BushThreadChannel, newThread: BushThreadChannel]; - typingStart: [typing: Typing]; - userUpdate: [oldUser: BushUser | PartialBushUser, newUser: BushUser]; - voiceStateUpdate: [oldState: BushVoiceState, newState: BushVoiceState]; - webhookUpdate: [channel: BushTextChannel]; - interactionCreate: [interaction: Interaction]; - shardError: [error: Error, shardId: number]; - shardReady: [shardId: number, unavailableGuilds: Set<Snowflake> | undefined]; - shardReconnecting: [shardId: number]; - shardResume: [shardId: number, replayedEvents: number]; - stageInstanceCreate: [stageInstance: BushStageInstance]; - stageInstanceUpdate: [ - oldStageInstance: BushStageInstance | null, - newStageInstance: BushStageInstance - ]; - stageInstanceDelete: [stageInstance: BushStageInstance]; - stickerCreate: [sticker: Sticker]; - stickerDelete: [sticker: Sticker]; - stickerUpdate: [oldSticker: Sticker, newSticker: Sticker]; - guildScheduledEventCreate: [guildScheduledEvent: GuildScheduledEvent]; - guildScheduledEventUpdate: [ - oldGuildScheduledEvent: GuildScheduledEvent, - newGuildScheduledEvent: GuildScheduledEvent - ]; - guildScheduledEventDelete: [guildScheduledEvent: GuildScheduledEvent]; - guildScheduledEventUserAdd: [ - guildScheduledEvent: GuildScheduledEvent, - user: BushUser - ]; - guildScheduledEventUserRemove: [ - guildScheduledEvent: GuildScheduledEvent, - user: BushUser - ]; - /* Custom */ bushBan: [ - victim: BushGuildMember | BushUser, - moderator: BushUser, - guild: BushGuild, + victim: GuildMember | User, + moderator: User, + guild: Guild, reason: string | undefined, caseID: string, duration: number, @@ -178,29 +31,29 @@ export interface BushClientEvents extends AkairoClientEvents { evidence?: string ]; bushBlock: [ - victim: BushGuildMember, - moderator: BushUser, - guild: BushGuild, + victim: GuildMember, + moderator: User, + guild: Guild, reason: string | undefined, caseID: string, duration: number, dmSuccess: boolean, - channel: BushGuildTextBasedChannel, + channel: GuildTextBasedChannel, evidence?: string ]; bushKick: [ - victim: BushGuildMember, - moderator: BushUser, - guild: BushGuild, + victim: GuildMember, + moderator: User, + guild: Guild, reason: string | undefined, caseID: string, dmSuccess: boolean, evidence?: string ]; bushMute: [ - victim: BushGuildMember, - moderator: BushUser, - guild: BushGuild, + victim: GuildMember, + moderator: User, + guild: Guild, reason: string | undefined, caseID: string, duration: number, @@ -208,43 +61,43 @@ export interface BushClientEvents extends AkairoClientEvents { evidence?: string ]; bushPunishRole: [ - victim: BushGuildMember, - moderator: BushUser, - guild: BushGuild, + victim: GuildMember, + moderator: User, + guild: Guild, reason: string | undefined, caseID: string, duration: number, - role: BushRole, + role: Role, evidence?: string ]; bushPunishRoleRemove: [ - victim: BushGuildMember, - moderator: BushUser, - guild: BushGuild, + victim: GuildMember, + moderator: User, + guild: Guild, reason: string | undefined, caseID: string, - role: BushRole, + role: Role, evidence?: string ]; bushPurge: [ - moderator: BushUser, - guild: BushGuild, - channel: BushTextChannel | BushNewsChannel | BushThreadChannel, - messages: Collection<Snowflake, BushMessage> + moderator: User, + guild: Guild, + channel: GuildTextBasedChannel, + messages: Collection<Snowflake, Message> ]; bushRemoveTimeout: [ - victim: BushGuildMember, - moderator: BushUser, - guild: BushGuild, + victim: GuildMember, + moderator: User, + guild: Guild, reason: string | undefined, caseID: string, dmSuccess: boolean, evidence?: string ]; bushTimeout: [ - victim: BushGuildMember, - moderator: BushUser, - guild: BushGuild, + victim: GuildMember, + moderator: User, + guild: Guild, reason: string | undefined, caseID: string, duration: number, @@ -252,35 +105,35 @@ export interface BushClientEvents extends AkairoClientEvents { evidence?: string ]; bushUnban: [ - victim: BushUser, - moderator: BushUser, - guild: BushGuild, + victim: User, + moderator: User, + guild: Guild, reason: string | undefined, caseID: string, dmSuccess: boolean, evidence?: string ]; bushUnblock: [ - victim: BushGuildMember | BushUser, - moderator: BushUser, - guild: BushGuild, + victim: GuildMember | User, + moderator: User, + guild: Guild, reason: string | undefined, caseID: string, dmSuccess: boolean, - channel: BushGuildTextBasedChannel, + channel: GuildTextBasedChannel, evidence?: string ]; bushUnmute: [ - victim: BushGuildMember, - moderator: BushUser, - guild: BushGuild, + victim: GuildMember, + moderator: User, + guild: Guild, reason: string | undefined, caseID: string, dmSuccess: boolean, evidence?: string ]; bushUpdateModlog: [ - moderator: BushGuildMember, + moderator: GuildMember, modlogID: string, key: 'evidence' | 'hidden', oldModlog: string | boolean, @@ -288,55 +141,55 @@ export interface BushClientEvents extends AkairoClientEvents { ]; bushUpdateSettings: [ setting: Setting, - guild: BushGuild, - oldValue: Guild[Setting], - newValue: Guild[Setting], - moderator?: BushGuildMember + guild: Guild, + oldValue: GuildDB[Setting], + newValue: GuildDB[Setting], + moderator?: GuildMember ]; bushWarn: [ - victim: BushGuildMember, - moderator: BushUser, - guild: BushGuild, + victim: GuildMember, + moderator: User, + guild: Guild, reason: string | undefined, caseID: string, dmSuccess: boolean, evidence?: string ]; bushLevelUpdate: [ - member: BushGuildMember, + member: GuildMember, oldLevel: number, newLevel: number, currentXp: number, - message: BushMessage & { guild: BushGuild } + message: CommandMessage ]; bushLockdown: [ - moderator: BushGuildMember, + moderator: GuildMember, reason: string | undefined, channelsSuccessMap: Collection<Snowflake, boolean>, all?: boolean ]; bushUnlockdown: [ - moderator: BushGuildMember, + moderator: GuildMember, reason: string | undefined, channelsSuccessMap: Collection<Snowflake, boolean>, all?: boolean ]; massBan: [ - moderator: BushGuildMember, - guild: BushGuild, + moderator: GuildMember, + guild: Guild, reason: string | undefined, results: Collection<Snowflake, BanResponse> ]; massEvidence: [ - moderator: BushGuildMember, - guild: BushGuild, + moderator: GuildMember, + guild: Guild, evidence: string, lines: string[] ]; /* components */ - button: [button: BushButtonInteraction]; - selectMenu: [selectMenu: BushSelectMenuInteraction]; - modal: [modal: BushModalSubmitInteraction]; + button: [button: ButtonInteraction]; + selectMenu: [selectMenu: SelectMenuInteraction]; + modal: [modal: ModalSubmitInteraction]; } type Setting = diff --git a/src/lib/extensions/discord.js/BushClientUser.ts b/src/lib/extensions/discord.js/BushClientUser.ts deleted file mode 100644 index cee9808..0000000 --- a/src/lib/extensions/discord.js/BushClientUser.ts +++ /dev/null @@ -1,98 +0,0 @@ -import type { - ActivityOptions, - Base64Resolvable, - BufferResolvable, - ClientPresence, - ClientUser, - ClientUserEditData, - PresenceData, - PresenceStatusData -} from 'discord.js'; -import { BushUser } from './BushUser.js'; - -/** - * Represents the logged in client's Discord user. - */ -export declare class BushClientUser extends BushUser implements ClientUser { - /** - * If the bot's {@link ClientApplication.owner Owner} has MFA enabled on their account - */ - public mfaEnabled: boolean; - - /** - * Represents the client user's presence - */ - public readonly presence: ClientPresence; - - /** - * Whether or not this account has been verified - */ - public verified: boolean; - - /** - * Edits the logged in client. - * @param data The new data - */ - public edit(data: ClientUserEditData): Promise<this>; - - /** - * Sets the activity the client user is playing. - * @param name Activity being played, or options for setting the activity - * @param options Options for setting the activity - * @example - * // Set the client user's activity - * client.user.setActivity('discord.js', { type: 'WATCHING' }); - */ - public setActivity(options?: ActivityOptions): ClientPresence; - public setActivity(name: string, options?: ActivityOptions): ClientPresence; - - /** - * Sets/removes the AFK flag for the client user. - * @param afk Whether or not the user is AFK - * @param shardId Shard Id(s) to have the AFK flag set on - */ - public setAFK(afk: boolean, shardId?: number | number[]): ClientPresence; - - /** - * Sets the avatar of the logged in client. - * @param avatar The new avatar - * @example - * // Set avatar - * client.user.setAvatar('./avatar.png') - * .then(user => console.log(`New avatar set!`)) - * .catch(console.error); - */ - public setAvatar(avatar: BufferResolvable | Base64Resolvable | null): Promise<this>; - - /** - * Sets the full presence of the client user. - * @param data Data for the presence - * @example - * // Set the client user's presence - * client.user.setPresence({ activities: [{ name: 'with discord.js' }], status: 'idle' }); - */ - public setPresence(data: PresenceData): ClientPresence; - - /** - * Sets the status of the client user. - * @param status Status to change to - * @param shardId Shard id(s) to have the activity set on - * @example - * // Set the client user's status - * client.user.setStatus('idle'); - */ - public setStatus(status: PresenceStatusData, shardId?: number | number[]): ClientPresence; - - /** - * Sets the username of the logged in client. - * <info>Changing usernames in Discord is heavily rate limited, with only 2 requests - * every hour. Use this sparingly!</info> - * @param username The new username - * @example - * // Set username - * client.user.setUsername('discordjs') - * .then(user => console.log(`My new username is ${user.username}`)) - * .catch(console.error); - */ - public setUsername(username: string): Promise<this>; -} diff --git a/src/lib/extensions/discord.js/BushDMChannel.ts b/src/lib/extensions/discord.js/BushDMChannel.ts deleted file mode 100644 index 87382ec..0000000 --- a/src/lib/extensions/discord.js/BushDMChannel.ts +++ /dev/null @@ -1,45 +0,0 @@ -import type { - BushCategoryChannel, - BushClient, - BushMessageManager, - BushNewsChannel, - BushStageChannel, - BushTextBasedChannel, - BushTextChannel, - BushThreadChannel, - BushUser, - BushVoiceBasedChannel, - BushVoiceChannel -} from '#lib'; -import { DMChannel, PartialGroupDMChannel, type Partialize } from 'discord.js'; -import type { RawDMChannelData } from 'discord.js/typings/rawDataTypes'; - -/** - * Represents a direct message channel between two users. - */ -export class BushDMChannel extends DMChannel { - public declare readonly client: BushClient; - public declare messages: BushMessageManager; - - public constructor(client: BushClient, data?: RawDMChannelData) { - super(client, data); - } -} - -export interface BushDMChannel extends DMChannel { - get recipient(): BushUser | null; - isText(): this is BushTextChannel; - isDM(): this is BushDMChannel; - isDMBased(): this is PartialGroupDMChannel | BushDMChannel; - isVoice(): this is BushVoiceChannel; - isCategory(): this is BushCategoryChannel; - isNews(): this is BushNewsChannel; - isThread(): this is BushThreadChannel; - isStage(): this is BushStageChannel; - isTextBased(): this is BushTextBasedChannel; - isVoiceBased(): this is BushVoiceBasedChannel; -} - -export interface PartialBushDMChannel extends Partialize<BushDMChannel, null, null, 'lastMessageId'> { - lastMessageId: undefined; -} diff --git a/src/lib/extensions/discord.js/BushEmoji.ts b/src/lib/extensions/discord.js/BushEmoji.ts deleted file mode 100644 index 9e42e5d..0000000 --- a/src/lib/extensions/discord.js/BushEmoji.ts +++ /dev/null @@ -1,14 +0,0 @@ -import type { BushClient } from '#lib'; -import { Emoji } from 'discord.js'; -import type { RawEmojiData } from 'discord.js/typings/rawDataTypes'; - -/** - * Represents an emoji, see {@link GuildEmoji} and {@link ReactionEmoji}. - */ -export class BushEmoji extends Emoji { - public declare readonly client: BushClient; - - public constructor(client: BushClient, emoji: RawEmojiData) { - super(client, emoji); - } -} diff --git a/src/lib/extensions/discord.js/BushGuildApplicationCommandManager.ts b/src/lib/extensions/discord.js/BushGuildApplicationCommandManager.ts deleted file mode 100644 index ba9db66..0000000 --- a/src/lib/extensions/discord.js/BushGuildApplicationCommandManager.ts +++ /dev/null @@ -1,114 +0,0 @@ -/* eslint-disable @typescript-eslint/ban-types */ -import { - BushApplicationCommandManager, - type BushApplicationCommand, - type BushApplicationCommandResolvable, - type BushClient, - type BushGuild -} from '#lib'; -import type { ApplicationCommandData, BaseFetchOptions, Collection, Snowflake } from 'discord.js'; -import type { RawApplicationCommandData } from 'discord.js/typings/rawDataTypes'; - -/** - * An extension for guild-specific application commands. - */ -export declare class BushGuildApplicationCommandManager extends BushApplicationCommandManager< - BushApplicationCommand, - {}, - BushGuild -> { - public constructor(guild: BushGuild, iterable?: Iterable<RawApplicationCommandData>); - public declare readonly client: BushClient; - - /** - * The guild that this manager belongs to - */ - public guild: BushGuild; - - /** - * Creates an application command. - * @param command The command - * @param guildId The guild's id to create this command in, - * ignored when using a {@link GuildApplicationCommandManager} - * @example - * // Create a new command - * client.application.commands.create({ - * name: 'test', - * description: 'A test command', - * }) - * .then(console.log) - * .catch(console.error); - */ - public create(command: BushApplicationCommandResolvable): Promise<BushApplicationCommand>; - - /** - * Deletes an application command. - * @param command The command to delete - * @param guildId The guild's id where the command is registered, - * ignored when using a {@link GuildApplicationCommandManager} - * @example - * // Delete a command - * guild.commands.delete('123456789012345678') - * .then(console.log) - * .catch(console.error); - */ - public delete(command: BushApplicationCommandResolvable): Promise<BushApplicationCommand | null>; - - /** - * Edits an application command. - * @param command The command to edit - * @param data The data to update the command with - * @param guildId The guild's id where the command registered, - * ignored when using a {@link GuildApplicationCommandManager} - * @example - * // Edit an existing command - * client.application.commands.edit('123456789012345678', { - * description: 'New description', - * }) - * .then(console.log) - * .catch(console.error); - */ - public edit(command: BushApplicationCommandResolvable, data: ApplicationCommandData): Promise<BushApplicationCommand>; - - /** - * Obtains one or multiple application commands from Discord, or the cache if it's already available. - * @param id The application command's id - * @param options Additional options for this fetch - * @example - * // Fetch a single command - * client.application.commands.fetch('123456789012345678') - * .then(command => console.log(`Fetched command ${command.name}`)) - * .catch(console.error); - * @example - * // Fetch all commands - * guild.commands.fetch() - * .then(commands => console.log(`Fetched ${commands.size} commands`)) - * .catch(console.error); - */ - public fetch(id: Snowflake, options?: BaseFetchOptions): Promise<BushApplicationCommand>; - public fetch(options: BaseFetchOptions): Promise<Collection<Snowflake, BushApplicationCommand>>; - public fetch(id?: undefined, options?: BaseFetchOptions): Promise<Collection<Snowflake, BushApplicationCommand>>; - - /** - * Sets all the commands for this application or guild. - * @param commands The commands - * @param guildId The guild's id to create the commands in, - * ignored when using a {@link GuildApplicationCommandManager} - * @example - * // Set all commands to just this one - * client.application.commands.set([ - * { - * name: 'test', - * description: 'A test command', - * }, - * ]) - * .then(console.log) - * .catch(console.error); - * @example - * // Remove all commands - * guild.commands.set([]) - * .then(console.log) - * .catch(console.error); - */ - public set(commands: ApplicationCommandData[]): Promise<Collection<Snowflake, BushApplicationCommand>>; -} diff --git a/src/lib/extensions/discord.js/BushGuildBan.ts b/src/lib/extensions/discord.js/BushGuildBan.ts deleted file mode 100644 index d56c531..0000000 --- a/src/lib/extensions/discord.js/BushGuildBan.ts +++ /dev/null @@ -1,15 +0,0 @@ -import type { BushClient, BushGuild, BushUser } from '#lib'; -import { GuildBan } from 'discord.js'; -import type { RawGuildBanData } from 'discord.js/typings/rawDataTypes'; - -/** - * Represents a ban in a guild on Discord. - */ -export declare class BushGuildBan extends GuildBan { - public constructor(client: BushClient, data: RawGuildBanData, guild: BushGuild); - public guild: BushGuild; - public user: BushUser; - public get partial(): boolean; - public reason?: string | null; - public fetch(force?: boolean): Promise<BushGuildBan>; -} diff --git a/src/lib/extensions/discord.js/BushGuildChannel.ts b/src/lib/extensions/discord.js/BushGuildChannel.ts deleted file mode 100644 index 62bf05a..0000000 --- a/src/lib/extensions/discord.js/BushGuildChannel.ts +++ /dev/null @@ -1,47 +0,0 @@ -import type { - BushCategoryChannel, - BushClient, - BushDMChannel, - BushGuild, - BushGuildBasedChannel, - BushNewsChannel, - BushStageChannel, - BushTextBasedChannel, - BushTextChannel, - BushThreadChannel, - BushVoiceBasedChannel, - BushVoiceChannel -} from '#lib'; -import { GuildChannel, PartialGroupDMChannel } from 'discord.js'; -import type { RawGuildChannelData } from 'discord.js/typings/rawDataTypes'; - -/** - * Represents a guild channel from any of the following: - * - {@link BushTextChannel} - * - {@link BushVoiceChannel} - * - {@link BushCategoryChannel} - * - {@link BushNewsChannel} - * - {@link BushStoreChannel} - * - {@link BushStageChannel} - */ -export class BushGuildChannel extends GuildChannel { - public declare readonly client: BushClient; - public declare guild: BushGuild; - - public constructor(guild: BushGuild, data?: RawGuildChannelData, client?: BushClient, immediatePatch?: boolean) { - super(guild, data, client, immediatePatch); - } -} - -export interface BushGuildChannel extends GuildChannel { - isText(): this is BushTextChannel; - isDMBased(): this is PartialGroupDMChannel | BushDMChannel; - isDM(): this is BushDMChannel; - isVoice(): this is BushVoiceChannel; - isCategory(): this is BushCategoryChannel; - isNews(): this is BushNewsChannel; - isThread(): this is BushThreadChannel; - isStage(): this is BushStageChannel; - isTextBased(): this is BushGuildBasedChannel & BushTextBasedChannel; - isVoiceBased(): this is BushVoiceBasedChannel; -} diff --git a/src/lib/extensions/discord.js/BushGuildChannelManager.ts b/src/lib/extensions/discord.js/BushGuildChannelManager.ts deleted file mode 100644 index 4048b98..0000000 --- a/src/lib/extensions/discord.js/BushGuildChannelManager.ts +++ /dev/null @@ -1,183 +0,0 @@ -import type { - BushFetchedThreads, - BushGuild, - BushGuildBasedChannel, - BushGuildChannel, - BushMappedGuildChannelTypes, - BushNonThreadGuildBasedChannel, - BushTextChannel -} from '#lib'; -import { - CachedManager, - ChannelData, - ChannelWebhookCreateOptions, - SetChannelPositionOptions, - Webhook, - type BaseFetchOptions, - type ChannelPosition, - type Collection, - type GuildChannelCreateOptions, - type GuildChannelManager, - type GuildChannelResolvable, - type GuildChannelTypes, - type Snowflake -} from 'discord.js'; -import type { RawGuildChannelData } from 'discord.js/typings/rawDataTypes'; - -/** - * Manages API methods for GuildChannels and stores their cache. - */ -export declare class BushGuildChannelManager - extends CachedManager<Snowflake, BushGuildBasedChannel, GuildChannelResolvable> - implements GuildChannelManager -{ - public constructor(guild: BushGuild, iterable?: Iterable<RawGuildChannelData>); - - /** - * The number of channels in this managers cache excluding thread channels - * that do not count towards a guild's maximum channels restriction. - */ - public readonly channelCountWithoutThreads: number; - - /** - * The guild this Manager belongs to - */ - public guild: BushGuild; - - /** - * Creates a new channel in the guild. - * @param name The name of the new channel - * @param options Options for creating the new channel - * @example - * // Create a new text channel - * guild.channels.create('new-general', { reason: 'Needed a cool new channel' }) - * .then(console.log) - * .catch(console.error); - * @example - * // Create a new channel with permission overwrites - * guild.channels.create('new-voice', { - * type: 'GuildVoice', - * permissionOverwrites: [ - * { - * id: message.author.id, - * deny: [PermissionFlagsBits.ViewChannel], - * }, - * ], - * }) - */ - public create<T extends GuildChannelTypes>( - name: string, - options: GuildChannelCreateOptions & { type: T } - ): Promise<BushMappedGuildChannelTypes[T]>; - public create(name: string, options?: GuildChannelCreateOptions): Promise<BushTextChannel>; - - /** - * Creates a webhook for the channel. - * @param channel The channel to create the webhook for - * @param name The name of the webhook - * @param options Options for creating the webhook - * @returns Returns the created Webhook - * @example - * // Create a webhook for the current channel - * guild.channels.createWebhook('222197033908436994', 'Snek', { - * avatar: 'https://i.imgur.com/mI8XcpG.jpg', - * reason: 'Needed a cool new Webhook' - * }) - * .then(console.log) - * .catch(console.error) - */ - public createWebhook(channel: GuildChannelResolvable, name: string, options?: ChannelWebhookCreateOptions): Promise<Webhook>; - - /** - * Edits the channel. - * @param channel The channel to edit - * @param data The new data for the channel - * @param reason Reason for editing this channel - * @example - * // Edit a channel - * guild.channels.edit('222197033908436994', { name: 'new-channel' }) - * .then(console.log) - * .catch(console.error); - */ - public edit(channel: GuildChannelResolvable, data: ChannelData, reason?: string): Promise<BushGuildChannel>; - - /** - * Obtains one or more guild channels from Discord, or the channel cache if they're already available. - * @param id The channel's id - * @param options Additional options for this fetch - * @example - * // Fetch all channels from the guild (excluding threads) - * message.guild.channels.fetch() - * .then(channels => console.log(`There are ${channels.size} channels.`)) - * .catch(console.error); - * @example - * // Fetch a single channel - * message.guild.channels.fetch('222197033908436994') - * .then(channel => console.log(`The channel name is: ${channel.name}`)) - * .catch(console.error); - */ - public fetch(id: Snowflake, options?: BaseFetchOptions): Promise<BushNonThreadGuildBasedChannel | null>; - public fetch(id?: undefined, options?: BaseFetchOptions): Promise<Collection<Snowflake, BushNonThreadGuildBasedChannel>>; - - /** - * Fetches all webhooks for the channel. - * @param channel The channel to fetch webhooks for - * @example - * // Fetch webhooks - * guild.channels.fetchWebhooks('769862166131245066') - * .then(hooks => console.log(`This channel has ${hooks.size} hooks`)) - * .catch(console.error); - */ - public fetchWebhooks(channel: GuildChannelResolvable): Promise<Collection<Snowflake, Webhook>>; - - /** - * Sets a new position for the guild channel. - * @param channel The channel to set the position for - * @param position The new position for the guild channel - * @param options Options for setting position - * @example - * // Set a new channel position - * guild.channels.setPosition('222078374472843266', 2) - * .then(newChannel => console.log(`Channel's new position is ${newChannel.position}`)) - * .catch(console.error); - */ - public setPosition( - channel: GuildChannelResolvable, - position: number, - options?: SetChannelPositionOptions - ): Promise<BushGuildChannel>; - - /** - * Batch-updates the guild's channels' positions. - * <info>Only one channel's parent can be changed at a time</info> - * @param channelPositions Channel positions to update - * @example - * guild.channels.setPositions([{ channel: channelId, position: newChannelIndex }]) - * .then(guild => console.log(`Updated channel positions for ${guild}`)) - * .catch(console.error); - */ - public setPositions(channelPositions: readonly ChannelPosition[]): Promise<BushGuild>; - - /** - * Obtains all active thread channels in the guild from Discord - * @param {} [cache=true] Whether to cache the fetched data - * @example - * // Fetch all threads from the guild - * message.guild.channels.fetchActiveThreads() - * .then(fetched => console.log(`There are ${fetched.threads.size} threads.`)) - * .catch(console.error); - */ - public fetchActiveThreads(cache?: boolean): Promise<BushFetchedThreads>; - - /** - * Deletes the channel. - * @param channel The channel to delete - * @param reason Reason for deleting this channel - * @example - * // Delete the channel - * guild.channels.delete('858850993013260338', 'making room for new channels') - * .then(console.log) - * .catch(console.error); - */ - public delete(channel: GuildChannelResolvable, reason?: string): Promise<void>; -} diff --git a/src/lib/extensions/discord.js/BushGuildEmoji.ts b/src/lib/extensions/discord.js/BushGuildEmoji.ts deleted file mode 100644 index 9b931bb..0000000 --- a/src/lib/extensions/discord.js/BushGuildEmoji.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { BushClient, BushGuild, BushGuildEmojiRoleManager, BushUser } from '#lib'; -import { GuildEmoji } from 'discord.js'; -import type { RawGuildEmojiData } from 'discord.js/typings/rawDataTypes'; - -/** - * Represents a custom emoji. - */ -export class BushGuildEmoji extends GuildEmoji { - public declare readonly client: BushClient; - public declare guild: BushGuild; - public declare author: BushUser | null; - - public constructor(client: BushClient, data: RawGuildEmojiData, guild: BushGuild) { - super(client, data, guild); - } -} - -export interface BushGuildEmoji extends GuildEmoji { - get roles(): BushGuildEmojiRoleManager; -} diff --git a/src/lib/extensions/discord.js/BushGuildEmojiRoleManager.ts b/src/lib/extensions/discord.js/BushGuildEmojiRoleManager.ts deleted file mode 100644 index 8b069ae..0000000 --- a/src/lib/extensions/discord.js/BushGuildEmojiRoleManager.ts +++ /dev/null @@ -1,55 +0,0 @@ -import type { BushClient, BushGuild, BushGuildEmoji, BushRole, BushRoleResolvable } from '#lib'; -import { DataManager, GuildEmojiRoleManager, type Collection, type Snowflake } from 'discord.js'; - -/** - * Manages API methods for roles belonging to emojis and stores their cache. - */ -export declare class BushGuildEmojiRoleManager - extends DataManager<Snowflake, BushRole, BushRoleResolvable> - implements GuildEmojiRoleManager -{ - public constructor(emoji: BushGuildEmoji); - public declare readonly client: BushClient; - - /** - * The emoji belonging to this manager - */ - public emoji: BushGuildEmoji; - - /** - * The guild belonging to this manager - */ - public guild: BushGuild; - - /** - * Adds a role (or multiple roles) to the list of roles that can use this emoji. - * @param roleOrRoles The role or roles to add - */ - public add( - roleOrRoles: BushRoleResolvable | readonly BushRoleResolvable[] | Collection<Snowflake, BushRole> - ): Promise<BushGuildEmoji>; - - /** - * Sets the role(s) that can use this emoji. - * @param roles The roles or role ids to apply - * @example - * // Set the emoji's roles to a single role - * guildEmoji.roles.set(['391156570408615936']) - * .then(console.log) - * .catch(console.error); - * @example - * // Remove all roles from an emoji - * guildEmoji.roles.set([]) - * .then(console.log) - * .catch(console.error); - */ - public set(roles: readonly BushRoleResolvable[] | Collection<Snowflake, BushRole>): Promise<BushGuildEmoji>; - - /** - * Removes a role (or multiple roles) from the list of roles that can use this emoji. - * @param roleOrRoles The role or roles to remove - */ - public remove( - roleOrRoles: BushRoleResolvable | readonly BushRoleResolvable[] | Collection<Snowflake, BushRole> - ): Promise<BushGuildEmoji>; -} diff --git a/src/lib/extensions/discord.js/BushGuildManager.ts b/src/lib/extensions/discord.js/BushGuildManager.ts deleted file mode 100644 index 41618e3..0000000 --- a/src/lib/extensions/discord.js/BushGuildManager.ts +++ /dev/null @@ -1,35 +0,0 @@ -import type { BushClient, BushGuild, BushGuildResolvable } from '#lib'; -import { - CachedManager, - GuildManager, - type Collection, - type FetchGuildOptions, - type FetchGuildsOptions, - type GuildCreateOptions, - type OAuth2Guild, - type Snowflake -} from 'discord.js'; -import { type RawGuildData } from 'discord.js/typings/rawDataTypes'; - -/** - * Manages API methods for Guilds and stores their cache. - */ -export declare class BushGuildManager extends CachedManager<Snowflake, BushGuild, BushGuildResolvable> implements GuildManager { - public constructor(client: BushClient, iterable?: Iterable<RawGuildData>); - - /** - * Creates a guild. - * <warn>This is only available to bots in fewer than 10 guilds.</warn> - * @param name The name of the guild - * @param options Options for creating the guild - * @returns The guild that was created - */ - public create(name: string, options?: GuildCreateOptions): Promise<BushGuild>; - - /** - * Obtains one or multiple guilds from Discord, or the guild cache if it's already available. - * @param options The guild's id or options - */ - public fetch(options: Snowflake | FetchGuildOptions): Promise<BushGuild>; - public fetch(options?: FetchGuildsOptions): Promise<Collection<Snowflake, OAuth2Guild>>; -} diff --git a/src/lib/extensions/discord.js/BushGuildMemberManager.ts b/src/lib/extensions/discord.js/BushGuildMemberManager.ts deleted file mode 100644 index b0368b5..0000000 --- a/src/lib/extensions/discord.js/BushGuildMemberManager.ts +++ /dev/null @@ -1,177 +0,0 @@ -import type { BushClient, BushGuild, BushGuildMember, BushGuildMemberResolvable, BushUser, BushUserResolvable } from '#lib'; -import { - CachedManager, - GuildMemberManager, - type AddGuildMemberOptions, - type BanOptions, - type Collection, - type FetchMemberOptions, - type FetchMembersOptions, - type GuildListMembersOptions, - type GuildMemberEditData, - type GuildPruneMembersOptions, - type GuildSearchMembersOptions, - type Snowflake -} from 'discord.js'; -import type { RawGuildMemberData } from 'discord.js/typings/rawDataTypes'; - -/** - * Manages API methods for GuildMembers and stores their cache. - */ -export declare class BushGuildMemberManager - extends CachedManager<Snowflake, BushGuildMember, BushGuildMemberResolvable> - implements GuildMemberManager -{ - public constructor(guild: BushGuild, iterable?: Iterable<RawGuildMemberData>); - public declare readonly client: BushClient; - - /** - * The guild this manager belongs to - */ - public guild: BushGuild; - - /** - * Adds a user to the guild using OAuth2. Requires the `PermissionFlagsBits.CreateInstantInvite` permission. - * @param user The user to add to the guild - * @param options Options for adding the user to the guild - */ - public add( - user: BushUserResolvable, - options: AddGuildMemberOptions & { fetchWhenExisting: false } - ): Promise<BushGuildMember | null>; - public add(user: BushUserResolvable, options: AddGuildMemberOptions): Promise<BushGuildMember>; - - /** - * Bans a user from the guild. - * @param user The user to ban - * @param options Options for the ban - * @returns Result object will be resolved as specifically as possible. - * If the GuildMember cannot be resolved, the User will instead be attempted to be resolved. If that also cannot - * be resolved, the user id will be the result. - * Internally calls the GuildBanManager#create method. - * @example - * // Ban a user by id (or with a user/guild member object) - * guild.members.ban('84484653687267328') - * .then(banInfo => console.log(`Banned ${banInfo.user?.tag ?? banInfo.tag ?? banInfo}`)) - * .catch(console.error); - */ - public ban(user: BushUserResolvable, options?: BanOptions): Promise<BushGuildMember | BushUser | Snowflake>; - - /** - * Edits a member of the guild. - * <info>The user must be a member of the guild</info> - * @param user The member to edit - * @param data The data to edit the member with - * @param reason Reason for editing this user - */ - public edit(user: BushUserResolvable, data: GuildMemberEditData, reason?: string): Promise<void>; - - /** - * Fetches member(s) from Discord, even if they're offline. - * @param options If a UserResolvable, the user to fetch. - * If undefined, fetches all members. - * If a query, it limits the results to users with similar usernames. - * @example - * // Fetch all members from a guild - * guild.members.fetch() - * .then(console.log) - * .catch(console.error); - * @example - * // Fetch a single member - * guild.members.fetch('66564597481480192') - * .then(console.log) - * .catch(console.error); - * @example - * // Fetch a single member without checking cache - * guild.members.fetch({ user, force: true }) - * .then(console.log) - * .catch(console.error) - * @example - * // Fetch a single member without caching - * guild.members.fetch({ user, cache: false }) - * .then(console.log) - * .catch(console.error); - * @example - * // Fetch by an array of users including their presences - * guild.members.fetch({ user: ['66564597481480192', '191615925336670208'], withPresences: true }) - * .then(console.log) - * .catch(console.error); - * @example - * // Fetch by query - * guild.members.fetch({ query: 'hydra', limit: 1 }) - * .then(console.log) - * .catch(console.error); - */ - public fetch( - options: BushUserResolvable | FetchMemberOptions | (FetchMembersOptions & { user: BushUserResolvable }) - ): Promise<BushGuildMember>; - public fetch(options?: FetchMembersOptions): Promise<Collection<Snowflake, BushGuildMember>>; - - /** - * Kicks a user from the guild. - * <info>The user must be a member of the guild</info> - * @param user The member to kick - * @param reason Reason for kicking - * @returns Result object will be resolved as specifically as possible. - * If the GuildMember cannot be resolved, the User will instead be attempted to be resolved. If that also cannot - * be resolved, the user's id will be the result. - * @example - * // Kick a user by id (or with a user/guild member object) - * guild.members.kick('84484653687267328') - * .then(banInfo => console.log(`Kicked ${banInfo.user?.tag ?? banInfo.tag ?? banInfo}`)) - * .catch(console.error); - */ - public kick(user: BushUserResolvable, reason?: string): Promise<BushGuildMember | BushUser | Snowflake>; - - /** - * Lists up to 1000 members of the guild. - * @param options Options for listing members - */ - public list(options?: GuildListMembersOptions): Promise<Collection<Snowflake, BushGuildMember>>; - - /** - * Prunes members from the guild based on how long they have been inactive. - * @param options Options for pruning - * @returns The number of members that were/will be kicked - * @example - * // See how many members will be pruned - * guild.members.prune({ dry: true }) - * .then(pruned => console.log(`This will prune ${pruned} people!`)) - * .catch(console.error); - * @example - * // Actually prune the members - * guild.members.prune({ days: 1, reason: 'too many people!' }) - * .then(pruned => console.log(`I just pruned ${pruned} people!`)) - * .catch(console.error); - * @example - * // Include members with a specified role - * guild.members.prune({ days: 7, roles: ['657259391652855808'] }) - * .then(pruned => console.log(`I just pruned ${pruned} people!`)) - * .catch(console.error); - */ - public prune(options: GuildPruneMembersOptions & { dry?: false; count: false }): Promise<null>; - public prune(options?: GuildPruneMembersOptions): Promise<number>; - - /** - * Searches for members in the guild based on a query. - * @param options Options for searching members - */ - public search(options: GuildSearchMembersOptions): Promise<Collection<Snowflake, BushGuildMember>>; - - /** - * Unbans a user from the guild. Internally calls the {@link GuildBanManager.remove} method. - * @param user The user to unban - * @param reason Reason for unbanning user - * @returns The user that was unbanned - * @example - * // Unban a user by id (or with a user/guild member object) - * guild.members.unban('84484653687267328') - * .then(user => console.log(`Unbanned ${user.username} from ${guild.name}`)) - * .catch(console.error); - */ - public unban(user: BushUserResolvable, reason?: string): Promise<BushUser | null>; -} - -export interface BushGuildMemberManager extends CachedManager<Snowflake, BushGuildMember, BushGuildMemberResolvable> { - get me(): BushGuildMember | null; -} diff --git a/src/lib/extensions/discord.js/BushMessage.ts b/src/lib/extensions/discord.js/BushMessage.ts deleted file mode 100644 index 48e1792..0000000 --- a/src/lib/extensions/discord.js/BushMessage.ts +++ /dev/null @@ -1,63 +0,0 @@ -import type { - BushClient, - BushCommandUtil, - BushGuild, - BushGuildMember, - BushGuildTextBasedChannel, - BushMessageReaction, - BushTextBasedChannel, - BushThreadChannel, - BushUser -} from '#lib'; -import { - Message, - MessageActionRowComponent, - type EmojiIdentifierResolvable, - type If, - type MessageEditOptions, - type MessagePayload, - type Partialize, - type ReplyMessageOptions, - type StartThreadOptions -} from 'discord.js'; -import type { RawMessageData } from 'discord.js/typings/rawDataTypes'; - -export type PartialBushMessage = Partialize< - BushMessage, - 'type' | 'system' | 'pinned' | 'tts', - 'content' | 'cleanContent' | 'author' ->; - -/** - * Represents a message on Discord. - */ -export class BushMessage<Cached extends boolean = boolean> extends Message<Cached> { - public declare readonly client: BushClient; - public declare util: BushCommandUtil<BushMessage<true>>; - public declare author: BushUser; - - public constructor(client: BushClient, data: RawMessageData) { - super(client, data); - } -} - -export interface BushMessage<Cached extends boolean = boolean> extends Message<Cached> { - get guild(): If<Cached, BushGuild>; - get member(): BushGuildMember | null; - get channel(): If<Cached, BushGuildTextBasedChannel, BushTextBasedChannel>; - delete(): Promise<BushMessage>; - edit(content: string | MessageEditOptions | MessagePayload): Promise<BushMessage>; - equals(message: BushMessage, rawData: unknown): boolean; - fetchReference(): Promise<BushMessage>; - crosspost(): Promise<BushMessage>; - fetch(force?: boolean): Promise<BushMessage>; - pin(): Promise<BushMessage>; - react(emoji: EmojiIdentifierResolvable): Promise<BushMessageReaction>; - removeAttachments(): Promise<BushMessage>; - reply(options: string | MessagePayload | ReplyMessageOptions): Promise<BushMessage>; - resolveComponent(customId: string): MessageActionRowComponent | null; - startThread(options: StartThreadOptions): Promise<BushThreadChannel>; - suppressEmbeds(suppress?: boolean): Promise<BushMessage>; - unpin(): Promise<BushMessage>; - inGuild(): this is BushMessage<true> & this; -} diff --git a/src/lib/extensions/discord.js/BushMessageManager.ts b/src/lib/extensions/discord.js/BushMessageManager.ts deleted file mode 100644 index edb7982..0000000 --- a/src/lib/extensions/discord.js/BushMessageManager.ts +++ /dev/null @@ -1,113 +0,0 @@ -import { BushMessageResolvable, BushTextBasedChannel, type BushMessage } from '#lib'; -import { - CachedManager, - FetchMessageOptions, - FetchMessagesOptions, - MessageManager, - type Collection, - type EmojiIdentifierResolvable, - type MessageEditOptions, - type MessagePayload, - type Snowflake -} from 'discord.js'; -import type { RawMessageData } from 'discord.js/typings/rawDataTypes'; - -/** - * Manages API methods for Messages and holds their cache. - */ -export declare class BushMessageManager - extends CachedManager<Snowflake, BushMessage, BushMessageResolvable> - implements MessageManager -{ - public constructor(channel: BushTextBasedChannel, iterable?: Iterable<RawMessageData>); - - /** - * The channel that the messages belong to - */ - public channel: BushTextBasedChannel; - - /** - * The cache of Messages - */ - public get cache(): Collection<Snowflake, BushMessage>; - - /** - * Publishes a message in an announcement channel to all channels following it, even if it's not cached. - * @param message The message to publish - */ - public crosspost(message: BushMessageResolvable): Promise<BushMessage>; - - /** - * Deletes a message, even if it's not cached. - * @param message The message to delete - */ - public delete(message: BushMessageResolvable): Promise<void>; - - /** - * Edits a message, even if it's not cached. - * @param message The message to edit - * @param options The options to edit the message - */ - public edit(message: BushMessageResolvable, options: string | MessagePayload | MessageEditOptions): Promise<BushMessage>; - - /** - * Gets a message, or messages, from this channel. - * <info>The returned Collection does not contain reaction users of the messages if they were not cached. - * Those need to be fetched separately in such a case.</info> - * @param message The id of the message to fetch, or query parameters. - * @param options Additional options for this fetch - * @example - * // Get message - * channel.messages.fetch('99539446449315840') - * .then(message => console.log(message.content)) - * .catch(console.error); - * @example - * // Get messages - * channel.messages.fetch({ limit: 10 }) - * .then(messages => console.log(`Received ${messages.size} messages`)) - * .catch(console.error); - * @example - * // Get messages and filter by user id - * channel.messages.fetch() - * .then(messages => console.log(`${messages.filter(m => m.author.id === '84484653687267328').size} messages`)) - * .catch(console.error); - */ - public fetch(options: BushMessageResolvable | FetchMessageOptions): Promise<BushMessage>; - public fetch(options?: FetchMessagesOptions): Promise<Collection<Snowflake, BushMessage>>; - - /** - * Fetches the pinned messages of this channel and returns a collection of them. - * <info>The returned Collection does not contain any reaction data of the messages. - * Those need to be fetched separately.</info> - * @param {} [cache=true] Whether to cache the message(s) - * @example - * // Get pinned messages - * channel.messages.fetchPinned() - * .then(messages => console.log(`Received ${messages.size} messages`)) - * .catch(console.error); - */ - public fetchPinned(cache?: boolean): Promise<Collection<Snowflake, BushMessage>>; - - /** - * Adds a reaction to a message, even if it's not cached. - * @param message The message to react to - * @param emoji The emoji to react with - */ - public react(message: BushMessageResolvable, emoji: EmojiIdentifierResolvable): Promise<void>; - - /** - * Pins a message to the channel's pinned messages, even if it's not cached. - * @param message The message to pin - */ - public pin(message: BushMessageResolvable): Promise<void>; - - /** - * Unpins a message from the channel's pinned messages, even if it's not cached. - * @param message The message to unpin - */ - public unpin(message: BushMessageResolvable): Promise<void>; -} - -export interface BushFetchMessageOptions extends FetchMessageOptions { - message: BushMessageResolvable; -} diff --git a/src/lib/extensions/discord.js/BushMessageReaction.ts b/src/lib/extensions/discord.js/BushMessageReaction.ts deleted file mode 100644 index 7fe110d..0000000 --- a/src/lib/extensions/discord.js/BushMessageReaction.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { BushClient, BushGuildEmoji, BushMessage, BushReactionEmoji } from '#lib'; -import { MessageReaction, type Partialize } from 'discord.js'; -import type { RawMessageReactionData } from 'discord.js/typings/rawDataTypes'; - -export type PartialBushMessageReaction = Partialize<BushMessageReaction, 'count'>; - -/** - * Represents a reaction to a message. - */ -export class BushMessageReaction extends MessageReaction { - public declare readonly client: BushClient; - - public constructor(client: BushClient, data: RawMessageReactionData, message: BushMessage) { - super(client, data, message); - } -} - -export interface BushMessageReaction extends MessageReaction { - get emoji(): BushGuildEmoji | BushReactionEmoji; -} diff --git a/src/lib/extensions/discord.js/BushModalSubmitInteraction.ts b/src/lib/extensions/discord.js/BushModalSubmitInteraction.ts deleted file mode 100644 index 9bdc9e5..0000000 --- a/src/lib/extensions/discord.js/BushModalSubmitInteraction.ts +++ /dev/null @@ -1,96 +0,0 @@ -import type { - BushClient, - BushGuild, - BushGuildCacheMessage, - BushGuildMember, - BushGuildTextBasedChannel, - BushTextBasedChannel, - BushUser -} from '#lib'; -import type { APIInteractionGuildMember, APIModalSubmitInteraction } from 'discord-api-types/v10'; -import { - InteractionDeferUpdateOptions, - InteractionResponse, - InteractionUpdateOptions, - MessagePayload, - ModalSubmitInteraction, - type CacheType, - type CacheTypeReducer -} from 'discord.js'; - -/** - * Represents a button interaction. - */ -export class BushModalSubmitInteraction<Cached extends CacheType = CacheType> extends ModalSubmitInteraction<Cached> { - public declare member: CacheTypeReducer<Cached, BushGuildMember, APIInteractionGuildMember>; - public declare user: BushUser; - - public constructor(client: BushClient, data: APIModalSubmitInteraction) { - super(client, data); - } -} - -export interface BushModalSubmitInteraction<Cached extends CacheType = CacheType> extends ModalSubmitInteraction<Cached> { - get channel(): CacheTypeReducer< - Cached, - BushGuildTextBasedChannel | null, - BushGuildTextBasedChannel | null, - BushGuildTextBasedChannel | null, - BushTextBasedChannel | null - >; - get guild(): CacheTypeReducer<Cached, BushGuild, null>; - inGuild(): this is BushModalSubmitInteraction<'raw' | 'cached'>; - inCachedGuild(): this is BushModalSubmitInteraction<'cached'>; - inRawGuild(): this is BushModalSubmitInteraction<'raw'>; - isFromMessage(): this is BushModalMessageModalSubmitInteraction<Cached>; -} - -export interface BushModalMessageModalSubmitInteraction<Cached extends CacheType = CacheType> - extends ModalSubmitInteraction<Cached> { - /** - * The message associated with this interaction - */ - message: BushGuildCacheMessage<Cached>; - - /** - * Updates the original message of the component on which the interaction was received on. - * @param options The options for the updated message - * @example - * // Remove the components from the message - * interaction.update({ - * content: "A component interaction was received", - * components: [] - * }) - * .then(console.log) - * .catch(console.error); - */ - update(options: InteractionUpdateOptions & { fetchReply: true }): Promise<BushGuildCacheMessage<Cached>>; - update(options: string | MessagePayload | InteractionUpdateOptions): Promise<InteractionResponse>; - - /** - * Defers an update to the message to which the component was attached. - * @param options Options for deferring the update to this interaction - * @example - * // Defer updating and reset the component's loading state - * interaction.deferUpdate() - * .then(console.log) - * .catch(console.error); - */ - deferUpdate(options: InteractionDeferUpdateOptions & { fetchReply: true }): Promise<BushGuildCacheMessage<Cached>>; - deferUpdate(options?: InteractionDeferUpdateOptions): Promise<InteractionResponse>; - - /** - * Indicates whether this interaction is received from a guild. - */ - inGuild(): this is BushModalMessageModalSubmitInteraction<'raw' | 'cached'>; - - /** - * Indicates whether or not this interaction is both cached and received from a guild. - */ - inCachedGuild(): this is BushModalMessageModalSubmitInteraction<'cached'>; - - /** - * Indicates whether or not this interaction is received from an uncached guild. - */ - inRawGuild(): this is BushModalMessageModalSubmitInteraction<'raw'>; -} diff --git a/src/lib/extensions/discord.js/BushNewsChannel.ts b/src/lib/extensions/discord.js/BushNewsChannel.ts deleted file mode 100644 index e262188..0000000 --- a/src/lib/extensions/discord.js/BushNewsChannel.ts +++ /dev/null @@ -1,15 +0,0 @@ -import type { BushGuild, BushGuildMember, BushMessageManager, BushThreadManager } from '#lib'; -import { NewsChannel, type AllowedThreadTypeForNewsChannel, type Collection, type Snowflake } from 'discord.js'; - -/** - * Represents a guild news channel on Discord. - */ -export class BushNewsChannel extends NewsChannel { - public declare threads: BushThreadManager<AllowedThreadTypeForNewsChannel>; - public declare guild: BushGuild; - public declare messages: BushMessageManager; -} - -export interface BushNewsChannel extends NewsChannel { - get members(): Collection<Snowflake, BushGuildMember>; -} diff --git a/src/lib/extensions/discord.js/BushPresence.ts b/src/lib/extensions/discord.js/BushPresence.ts deleted file mode 100644 index 40873ac..0000000 --- a/src/lib/extensions/discord.js/BushPresence.ts +++ /dev/null @@ -1,19 +0,0 @@ -import type { BushClient, BushGuild, BushGuildMember, BushUser } from '#lib'; -import { Presence } from 'discord.js'; -import type { RawPresenceData } from 'discord.js/typings/rawDataTypes'; - -/** - * Represents a user's presence. - */ -export class BushPresence extends Presence { - public declare guild: BushGuild | null; - - public constructor(client: BushClient, data?: RawPresenceData) { - super(client, data); - } -} - -export interface BushPresence extends Presence { - get member(): BushGuildMember | null; - get user(): BushUser | null; -} diff --git a/src/lib/extensions/discord.js/BushReactionEmoji.ts b/src/lib/extensions/discord.js/BushReactionEmoji.ts deleted file mode 100644 index b2a7eb0..0000000 --- a/src/lib/extensions/discord.js/BushReactionEmoji.ts +++ /dev/null @@ -1,16 +0,0 @@ -import type { BushMessageReaction } from '#lib'; -import { ReactionEmoji } from 'discord.js'; -import type { RawReactionEmojiData } from 'discord.js/typings/rawDataTypes'; - -/** - * Represents a limited emoji set used for both custom and unicode emojis. Custom emojis - * will use this class opposed to the Emoji class when the client doesn't know enough - * information about them. - */ -export class BushReactionEmoji extends ReactionEmoji { - public declare reaction: BushMessageReaction; - - public constructor(reaction: BushMessageReaction, emoji: RawReactionEmojiData) { - super(reaction, emoji); - } -} diff --git a/src/lib/extensions/discord.js/BushRole.ts b/src/lib/extensions/discord.js/BushRole.ts deleted file mode 100644 index a9575bd..0000000 --- a/src/lib/extensions/discord.js/BushRole.ts +++ /dev/null @@ -1,18 +0,0 @@ -import type { BushClient, BushGuild, BushGuildMember } from '#lib'; -import { Role, type Collection, type Snowflake } from 'discord.js'; -import type { RawRoleData } from 'discord.js/typings/rawDataTypes'; - -/** - * Represents a role on Discord. - */ -export class BushRole extends Role { - public declare guild: BushGuild; - - public constructor(client: BushClient, data: RawRoleData, guild: BushGuild) { - super(client, data, guild); - } -} - -export interface BushRole extends Role { - get members(): Collection<Snowflake, BushGuildMember>; -} diff --git a/src/lib/extensions/discord.js/BushSelectMenuInteraction.ts b/src/lib/extensions/discord.js/BushSelectMenuInteraction.ts deleted file mode 100644 index 66a5ea9..0000000 --- a/src/lib/extensions/discord.js/BushSelectMenuInteraction.ts +++ /dev/null @@ -1,30 +0,0 @@ -import type { BushClient, BushGuild, BushGuildMember, BushGuildTextBasedChannel, BushTextBasedChannel, BushUser } from '#lib'; -import type { APIInteractionGuildMember } from 'discord-api-types/v10'; -import { SelectMenuInteraction, type CacheType, type CacheTypeReducer } from 'discord.js'; -import type { RawMessageSelectMenuInteractionData } from 'discord.js/typings/rawDataTypes'; - -/** - * Represents a select menu interaction. - */ -export class BushSelectMenuInteraction<Cached extends CacheType = CacheType> extends SelectMenuInteraction<Cached> { - public declare member: CacheTypeReducer<Cached, BushGuildMember, APIInteractionGuildMember>; - public declare user: BushUser; - - public constructor(client: BushClient, data: RawMessageSelectMenuInteractionData) { - super(client, data); - } -} - -export interface BushSelectMenuInteraction<Cached extends CacheType = CacheType> extends SelectMenuInteraction<Cached> { - get channel(): CacheTypeReducer< - Cached, - BushGuildTextBasedChannel | null, - BushGuildTextBasedChannel | null, - BushGuildTextBasedChannel | null, - BushTextBasedChannel | null - >; - get guild(): CacheTypeReducer<Cached, BushGuild, null>; - inGuild(): this is BushSelectMenuInteraction<'raw' | 'cached'>; - inCachedGuild(): this is BushSelectMenuInteraction<'cached'>; - inRawGuild(): this is BushSelectMenuInteraction<'raw'>; -} diff --git a/src/lib/extensions/discord.js/BushStageChannel.ts b/src/lib/extensions/discord.js/BushStageChannel.ts deleted file mode 100644 index 983bd56..0000000 --- a/src/lib/extensions/discord.js/BushStageChannel.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { BushCategoryChannel, BushGuild, BushGuildMember, BushStageInstance } from '#lib'; -import { StageChannel, type Collection, type Snowflake } from 'discord.js'; -import type { RawGuildChannelData } from 'discord.js/typings/rawDataTypes'; - -/** - * Represents a guild stage channel on Discord. - */ -export class BushStageChannel extends StageChannel { - public declare guild: BushGuild; - - public constructor(guild: BushGuild, data?: RawGuildChannelData) { - super(guild, data); - } -} - -export interface BushStageChannel extends StageChannel { - get members(): Collection<Snowflake, BushGuildMember>; - get parent(): BushCategoryChannel | null; - get stageInstance(): BushStageInstance | null; -} diff --git a/src/lib/extensions/discord.js/BushStageInstance.ts b/src/lib/extensions/discord.js/BushStageInstance.ts deleted file mode 100644 index 96453a7..0000000 --- a/src/lib/extensions/discord.js/BushStageInstance.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type { BushClient, BushGuild, BushStageChannel } from '#lib'; -import { StageInstance } from 'discord.js'; -import type { RawStageInstanceData } from 'discord.js/typings/rawDataTypes'; - -/** - * Represents a stage instance. - */ -export class BushStageInstance extends StageInstance { - public constructor(client: BushClient, data: RawStageInstanceData, channel: BushStageChannel) { - super(client, data, channel); - } -} - -export interface BushStageInstance extends StageInstance { - get channel(): BushStageChannel | null; - get guild(): BushGuild | null; -} diff --git a/src/lib/extensions/discord.js/BushTextChannel.ts b/src/lib/extensions/discord.js/BushTextChannel.ts deleted file mode 100644 index 575de20..0000000 --- a/src/lib/extensions/discord.js/BushTextChannel.ts +++ /dev/null @@ -1,42 +0,0 @@ -import type { - BushCategoryChannel, - BushDMChannel, - BushGuild, - BushGuildBasedChannel, - BushMessageManager, - BushNewsChannel, - BushStageChannel, - BushTextBasedChannel, - BushThreadChannel, - BushThreadManager, - BushVoiceBasedChannel, - BushVoiceChannel -} from '#lib'; -import { PartialGroupDMChannel, TextChannel, type AllowedThreadTypeForTextChannel } from 'discord.js'; -import type { RawGuildChannelData } from 'discord.js/typings/rawDataTypes'; - -/** - * Represents a guild text channel on Discord. - */ -export class BushTextChannel extends TextChannel { - public declare guild: BushGuild; - public declare messages: BushMessageManager; - public declare threads: BushThreadManager<AllowedThreadTypeForTextChannel>; - - public constructor(guild: BushGuild, data?: RawGuildChannelData) { - super(guild, data); - } -} - -export interface BushTextChannel extends TextChannel { - isText(): this is BushTextChannel; - isDM(): this is BushDMChannel; - isDMBased(): this is PartialGroupDMChannel | BushDMChannel; - isVoice(): this is BushVoiceChannel; - isCategory(): this is BushCategoryChannel; - isNews(): this is BushNewsChannel; - isThread(): this is BushThreadChannel; - isStage(): this is BushStageChannel; - isTextBased(): this is BushGuildBasedChannel & BushTextBasedChannel; - isVoiceBased(): this is BushVoiceBasedChannel; -} diff --git a/src/lib/extensions/discord.js/BushThreadChannel.ts b/src/lib/extensions/discord.js/BushThreadChannel.ts deleted file mode 100644 index 8b941f9..0000000 --- a/src/lib/extensions/discord.js/BushThreadChannel.ts +++ /dev/null @@ -1,47 +0,0 @@ -import type { - BushCategoryChannel, - BushClient, - BushDMChannel, - BushGuild, - BushGuildBasedChannel, - BushGuildMember, - BushMessageManager, - BushNewsChannel, - BushStageChannel, - BushTextBasedChannel, - BushTextChannel, - BushThreadMemberManager, - BushVoiceBasedChannel, - BushVoiceChannel -} from '#lib'; -import { PartialGroupDMChannel, ThreadChannel, type Collection, type Snowflake } from 'discord.js'; -import type { RawThreadChannelData } from 'discord.js/typings/rawDataTypes'; - -/** - * Represents a thread channel on Discord. - */ -export class BushThreadChannel extends ThreadChannel { - public declare guild: BushGuild; - public declare messages: BushMessageManager; - public declare members: BushThreadMemberManager; - public declare readonly client: BushClient; - - public constructor(guild: BushGuild, data?: RawThreadChannelData, client?: BushClient, fromInteraction?: boolean) { - super(guild, data, client, fromInteraction); - } -} - -export interface BushThreadChannel extends ThreadChannel { - get guildMembers(): Collection<Snowflake, BushGuildMember>; - get parent(): BushTextChannel | BushNewsChannel | null; - isText(): this is BushTextChannel; - isDM(): this is BushDMChannel; - isDMBased(): this is PartialGroupDMChannel | BushDMChannel; - isVoice(): this is BushVoiceChannel; - isCategory(): this is BushCategoryChannel; - isNews(): this is BushNewsChannel; - isThread(): this is BushThreadChannel; - isStage(): this is BushStageChannel; - isTextBased(): this is BushGuildBasedChannel & BushTextBasedChannel; - isVoiceBased(): this is BushVoiceBasedChannel; -} diff --git a/src/lib/extensions/discord.js/BushThreadManager.ts b/src/lib/extensions/discord.js/BushThreadManager.ts deleted file mode 100644 index 0748a4d..0000000 --- a/src/lib/extensions/discord.js/BushThreadManager.ts +++ /dev/null @@ -1,84 +0,0 @@ -import type { BushFetchedThreads, BushThreadChannel } from '#lib'; -import { - CachedManager, - NewsChannel, - TextChannel, - ThreadManager, - type BaseFetchOptions, - type FetchArchivedThreadOptions, - type FetchThreadsOptions, - type Snowflake, - type ThreadChannelResolvable, - type ThreadCreateOptions -} from 'discord.js'; -import type { RawThreadChannelData } from 'discord.js/typings/rawDataTypes'; - -/** - * Manages API methods for {@link BushThreadChannel} objects and stores their cache. - */ -export declare class BushThreadManager<AllowedThreadType> - extends CachedManager<Snowflake, BushThreadChannel, ThreadChannelResolvable> - implements ThreadManager<AllowedThreadType> -{ - public constructor(channel: TextChannel | NewsChannel, iterable?: Iterable<RawThreadChannelData>); - - /** - * The channel this Manager belongs to - */ - public channel: TextChannel | NewsChannel; - - /** - * Creates a new thread in the channel. - * @param options Options to create a new thread - * @example - * // Create a new public thread - * channel.threads - * .create({ - * name: 'food-talk', - * autoArchiveDuration: 60, - * reason: 'Needed a separate thread for food', - * }) - * .then(threadChannel => console.log(threadChannel)) - * .catch(console.error); - * @example - * // Create a new private thread - * channel.threads - * .create({ - * name: 'mod-talk', - * autoArchiveDuration: 60, - * type: 'GuildPrivateThread', - * reason: 'Needed a separate thread for moderation', - * }) - * .then(threadChannel => console.log(threadChannel)) - * .catch(console.error); - */ - public create(options: ThreadCreateOptions<AllowedThreadType>): Promise<BushThreadChannel>; - - /** - * Obtains a thread from Discord, or the channel cache if it's already available. - * @param options The options to fetch threads. If it is a - * ThreadChannelResolvable then the specified thread will be fetched. Fetches all active threads if `undefined` - * @param cacheOptions Additional options for this fetch. <warn>The `force` field gets ignored - * if `options` is not a {@link ThreadChannelResolvable}</warn> - * @example - * // Fetch a thread by its id - * channel.threads.fetch('831955138126104859') - * .then(channel => console.log(channel.name)) - * .catch(console.error); - */ - public fetch(options: ThreadChannelResolvable, cacheOptions?: BaseFetchOptions): Promise<BushThreadChannel | null>; - public fetch(options?: FetchThreadsOptions, cacheOptions?: { cache?: boolean }): Promise<BushFetchedThreads>; - - /** - * Obtains a set of archived threads from Discord, requires `READ_MESSAGE_HISTORY` in the parent channel. - * @param options The options to fetch archived threads - * @param cache Whether to cache the new thread objects if they aren't already - */ - public fetchArchived(options?: FetchArchivedThreadOptions, cache?: boolean): Promise<BushFetchedThreads>; - - /** - * Obtains the accessible active threads from Discord, requires `READ_MESSAGE_HISTORY` in the parent channel. - * @param cache Whether to cache the new thread objects if they aren't already - */ - public fetchActive(cache?: boolean): Promise<BushFetchedThreads>; -} diff --git a/src/lib/extensions/discord.js/BushThreadMember.ts b/src/lib/extensions/discord.js/BushThreadMember.ts deleted file mode 100644 index 90c9c9b..0000000 --- a/src/lib/extensions/discord.js/BushThreadMember.ts +++ /dev/null @@ -1,19 +0,0 @@ -import type { BushGuildMember, BushThreadChannel, BushUser } from '#lib'; -import { ThreadMember } from 'discord.js'; -import type { RawThreadMemberData } from 'discord.js/typings/rawDataTypes'; - -/** - * Represents a Member for a Thread. - */ -export class BushThreadMember extends ThreadMember { - public declare thread: BushThreadChannel; - - public constructor(thread: BushThreadChannel, data?: RawThreadMemberData) { - super(thread, data); - } -} - -export interface BushThreadMember extends ThreadMember { - get guildMember(): BushGuildMember | null; - get user(): BushUser | null; -} diff --git a/src/lib/extensions/discord.js/BushThreadMemberManager.ts b/src/lib/extensions/discord.js/BushThreadMemberManager.ts deleted file mode 100644 index d183b30..0000000 --- a/src/lib/extensions/discord.js/BushThreadMemberManager.ts +++ /dev/null @@ -1,62 +0,0 @@ -import type { BushClient, BushThreadChannel, BushThreadMember, BushThreadMemberResolvable, BushUserResolvable } from '#lib'; -import { - CachedManager, - ThreadMemberManager, - type BaseFetchOptions, - type Collection, - type Snowflake, - type UserResolvable -} from 'discord.js'; -import type { RawThreadMemberData } from 'discord.js/typings/rawDataTypes'; - -/** - * Manages API methods for GuildMembers and stores their cache. - */ -export declare class BushThreadMemberManager - extends CachedManager<Snowflake, BushThreadMember, BushThreadMemberResolvable> - implements ThreadMemberManager -{ - public constructor(thread: BushThreadChannel, iterable?: Iterable<RawThreadMemberData>); - public declare readonly client: BushClient; - - /** - * The thread this manager belongs to - */ - public thread: BushThreadChannel; - - /** - * Adds a member to the thread. - * @param member The member to add - * @param reason The reason for adding this member - */ - public add(member: UserResolvable | '@me', reason?: string): Promise<Snowflake>; - - /** - * Fetches member(s) for the thread from Discord, requires access to the `GatewayIntentBits.GuildMembers` gateway intent. - * @param options Additional options for this fetch, when a `boolean` is provided - * all members are fetched with `options.cache` set to the boolean value - */ - public fetch(options?: BushThreadMemberFetchOptions): Promise<BushThreadMember>; - public fetch(cache?: boolean): Promise<Collection<Snowflake, BushThreadMember>>; - - /** - * Remove a user from the thread. - * @param id The id of the member to remove - * @param reason The reason for removing this member from the thread - */ - public remove(id: Snowflake | '@me', reason?: string): Promise<Snowflake>; -} - -export interface BushThreadMemberManager extends CachedManager<Snowflake, BushThreadMember, BushThreadMemberResolvable> { - /** - * The client user as a ThreadMember of this ThreadChannel - */ - get me(): BushThreadMember | null; -} - -export interface BushThreadMemberFetchOptions extends BaseFetchOptions { - /** - * The specific user to fetch from the thread - */ - member?: BushUserResolvable; -} diff --git a/src/lib/extensions/discord.js/BushUser.ts b/src/lib/extensions/discord.js/BushUser.ts deleted file mode 100644 index 27ef2b2..0000000 --- a/src/lib/extensions/discord.js/BushUser.ts +++ /dev/null @@ -1,34 +0,0 @@ -import type { BushClient, BushDMChannel } from '#lib'; -import { User, type Partialize } from 'discord.js'; -import type { RawUserData } from 'discord.js/typings/rawDataTypes'; - -export type PartialBushUser = Partialize<BushUser, 'username' | 'tag' | 'discriminator' | 'isOwner' | 'isSuperUser'>; - -/** - * Represents a user on Discord. - */ -export class BushUser extends User { - public declare readonly client: BushClient; - - public constructor(client: BushClient, data: RawUserData) { - super(client, data); - } - - /** - * Indicates whether the user is an owner of the bot. - */ - public isOwner(): boolean { - return client.isOwner(this); - } - - /** - * Indicates whether the user is a superuser of the bot. - */ - public isSuperUser(): boolean { - return client.isSuperUser(this); - } -} - -export interface BushUser extends User { - get dmChannel(): BushDMChannel | null; -} diff --git a/src/lib/extensions/discord.js/BushUserManager.ts b/src/lib/extensions/discord.js/BushUserManager.ts deleted file mode 100644 index c26dbde..0000000 --- a/src/lib/extensions/discord.js/BushUserManager.ts +++ /dev/null @@ -1,60 +0,0 @@ -import type { BushClient, BushDMChannel, BushUser, BushUserResolvable } from '#lib'; -import { - CachedManager, - Message, - MessageOptions, - MessagePayload, - UserFlagsBitField, - UserManager, - type BaseFetchOptions, - type Snowflake -} from 'discord.js'; -import type { RawUserData } from 'discord.js/typings/rawDataTypes'; - -/** - * Manages API methods for users and stores their cache. - */ -export declare class BushUserManager extends CachedManager<Snowflake, BushUser, BushUserResolvable> implements UserManager { - private constructor(client: BushClient, iterable?: Iterable<RawUserData>); - - /** - * The DM between the client's user and a user - * @param userId The user id - * @private - */ - public dmChannel(userId: Snowflake): BushDMChannel | null; - - /** - * Creates a {@link BushDMChannel} between the client and a user. - * @param user The UserResolvable to identify - * @param options Additional options for this fetch - */ - public createDM(user: BushUserResolvable, options?: BaseFetchOptions): Promise<BushDMChannel>; - - /** - * Deletes a {@link BushDMChannel} (if one exists) between the client and a user. Resolves with the channel if successful. - * @param user The UserResolvable to identify - */ - public deleteDM(user: BushUserResolvable): Promise<BushDMChannel>; - - /** - * Obtains a user from Discord, or the user cache if it's already available. - * @param user The user to fetch - * @param options Additional options for this fetch - */ - public fetch(user: BushUserResolvable, options?: BaseFetchOptions): Promise<BushUser>; - - /** - * Fetches a user's flags. - * @param user The UserResolvable to identify - * @param options Additional options for this fetch - */ - public fetchFlags(user: BushUserResolvable, options?: BaseFetchOptions): Promise<UserFlagsBitField>; - - /** - * Sends a message to a user. - * @param user The UserResolvable to identify - * @param options The options to provide - */ - public send(user: BushUserResolvable, options: string | MessagePayload | MessageOptions): Promise<Message>; -} diff --git a/src/lib/extensions/discord.js/BushVoiceChannel.ts b/src/lib/extensions/discord.js/BushVoiceChannel.ts deleted file mode 100644 index 6966727..0000000 --- a/src/lib/extensions/discord.js/BushVoiceChannel.ts +++ /dev/null @@ -1,40 +0,0 @@ -import type { - BushCategoryChannel, - BushClient, - BushDMChannel, - BushGuild, - BushGuildBasedChannel, - BushGuildMember, - BushNewsChannel, - BushStageChannel, - BushTextBasedChannel, - BushTextChannel, - BushThreadChannel, - BushVoiceBasedChannel -} from '#lib'; -import { VoiceChannel, type Collection, type Snowflake } from 'discord.js'; -import type { RawGuildChannelData } from 'discord.js/typings/rawDataTypes'; - -/** - * Represents a guild voice channel on Discord. - */ -export class BushVoiceChannel extends VoiceChannel { - public declare readonly client: BushClient; - - public constructor(guild: BushGuild, data?: RawGuildChannelData) { - super(guild, data); - } -} - -export interface BushVoiceChannel extends VoiceChannel { - get members(): Collection<Snowflake, BushGuildMember>; - isText(): this is BushTextChannel; - isDM(): this is BushDMChannel; - isVoice(): this is BushVoiceChannel; - isCategory(): this is BushCategoryChannel; - isNews(): this is BushNewsChannel; - isThread(): this is BushThreadChannel; - isStage(): this is BushStageChannel; - isTextBased(): this is BushGuildBasedChannel & BushTextBasedChannel; - isVoiceBased(): this is BushVoiceBasedChannel; -} diff --git a/src/lib/extensions/discord.js/BushVoiceState.ts b/src/lib/extensions/discord.js/BushVoiceState.ts deleted file mode 100644 index bbcdfa8..0000000 --- a/src/lib/extensions/discord.js/BushVoiceState.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { BushClient, BushGuild, BushGuildMember, BushVoiceBasedChannel } from '#lib'; -import { VoiceState } from 'discord.js'; -import type { RawVoiceStateData } from 'discord.js/typings/rawDataTypes'; - -/** - * Represents the voice state for a Guild Member. - */ -export class BushVoiceState extends VoiceState { - public declare readonly client: BushClient; - public declare guild: BushGuild; - - public constructor(guild: BushGuild, data: RawVoiceStateData) { - super(guild, data); - } -} - -export interface BushVoiceState extends VoiceState { - get channel(): BushVoiceBasedChannel | null; - get getmember(): BushGuildMember | null; -} diff --git a/src/lib/extensions/discord.js/BushGuild.ts b/src/lib/extensions/discord.js/ExtendedGuild.ts index a93e35f..b8b7b22 100644 --- a/src/lib/extensions/discord.js/BushGuild.ts +++ b/src/lib/extensions/discord.js/ExtendedGuild.ts @@ -1,65 +1,146 @@ import { AllowedMentions, banResponse, - BushGuildChannelManager, - BushGuildMemberManager, - BushMessage, - BushVoiceChannel, dmResponse, permissionsResponse, punishmentEntryRemove, type BanResponse, - type BushClient, - type BushGuildMember, - type BushGuildMemberResolvable, - type BushNewsChannel, - type BushTextChannel, - type BushThreadChannel, - type BushUser, - type BushUserResolvable, type GuildFeatures, type GuildLogType, type GuildModel } from '#lib'; -import { APIMessage } from 'discord-api-types/v10'; import { + AttachmentBuilder, + AttachmentPayload, Collection, Guild, + JSONEncodable, + Message, MessageType, PermissionFlagsBits, SnowflakeUtil, ThreadChannel, - Webhook, - WebhookMessageOptions, + type APIMessage, + type GuildMember, + type GuildMemberResolvable, + type GuildTextBasedChannel, type MessageOptions, type MessagePayload, - type Snowflake + type NewsChannel, + type Snowflake, + type TextChannel, + type User, + type UserResolvable, + type VoiceChannel, + type Webhook, + type WebhookMessageOptions } from 'discord.js'; -import type { RawGuildData } from 'discord.js/typings/rawDataTypes'; import _ from 'lodash'; import { Moderation } from '../../common/util/Moderation.js'; import { Guild as GuildDB } from '../../models/instance/Guild.js'; import { ModLogType } from '../../models/instance/ModLog.js'; +declare module 'discord.js' { + export interface Guild { + /** + * Checks if the guild has a certain custom feature. + * @param feature The feature to check for + */ + hasFeature(feature: GuildFeatures): Promise<boolean>; + /** + * Adds a custom feature to the guild. + * @param feature The feature to add + * @param moderator The moderator responsible for adding a feature + */ + addFeature(feature: GuildFeatures, moderator?: GuildMember): Promise<GuildDB['enabledFeatures']>; + /** + * Removes a custom feature from the guild. + * @param feature The feature to remove + * @param moderator The moderator responsible for removing a feature + */ + removeFeature(feature: GuildFeatures, moderator?: GuildMember): Promise<GuildDB['enabledFeatures']>; + /** + * Makes a custom feature the opposite of what it was before + * @param feature The feature to toggle + * @param moderator The moderator responsible for toggling a feature + */ + toggleFeature(feature: GuildFeatures, moderator?: GuildMember): Promise<GuildDB['enabledFeatures']>; + /** + * Fetches a custom setting for the guild + * @param setting The setting to get + */ + getSetting<K extends keyof GuildModel>(setting: K): Promise<GuildModel[K]>; + /** + * Sets a custom setting for the guild + * @param setting The setting to change + * @param value The value to change the setting to + * @param moderator The moderator to responsible for changing the setting + */ + setSetting<K extends Exclude<keyof GuildModel, 'id'>>( + setting: K, + value: GuildModel[K], + moderator?: GuildMember + ): Promise<GuildModel>; + /** + * Get a the log channel configured for a certain log type. + * @param logType The type of log channel to get. + * @returns Either the log channel or undefined if not configured. + */ + getLogChannel(logType: GuildLogType): Promise<TextChannel | undefined>; + /** + * Sends a message to the guild's specified logging channel + * @param logType The corresponding channel that the message will be sent to + * @param message The parameters for {@link BushTextChannel.send} + */ + sendLogChannel(logType: GuildLogType, message: string | MessagePayload | MessageOptions): Promise<Message | null | undefined>; + /** + * Sends a formatted error message in a guild's error log channel + * @param title The title of the error embed + * @param message The description of the error embed + */ + error(title: string, message: string): Promise<void>; + /** + * Bans a user, dms them, creates a mod log entry, and creates a punishment entry. + * @param options Options for banning the user. + * @returns A string status message of the ban. + */ + bushBan(options: GuildBushBanOptions): Promise<BanResponse>; + /** + * {@link bushBan} with less resolving and checks + * @param options Options for banning the user. + * @returns A string status message of the ban. + * **Preconditions:** + * - {@link me} has the `BanMembers` permission + * **Warning:** + * - Doesn't emit bushBan Event + */ + massBanOne(options: GuildMassBanOneOptions): Promise<BanResponse>; + /** + * Unbans a user, dms them, creates a mod log entry, and destroys the punishment entry. + * @param options Options for unbanning the user. + * @returns A status message of the unban. + */ + bushUnban(options: GuildBushUnbanOptions): Promise<UnbanResponse>; + /** + * Denies send permissions in specified channels + * @param options The options for locking down the guild + */ + lockdown(options: LockdownOptions): Promise<LockdownResponse>; + quote(rawQuote: APIMessage, channel: GuildTextBasedChannel): Promise<Message | null>; + } +} + /** * Represents a guild (or a server) on Discord. * <info>It's recommended to see if a guild is available before performing operations or reading data from it. You can - * check this with {@link BushGuild.available}.</info> + * check this with {@link ExtendedGuild.available}.</info> */ -export class BushGuild extends Guild { - public declare readonly client: BushClient; - public declare members: BushGuildMemberManager; - public declare channels: BushGuildChannelManager; - - public constructor(client: BushClient, data: RawGuildData) { - super(client, data); - } - +export class ExtendedGuild extends Guild { /** * Checks if the guild has a certain custom feature. * @param feature The feature to check for */ - public async hasFeature(feature: GuildFeatures): Promise<boolean> { + public override async hasFeature(feature: GuildFeatures): Promise<boolean> { const features = await this.getSetting('enabledFeatures'); return features.includes(feature); } @@ -69,7 +150,7 @@ export class BushGuild extends Guild { * @param feature The feature to add * @param moderator The moderator responsible for adding a feature */ - public async addFeature(feature: GuildFeatures, moderator?: BushGuildMember): Promise<GuildModel['enabledFeatures']> { + public override async addFeature(feature: GuildFeatures, moderator?: GuildMember): Promise<GuildModel['enabledFeatures']> { const features = await this.getSetting('enabledFeatures'); const newFeatures = util.addOrRemoveFromArray('add', features, feature); return (await this.setSetting('enabledFeatures', newFeatures, moderator)).enabledFeatures; @@ -80,7 +161,7 @@ export class BushGuild extends Guild { * @param feature The feature to remove * @param moderator The moderator responsible for removing a feature */ - public async removeFeature(feature: GuildFeatures, moderator?: BushGuildMember): Promise<GuildModel['enabledFeatures']> { + public override async removeFeature(feature: GuildFeatures, moderator?: GuildMember): Promise<GuildModel['enabledFeatures']> { const features = await this.getSetting('enabledFeatures'); const newFeatures = util.addOrRemoveFromArray('remove', features, feature); return (await this.setSetting('enabledFeatures', newFeatures, moderator)).enabledFeatures; @@ -91,7 +172,7 @@ export class BushGuild extends Guild { * @param feature The feature to toggle * @param moderator The moderator responsible for toggling a feature */ - public async toggleFeature(feature: GuildFeatures, moderator?: BushGuildMember): Promise<GuildModel['enabledFeatures']> { + public override async toggleFeature(feature: GuildFeatures, moderator?: GuildMember): Promise<GuildModel['enabledFeatures']> { return (await this.hasFeature(feature)) ? await this.removeFeature(feature, moderator) : await this.addFeature(feature, moderator); @@ -101,7 +182,7 @@ export class BushGuild extends Guild { * Fetches a custom setting for the guild * @param setting The setting to get */ - public async getSetting<K extends keyof GuildModel>(setting: K): Promise<GuildModel[K]> { + public override async getSetting<K extends keyof GuildModel>(setting: K): Promise<GuildModel[K]> { return ( client.cache.guilds.get(this.id)?.[setting] ?? ((await GuildDB.findByPk(this.id)) ?? GuildDB.build({ id: this.id }))[setting] @@ -114,10 +195,10 @@ export class BushGuild extends Guild { * @param value The value to change the setting to * @param moderator The moderator to responsible for changing the setting */ - public async setSetting<K extends Exclude<keyof GuildModel, 'id'>>( + public override async setSetting<K extends Exclude<keyof GuildModel, 'id'>>( setting: K, value: GuildDB[K], - moderator?: BushGuildMember + moderator?: GuildMember ): Promise<GuildDB> { const row = (await GuildDB.findByPk(this.id)) ?? GuildDB.build({ id: this.id }); const oldValue = row[setting] as GuildDB[K]; @@ -132,12 +213,12 @@ export class BushGuild extends Guild { * @param logType The type of log channel to get. * @returns Either the log channel or undefined if not configured. */ - public async getLogChannel(logType: GuildLogType): Promise<BushTextChannel | undefined> { + public override async getLogChannel(logType: GuildLogType): Promise<TextChannel | undefined> { const channelId = (await this.getSetting('logChannels'))[logType]; if (!channelId) return undefined; return ( - (this.channels.cache.get(channelId) as BushTextChannel | undefined) ?? - ((await this.channels.fetch(channelId)) as BushTextChannel | null) ?? + (this.channels.cache.get(channelId) as TextChannel | undefined) ?? + ((await this.channels.fetch(channelId)) as TextChannel | null) ?? undefined ); } @@ -147,7 +228,10 @@ export class BushGuild extends Guild { * @param logType The corresponding channel that the message will be sent to * @param message The parameters for {@link BushTextChannel.send} */ - public async sendLogChannel(logType: GuildLogType, message: string | MessagePayload | MessageOptions) { + public override async sendLogChannel( + logType: GuildLogType, + message: string | MessagePayload | MessageOptions + ): Promise<Message | null | undefined> { const logChannel = await this.getLogChannel(logType); if (!logChannel || !logChannel.isTextBased()) return; if ( @@ -165,7 +249,7 @@ export class BushGuild extends Guild { * @param title The title of the error embed * @param message The description of the error embed */ - public async error(title: string, message: string) { + public override async error(title: string, message: string): Promise<void> { void client.console.info(_.camelCase(title), message.replace(/\*\*(.*?)\*\*/g, '<<$1>>')); void this.sendLogChannel('error', { embeds: [{ title: title, description: message, color: util.colors.error }] }); } @@ -175,7 +259,7 @@ export class BushGuild extends Guild { * @param options Options for banning the user. * @returns A string status message of the ban. */ - public async bushBan(options: GuildBushBanOptions): Promise<BanResponse> { + public override async bushBan(options: GuildBushBanOptions): Promise<BanResponse> { // checks if (!this.members.me!.permissions.has(PermissionFlagsBits.BanMembers)) return banResponse.MISSING_PERMISSIONS; @@ -259,7 +343,7 @@ export class BushGuild extends Guild { * **Warning:** * - Doesn't emit bushBan Event */ - public async massBanOne(options: GuildMassBanOneOptions): Promise<BanResponse> { + public override async massBanOne(options: GuildMassBanOneOptions): Promise<BanResponse> { if (this.bans.cache.has(options.user)) return banResponse.ALREADY_BANNED; const ret = await (async () => { @@ -318,7 +402,7 @@ export class BushGuild extends Guild { * @param options Options for unbanning the user. * @returns A status message of the unban. */ - public async bushUnban(options: GuildBushUnbanOptions): Promise<UnbanResponse> { + public override async bushUnban(options: GuildBushUnbanOptions): Promise<UnbanResponse> { // checks if (!this.members.me!.permissions.has(PermissionFlagsBits.BanMembers)) return unbanResponse.MISSING_PERMISSIONS; @@ -391,7 +475,7 @@ export class BushGuild extends Guild { * Denies send permissions in specified channels * @param options The options for locking down the guild */ - public async lockdown(options: LockdownOptions): Promise<LockdownResponse> { + public override async lockdown(options: LockdownOptions): Promise<LockdownResponse> { if (!options.all && !options.channel) return 'all not chosen and no channel specified'; const channelIds = options.all ? await this.getSetting('lockdownChannels') : [options.channel!.id]; @@ -466,11 +550,11 @@ export class BushGuild extends Guild { return ret; } - public async quote(rawQuote: APIMessage, channel: BushTextChannel | BushNewsChannel | BushThreadChannel) { + public override async quote(rawQuote: APIMessage, channel: GuildTextBasedChannel): Promise<Message | null> { if (!channel.isTextBased() || channel.isDMBased() || channel.guildId !== this.id || !this.members.me) return null; if (!channel.permissionsFor(this.members.me).has('ManageWebhooks')) return null; - const quote = new BushMessage(client, rawQuote); + const quote = new Message(client, rawQuote); const target = channel instanceof ThreadChannel ? channel.parent : channel; if (!target) return null; @@ -482,7 +566,8 @@ export class BushGuild extends Guild { let webhook = webhooks.find((w) => !!w.token) ?? null; if (!webhook) webhook = await target - .createWebhook(`${client.user!.username} Quotes #${target.name}`, { + .createWebhook({ + name: `${client.user!.username} Quotes #${target.name}`, avatar: client.user!.displayAvatarURL({ size: 2048 }), reason: 'Creating a webhook for quoting' }) @@ -503,7 +588,10 @@ export class BushGuild extends Guild { sendOptions.content = quote.content || undefined; sendOptions.threadId = channel instanceof ThreadChannel ? channel.id : undefined; sendOptions.embeds = quote.embeds.length ? quote.embeds : undefined; - sendOptions.attachments = quote.attachments.size ? [...quote.attachments.values()] : undefined; + //@ts-expect-error: jank + sendOptions.attachments = quote.attachments.size + ? [...quote.attachments.values()].map((a) => AttachmentBuilder.from(a as JSONEncodable<AttachmentPayload>)) + : undefined; if (quote.stickers.size && !(quote.content || quote.embeds.length || quote.attachments.size)) sendOptions.content = '[[This message has a sticker but not content]]'; @@ -651,7 +739,7 @@ export interface GuildBushUnbanOptions { /** * The user to unban */ - user: BushUserResolvable | BushUser; + user: UserResolvable | User; /** * The reason for unbanning the user @@ -661,7 +749,7 @@ export interface GuildBushUnbanOptions { /** * The moderator who unbanned the user */ - moderator?: BushUserResolvable; + moderator?: UserResolvable; /** * The evidence for the unban @@ -698,7 +786,7 @@ export interface GuildBushBanOptions { /** * The user to ban */ - user: BushUserResolvable; + user: UserResolvable; /** * The reason to ban the user @@ -708,7 +796,7 @@ export interface GuildBushBanOptions { /** * The moderator who banned the user */ - moderator?: BushUserResolvable; + moderator?: UserResolvable; /** * The duration of the ban @@ -747,7 +835,7 @@ export interface LockdownOptions { /** * The moderator responsible for the lockdown */ - moderator: BushGuildMemberResolvable; + moderator: GuildMemberResolvable; /** * Whether to lock down all (specified) channels @@ -762,7 +850,7 @@ export interface LockdownOptions { /** * A specific channel to lockdown */ - channel?: BushThreadChannel | BushNewsChannel | BushTextChannel | BushVoiceChannel; + channel?: ThreadChannel | NewsChannel | TextChannel | VoiceChannel; /** * Whether or not to unlock the channel(s) instead of locking them diff --git a/src/lib/extensions/discord.js/BushGuildMember.ts b/src/lib/extensions/discord.js/ExtendedGuildMember.ts index 20a1f60..28acc1a 100644 --- a/src/lib/extensions/discord.js/BushGuildMember.ts +++ b/src/lib/extensions/discord.js/ExtendedGuildMember.ts @@ -1,44 +1,127 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ +import { BushClientEvents, Moderation, ModLogType, PunishmentTypeDM, Time } from '#lib'; import { - BushClientEvents, - Moderation, - ModLogType, - PunishmentTypeDM, - Time, - type BushClient, - type BushGuild, - type BushGuildTextBasedChannel, - type BushGuildTextChannelResolvable, - type BushRole, - type BushThreadChannelResolvable, - type BushUser -} from '#lib'; -import { GuildMember, PermissionFlagsBits, type Partialize, type Role } from 'discord.js'; -import type { RawGuildMemberData } from 'discord.js/typings/rawDataTypes'; + ChannelType, + GuildChannelResolvable, + GuildMember, + GuildTextBasedChannel, + PermissionFlagsBits, + type Role +} from 'discord.js'; /* eslint-enable @typescript-eslint/no-unused-vars */ +declare module 'discord.js' { + export interface GuildMember { + /** + * Send a punishment dm to the user. + * @param punishment The punishment that the user has received. + * @param reason The reason for the user's punishment. + * @param duration The duration of the punishment. + * @param modlog The modlog case id so the user can make an appeal. + * @param sendFooter Whether or not to send the guild's punishment footer with the dm. + * @returns Whether or not the dm was sent successfully. + */ + bushPunishDM( + punishment: PunishmentTypeDM, + reason?: string | null, + duration?: number, + modlog?: string, + sendFooter?: boolean + ): Promise<boolean>; + /** + * Warn the user, create a modlog entry, and send a dm to the user. + * @param options Options for warning the user. + * @returns An object with the result of the warning, and the case number of the warn. + * @emits {@link BushClientEvents.bushWarn} + */ + bushWarn(options: BushPunishmentOptions): Promise<{ result: WarnResponse; caseNum: number | null }>; + /** + * Add a role to the user, if it is a punishment create a modlog entry, and create a punishment entry if it is temporary or a punishment. + * @param options Options for adding a role to the user. + * @returns A status message for adding the add. + * @emits {@link BushClientEvents.bushPunishRole} + */ + bushAddRole(options: AddRoleOptions): Promise<AddRoleResponse>; + /** + * Remove a role from the user, if it is a punishment create a modlog entry, and destroy a punishment entry if it was temporary or a punishment. + * @param options Options for removing a role from the user. + * @returns A status message for removing the role. + * @emits {@link BushClientEvents.bushPunishRoleRemove} + */ + bushRemoveRole(options: RemoveRoleOptions): Promise<RemoveRoleResponse>; + /** + * Mute the user, create a modlog entry, creates a punishment entry, and dms the user. + * @param options Options for muting the user. + * @returns A status message for muting the user. + * @emits {@link BushClientEvents.bushMute} + */ + bushMute(options: BushTimedPunishmentOptions): Promise<MuteResponse>; + /** + * Unmute the user, create a modlog entry, remove the punishment entry, and dm the user. + * @param options Options for unmuting the user. + * @returns A status message for unmuting the user. + * @emits {@link BushClientEvents.bushUnmute} + */ + bushUnmute(options: BushPunishmentOptions): Promise<UnmuteResponse>; + /** + * Kick the user, create a modlog entry, and dm the user. + * @param options Options for kicking the user. + * @returns A status message for kicking the user. + * @emits {@link BushClientEvents.bushKick} + */ + bushKick(options: BushPunishmentOptions): Promise<KickResponse>; + /** + * Ban the user, create a modlog entry, create a punishment entry, and dm the user. + * @param options Options for banning the user. + * @returns A status message for banning the user. + * @emits {@link BushClientEvents.bushBan} + */ + bushBan(options: BushBanOptions): Promise<Exclude<BanResponse, typeof banResponse['ALREADY_BANNED']>>; + /** + * Prevents a user from speaking in a channel. + * @param options Options for blocking the user. + */ + bushBlock(options: BlockOptions): Promise<BlockResponse>; + /** + * Allows a user to speak in a channel. + * @param options Options for unblocking the user. + */ + bushUnblock(options: UnblockOptions): Promise<UnblockResponse>; + /** + * Mutes a user using discord's timeout feature. + * @param options Options for timing out the user. + */ + bushTimeout(options: BushTimeoutOptions): Promise<TimeoutResponse>; + /** + * Removes a timeout from a user. + * @param options Options for removing the timeout. + */ + bushRemoveTimeout(options: BushPunishmentOptions): Promise<RemoveTimeoutResponse>; + /** + * Whether or not the user is an owner of the bot. + */ + isOwner(): boolean; + /** + * Whether or not the user is a super user of the bot. + */ + isSuperUser(): boolean; + } +} + /** * Represents a member of a guild on Discord. */ -export class BushGuildMember extends GuildMember { - public declare readonly client: BushClient; - public declare guild: BushGuild; - public declare user: BushUser; - - public constructor(client: BushClient, data: RawGuildMemberData, guild: BushGuild) { - super(client, data, guild); - } - +export class ExtendedGuildMember extends GuildMember { /** * Send a punishment dm to the user. - * @param modlog The modlog case id so the user can make an appeal. * @param punishment The punishment that the user has received. * @param reason The reason for the user's punishment. * @param duration The duration of the punishment. + * @param modlog The modlog case id so the user can make an appeal. * @param sendFooter Whether or not to send the guild's punishment footer with the dm. * @returns Whether or not the dm was sent successfully. */ - public async bushPunishDM( + public override async bushPunishDM( punishment: PunishmentTypeDM, reason?: string | null, duration?: number, @@ -62,7 +145,7 @@ export class BushGuildMember extends GuildMember { * @returns An object with the result of the warning, and the case number of the warn. * @emits {@link BushClientEvents.bushWarn} */ - public async bushWarn(options: BushPunishmentOptions): Promise<{ result: WarnResponse; caseNum: number | null }> { + public override async bushWarn(options: BushPunishmentOptions): Promise<{ result: WarnResponse; caseNum: number | null }> { let caseID: string | undefined = undefined; let dmSuccessEvent: boolean | undefined = undefined; const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.members.me); @@ -105,7 +188,7 @@ export class BushGuildMember extends GuildMember { * @returns A status message for adding the add. * @emits {@link BushClientEvents.bushPunishRole} */ - public async bushAddRole(options: AddRoleOptions): Promise<AddRoleResponse> { + public override async bushAddRole(options: AddRoleOptions): Promise<AddRoleResponse> { // checks if (!this.guild.members.me!.permissions.has(PermissionFlagsBits.ManageRoles)) return addRoleResponse.MISSING_PERMISSIONS; const ifShouldAddRole = this.#checkIfShouldAddRole(options.role, options.moderator); @@ -164,7 +247,7 @@ export class BushGuildMember extends GuildMember { options.reason ?? undefined, caseID!, options.duration ?? 0, - options.role as BushRole, + options.role, options.evidence ); return ret; @@ -176,7 +259,7 @@ export class BushGuildMember extends GuildMember { * @returns A status message for removing the role. * @emits {@link BushClientEvents.bushPunishRoleRemove} */ - public async bushRemoveRole(options: RemoveRoleOptions): Promise<RemoveRoleResponse> { + public override async bushRemoveRole(options: RemoveRoleOptions): Promise<RemoveRoleResponse> { // checks if (!this.guild.members.me!.permissions.has(PermissionFlagsBits.ManageRoles)) return removeRoleResponse.MISSING_PERMISSIONS; const ifShouldAddRole = this.#checkIfShouldAddRole(options.role, options.moderator); @@ -235,7 +318,7 @@ export class BushGuildMember extends GuildMember { this.guild, options.reason ?? undefined, caseID!, - options.role as BushRole, + options.role, options.evidence ); return ret; @@ -248,8 +331,8 @@ export class BushGuildMember extends GuildMember { * @returns `true` if the role should be added/removed or a string for the reason why it shouldn't. */ #checkIfShouldAddRole( - role: BushRole | Role, - moderator?: BushGuildMember + role: Role | Role, + moderator?: GuildMember ): true | 'user hierarchy' | 'role managed' | 'client hierarchy' { if (moderator && moderator.roles.highest.position <= role.position && this.guild.ownerId !== this.user.id) { return shouldAddRoleResponse.USER_HIERARCHY; @@ -267,7 +350,7 @@ export class BushGuildMember extends GuildMember { * @returns A status message for muting the user. * @emits {@link BushClientEvents.bushMute} */ - public async bushMute(options: BushTimedPunishmentOptions): Promise<MuteResponse> { + public override async bushMute(options: BushTimedPunishmentOptions): Promise<MuteResponse> { // checks if (!this.guild.members.me!.permissions.has(PermissionFlagsBits.ManageRoles)) return muteResponse.MISSING_PERMISSIONS; const muteRoleID = await this.guild.getSetting('muteRole'); @@ -353,7 +436,7 @@ export class BushGuildMember extends GuildMember { * @returns A status message for unmuting the user. * @emits {@link BushClientEvents.bushUnmute} */ - public async bushUnmute(options: BushPunishmentOptions): Promise<UnmuteResponse> { + public override async bushUnmute(options: BushPunishmentOptions): Promise<UnmuteResponse> { // checks if (!this.guild.members.me!.permissions.has(PermissionFlagsBits.ManageRoles)) return unmuteResponse.MISSING_PERMISSIONS; const muteRoleID = await this.guild.getSetting('muteRole'); @@ -436,7 +519,7 @@ export class BushGuildMember extends GuildMember { * @returns A status message for kicking the user. * @emits {@link BushClientEvents.bushKick} */ - public async bushKick(options: BushPunishmentOptions): Promise<KickResponse> { + public override async bushKick(options: BushPunishmentOptions): Promise<KickResponse> { // checks if (!this.guild.members.me?.permissions.has(PermissionFlagsBits.KickMembers) || !this.kickable) return kickResponse.MISSING_PERMISSIONS; @@ -490,7 +573,7 @@ export class BushGuildMember extends GuildMember { * @returns A status message for banning the user. * @emits {@link BushClientEvents.bushBan} */ - public async bushBan(options: BushBanOptions): Promise<Exclude<BanResponse, typeof banResponse['ALREADY_BANNED']>> { + public override async bushBan(options: BushBanOptions): Promise<Exclude<BanResponse, typeof banResponse['ALREADY_BANNED']>> { // checks if (!this.guild.members.me!.permissions.has(PermissionFlagsBits.BanMembers) || !this.bannable) return banResponse.MISSING_PERMISSIONS; @@ -570,7 +653,7 @@ export class BushGuildMember extends GuildMember { * Prevents a user from speaking in a channel. * @param options Options for blocking the user. */ - public async bushBlock(options: BlockOptions): Promise<BlockResponse> { + public override async bushBlock(options: BlockOptions): Promise<BlockResponse> { const channel = this.guild.channels.resolve(options.channel); if (!channel || (!channel.isTextBased() && !channel.isThread())) return blockResponse.INVALID_CHANNEL; @@ -660,10 +743,10 @@ export class BushGuildMember extends GuildMember { * Allows a user to speak in a channel. * @param options Options for unblocking the user. */ - public async bushUnblock(options: UnblockOptions): Promise<UnblockResponse> { + public override async bushUnblock(options: UnblockOptions): Promise<UnblockResponse> { const _channel = this.guild.channels.resolve(options.channel); - if (!_channel || (!_channel.isText() && !_channel.isThread())) return unblockResponse.INVALID_CHANNEL; - const channel = _channel as BushGuildTextBasedChannel; + if (!_channel || (_channel.type !== ChannelType.GuildText && !_channel.isThread())) return unblockResponse.INVALID_CHANNEL; + const channel = _channel as GuildTextBasedChannel; // checks if (!channel.permissionsFor(this.guild.members.me!)!.has(PermissionFlagsBits.ManageChannels)) @@ -747,7 +830,7 @@ export class BushGuildMember extends GuildMember { * Mutes a user using discord's timeout feature. * @param options Options for timing out the user. */ - public async bushTimeout(options: BushTimeoutOptions): Promise<TimeoutResponse> { + public override async bushTimeout(options: BushTimeoutOptions): Promise<TimeoutResponse> { // checks if (!this.guild.members.me!.permissions.has(PermissionFlagsBits.ModerateMembers)) return timeoutResponse.MISSING_PERMISSIONS; @@ -811,7 +894,7 @@ export class BushGuildMember extends GuildMember { * Removes a timeout from a user. * @param options Options for removing the timeout. */ - public async bushRemoveTimeout(options: BushPunishmentOptions): Promise<RemoveTimeoutResponse> { + public override async bushRemoveTimeout(options: BushPunishmentOptions): Promise<RemoveTimeoutResponse> { // checks if (!this.guild.members.me!.permissions.has(PermissionFlagsBits.ModerateMembers)) return removeTimeoutResponse.MISSING_PERMISSIONS; @@ -869,14 +952,14 @@ export class BushGuildMember extends GuildMember { /** * Whether or not the user is an owner of the bot. */ - public isOwner(): boolean { + public override isOwner(): boolean { return client.isOwner(this); } /** * Whether or not the user is a super user of the bot. */ - public isSuperUser(): boolean { + public override isSuperUser(): boolean { return client.isSuperUser(this); } } @@ -893,7 +976,7 @@ export interface BushPunishmentOptions { /** * The moderator who punished the user. */ - moderator?: BushGuildMember; + moderator?: GuildMember; /** * Evidence for the punishment. @@ -923,7 +1006,7 @@ export interface AddRoleOptions extends BushTimedPunishmentOptions { /** * The role to add to the user. */ - role: BushRole | Role; + role: Role; /** * Whether to create a modlog entry for this punishment. @@ -938,7 +1021,7 @@ export interface RemoveRoleOptions extends BushTimedPunishmentOptions { /** * The role to remove from the user. */ - role: BushRole | Role; + role: Role; /** * Whether to create a modlog entry for this punishment. @@ -963,7 +1046,7 @@ export interface BlockOptions extends BushTimedPunishmentOptions { /** * The channel to block the user from. */ - channel: BushGuildTextChannelResolvable | BushThreadChannelResolvable; + channel: GuildChannelResolvable; } /** @@ -973,7 +1056,7 @@ export interface UnblockOptions extends BushPunishmentOptions { /** * The channel to unblock the user from. */ - channel: BushGuildTextChannelResolvable | BushThreadChannelResolvable; + channel: GuildChannelResolvable; } /** @@ -1152,8 +1235,6 @@ export type TimeoutResponse = ValueOf<typeof timeoutResponse>; */ export type RemoveTimeoutResponse = ValueOf<typeof removeTimeoutResponse>; -export type PartialBushGuildMember = Partialize<BushGuildMember, 'joinedAt' | 'joinedTimestamp' | 'pending'>; - /** * @typedef {BushClientEvents} VSCodePleaseDontRemove */ diff --git a/src/lib/extensions/discord.js/ExtendedMessage.ts b/src/lib/extensions/discord.js/ExtendedMessage.ts new file mode 100644 index 0000000..4431077 --- /dev/null +++ b/src/lib/extensions/discord.js/ExtendedMessage.ts @@ -0,0 +1,12 @@ +import { CommandUtil } from 'discord-akairo'; +import { Message, type Client } from 'discord.js'; +import { type RawMessageData } from 'discord.js/typings/rawDataTypes.js'; + +export class ExtendedMessage<Cached extends boolean = boolean> extends Message<Cached> { + public declare util: CommandUtil<Message>; + + public constructor(client_: Client, data: RawMessageData) { + super(client_, data); + this.util = new CommandUtil(client.commandHandler, this); + } +} diff --git a/src/lib/extensions/discord.js/ExtendedUser.ts b/src/lib/extensions/discord.js/ExtendedUser.ts new file mode 100644 index 0000000..556ab85 --- /dev/null +++ b/src/lib/extensions/discord.js/ExtendedUser.ts @@ -0,0 +1,35 @@ +import { User, type Partialize } from 'discord.js'; + +declare module 'discord.js' { + export interface User { + /** + * Indicates whether the user is an owner of the bot. + */ + isOwner(): boolean; + /** + * Indicates whether the user is a superuser of the bot. + */ + isSuperUser(): boolean; + } +} + +export type PartialBushUser = Partialize<ExtendedUser, 'username' | 'tag' | 'discriminator' | 'isOwner' | 'isSuperUser'>; + +/** + * Represents a user on Discord. + */ +export class ExtendedUser extends User { + /** + * Indicates whether the user is an owner of the bot. + */ + public override isOwner(): boolean { + return client.isOwner(this); + } + + /** + * Indicates whether the user is a superuser of the bot. + */ + public override isSuperUser(): boolean { + return client.isSuperUser(this); + } +} diff --git a/src/lib/extensions/discord.js/other.ts b/src/lib/extensions/discord.js/other.ts deleted file mode 100644 index 0560ffc..0000000 --- a/src/lib/extensions/discord.js/other.ts +++ /dev/null @@ -1,188 +0,0 @@ -import type { - BushApplicationCommand, - BushCategoryChannel, - BushDMChannel, - BushGuild, - BushGuildEmoji, - BushGuildMember, - BushMessage, - BushNewsChannel, - BushReactionEmoji, - BushRole, - BushStageChannel, - BushTextChannel, - BushThreadChannel, - BushThreadMember, - BushUser, - BushVoiceChannel, - PartialBushDMChannel -} from '#lib'; -import { APIMessage } from 'discord-api-types/v10'; -import type { - ApplicationCommandResolvable, - CacheType, - CacheTypeReducer, - ChannelResolvable, - ChannelType, - Collection, - EmojiIdentifierResolvable, - EmojiResolvable, - FetchedThreads, - GuildChannelResolvable, - GuildMemberResolvable, - GuildTextChannelResolvable, - MessageResolvable, - PartialGroupDMChannel, - RoleResolvable, - Snowflake, - ThreadChannelResolvable, - ThreadMemberResolvable, - UserResolvable -} from 'discord.js'; - -/** - * Data that resolves to give a ThreadMember object. - */ -export type BushThreadMemberResolvable = ThreadMemberResolvable | BushThreadMember | BushUserResolvable; - -/** - * Data that resolves to give a User object. - */ -export type BushUserResolvable = UserResolvable | BushUser | Snowflake | BushMessage | BushGuildMember | BushThreadMember; - -/** - * Data that resolves to give a GuildMember object. - */ -export type BushGuildMemberResolvable = GuildMemberResolvable | BushGuildMember | BushUserResolvable; - -/** - * Data that can be resolved to a Role object. - */ -export type BushRoleResolvable = RoleResolvable | BushRole | Snowflake; - -/** - * Data that can be resolved to a Message object. - */ -export type BushMessageResolvable = MessageResolvable | BushMessage | Snowflake; - -/** - * Data that can be resolved into a GuildEmoji object. - */ -export type BushEmojiResolvable = EmojiResolvable | Snowflake | BushGuildEmoji | BushReactionEmoji; - -/** - * Data that can be resolved to give an emoji identifier. This can be: - * * The unicode representation of an emoji - * * The `<a:name:id>`, `<:name:id>`, `a:name:id` or `name:id` emoji identifier string of an emoji - * * An EmojiResolvable - */ -export type BushEmojiIdentifierResolvable = EmojiIdentifierResolvable | string | BushEmojiResolvable; - -/** - * Data that can be resolved to a Thread Channel object. - */ -export type BushThreadChannelResolvable = ThreadChannelResolvable | BushThreadChannel | Snowflake; - -/** - * Data that resolves to give an ApplicationCommand object. - */ -export type BushApplicationCommandResolvable = ApplicationCommandResolvable | BushApplicationCommand | Snowflake; - -/** - * Data that can be resolved to a GuildTextChannel object. - */ -export type BushGuildTextChannelResolvable = GuildTextChannelResolvable | BushTextChannel | BushNewsChannel | Snowflake; - -/** - * Data that can be resolved to give a Channel object. - */ -export type BushChannelResolvable = ChannelResolvable | BushAnyChannel | Snowflake; - -/** - * Data that can be resolved to give a Guild Channel object. - */ -export type BushGuildChannelResolvable = GuildChannelResolvable | Snowflake | BushGuildBasedChannel; - -export type BushAnyChannel = - | BushCategoryChannel - | BushDMChannel - | PartialBushDMChannel - | PartialGroupDMChannel - | BushNewsChannel - | BushStageChannel - | BushTextChannel - | BushThreadChannel - | BushVoiceChannel; - -/** - * The channels that are text-based. - */ -export type BushTextBasedChannel = - | BushDMChannel - | PartialBushDMChannel - | BushNewsChannel - | BushTextChannel - | BushThreadChannel - | BushVoiceChannel; - -/** - * The types of channels that are text-based. - */ -export type BushTextBasedChannelTypes = BushTextBasedChannel['type']; - -export type BushVoiceBasedChannel = Extract<BushAnyChannel, { bitrate: number }>; - -export type BushGuildBasedChannel = Extract<BushAnyChannel, { guild: BushGuild }>; - -export type BushNonCategoryGuildBasedChannel = Exclude<BushGuildBasedChannel, BushCategoryChannel>; - -export type BushNonThreadGuildBasedChannel = Exclude<BushGuildBasedChannel, BushThreadChannel>; - -export type BushGuildTextBasedChannel = Extract<BushGuildBasedChannel, BushTextBasedChannel>; - -/** - * Data that can be resolved to a Text Channel object. - */ -export type BushTextChannelResolvable = Snowflake | BushTextChannel; - -/** - * Data that can be resolved to a GuildVoiceChannel object. - */ -export type BushGuildVoiceChannelResolvable = BushVoiceBasedChannel | Snowflake; - -export interface BushMappedChannelCategoryTypes { - [ChannelType.GuildNews]: BushNewsChannel; - [ChannelType.GuildVoice]: BushVoiceChannel; - [ChannelType.GuildText]: BushTextChannel; - [ChannelType.GuildStageVoice]: BushStageChannel; - [ChannelType.GuildForum]: never; // TODO: Fix when guild forums come out -} - -export type BushMappedGuildChannelTypes = { - [ChannelType.GuildCategory]: BushCategoryChannel; -} & BushMappedChannelCategoryTypes; - -/** - * The data returned from a thread fetch that returns multiple threads. - */ -export interface BushFetchedThreads extends FetchedThreads { - /** - * The threads that were fetched, with any members returned - */ - threads: Collection<Snowflake, BushThreadChannel>; - - /** - * Whether there are potentially additional threads that require a subsequent call - */ - hasMore?: boolean; -} - -export type BushGuildCacheMessage<Cached extends CacheType> = CacheTypeReducer< - Cached, - BushMessage<true>, - APIMessage, - BushMessage | APIMessage, - BushMessage | APIMessage ->; - -export { ApplicationCommandOptionType as SlashType } from 'discord.js'; |