From 661e4c9935aeb8760dafc7ced4bbec6cc356a033 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Tue, 14 Jun 2022 12:47:57 -0400 Subject: 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 --- .../discord-akairo/BushArgumentTypeCaster.ts | 4 +- src/lib/extensions/discord-akairo/BushClient.ts | 146 +-- .../extensions/discord-akairo/BushClientUtil.ts | 49 +- src/lib/extensions/discord-akairo/BushCommand.ts | 87 +- .../discord-akairo/BushCommandHandler.ts | 45 +- .../extensions/discord-akairo/BushCommandUtil.ts | 22 - src/lib/extensions/discord-akairo/BushInhibitor.ts | 9 +- .../discord-akairo/BushInhibitorHandler.ts | 5 +- src/lib/extensions/discord-akairo/BushListener.ts | 3 - .../discord-akairo/BushListenerHandler.ts | 5 +- .../extensions/discord-akairo/BushSlashMessage.ts | 34 - src/lib/extensions/discord-akairo/BushTask.ts | 11 +- .../extensions/discord-akairo/BushTaskHandler.ts | 9 +- src/lib/extensions/discord-akairo/SlashMessage.ts | 3 + src/lib/extensions/discord.js/BushActivity.ts | 14 - .../discord.js/BushApplicationCommand.ts | 16 - .../discord.js/BushApplicationCommandManager.ts | 151 --- .../BushApplicationCommandPermissionsManager.ts | 184 --- .../discord.js/BushBaseGuildEmojiManager.ts | 19 - .../discord.js/BushBaseGuildTextChannel.ts | 28 - .../discord.js/BushBaseGuildVoiceChannel.ts | 13 - .../extensions/discord.js/BushButtonInteraction.ts | 30 - .../extensions/discord.js/BushCategoryChannel.ts | 41 - .../discord.js/BushCategoryChannelChildManager.ts | 44 - src/lib/extensions/discord.js/BushChannel.ts | 39 - .../extensions/discord.js/BushChannelManager.ts | 25 - .../discord.js/BushChatInputCommandInteraction.ts | 49 - src/lib/extensions/discord.js/BushClientEvents.ts | 291 ++--- src/lib/extensions/discord.js/BushClientUser.ts | 98 -- src/lib/extensions/discord.js/BushDMChannel.ts | 45 - src/lib/extensions/discord.js/BushEmoji.ts | 14 - src/lib/extensions/discord.js/BushGuild.ts | 782 ------------ .../BushGuildApplicationCommandManager.ts | 114 -- src/lib/extensions/discord.js/BushGuildBan.ts | 15 - src/lib/extensions/discord.js/BushGuildChannel.ts | 47 - .../discord.js/BushGuildChannelManager.ts | 183 --- src/lib/extensions/discord.js/BushGuildEmoji.ts | 20 - .../discord.js/BushGuildEmojiRoleManager.ts | 55 - src/lib/extensions/discord.js/BushGuildManager.ts | 35 - src/lib/extensions/discord.js/BushGuildMember.ts | 1159 ------------------ .../discord.js/BushGuildMemberManager.ts | 177 --- src/lib/extensions/discord.js/BushMessage.ts | 63 - .../extensions/discord.js/BushMessageManager.ts | 113 -- .../extensions/discord.js/BushMessageReaction.ts | 20 - .../discord.js/BushModalSubmitInteraction.ts | 96 -- src/lib/extensions/discord.js/BushNewsChannel.ts | 15 - src/lib/extensions/discord.js/BushPresence.ts | 19 - src/lib/extensions/discord.js/BushReactionEmoji.ts | 16 - src/lib/extensions/discord.js/BushRole.ts | 18 - .../discord.js/BushSelectMenuInteraction.ts | 30 - src/lib/extensions/discord.js/BushStageChannel.ts | 20 - src/lib/extensions/discord.js/BushStageInstance.ts | 17 - src/lib/extensions/discord.js/BushTextChannel.ts | 42 - src/lib/extensions/discord.js/BushThreadChannel.ts | 47 - src/lib/extensions/discord.js/BushThreadManager.ts | 84 -- src/lib/extensions/discord.js/BushThreadMember.ts | 19 - .../discord.js/BushThreadMemberManager.ts | 62 - src/lib/extensions/discord.js/BushUser.ts | 34 - src/lib/extensions/discord.js/BushUserManager.ts | 60 - src/lib/extensions/discord.js/BushVoiceChannel.ts | 40 - src/lib/extensions/discord.js/BushVoiceState.ts | 20 - src/lib/extensions/discord.js/ExtendedGuild.ts | 870 ++++++++++++++ .../extensions/discord.js/ExtendedGuildMember.ts | 1240 ++++++++++++++++++++ src/lib/extensions/discord.js/ExtendedMessage.ts | 12 + src/lib/extensions/discord.js/ExtendedUser.ts | 35 + src/lib/extensions/discord.js/other.ts | 188 --- 66 files changed, 2380 insertions(+), 4920 deletions(-) delete mode 100644 src/lib/extensions/discord-akairo/BushCommandUtil.ts delete mode 100644 src/lib/extensions/discord-akairo/BushSlashMessage.ts create mode 100644 src/lib/extensions/discord-akairo/SlashMessage.ts delete mode 100644 src/lib/extensions/discord.js/BushActivity.ts delete mode 100644 src/lib/extensions/discord.js/BushApplicationCommand.ts delete mode 100644 src/lib/extensions/discord.js/BushApplicationCommandManager.ts delete mode 100644 src/lib/extensions/discord.js/BushApplicationCommandPermissionsManager.ts delete mode 100644 src/lib/extensions/discord.js/BushBaseGuildEmojiManager.ts delete mode 100644 src/lib/extensions/discord.js/BushBaseGuildTextChannel.ts delete mode 100644 src/lib/extensions/discord.js/BushBaseGuildVoiceChannel.ts delete mode 100644 src/lib/extensions/discord.js/BushButtonInteraction.ts delete mode 100644 src/lib/extensions/discord.js/BushCategoryChannel.ts delete mode 100644 src/lib/extensions/discord.js/BushCategoryChannelChildManager.ts delete mode 100644 src/lib/extensions/discord.js/BushChannel.ts delete mode 100644 src/lib/extensions/discord.js/BushChannelManager.ts delete mode 100644 src/lib/extensions/discord.js/BushChatInputCommandInteraction.ts delete mode 100644 src/lib/extensions/discord.js/BushClientUser.ts delete mode 100644 src/lib/extensions/discord.js/BushDMChannel.ts delete mode 100644 src/lib/extensions/discord.js/BushEmoji.ts delete mode 100644 src/lib/extensions/discord.js/BushGuild.ts delete mode 100644 src/lib/extensions/discord.js/BushGuildApplicationCommandManager.ts delete mode 100644 src/lib/extensions/discord.js/BushGuildBan.ts delete mode 100644 src/lib/extensions/discord.js/BushGuildChannel.ts delete mode 100644 src/lib/extensions/discord.js/BushGuildChannelManager.ts delete mode 100644 src/lib/extensions/discord.js/BushGuildEmoji.ts delete mode 100644 src/lib/extensions/discord.js/BushGuildEmojiRoleManager.ts delete mode 100644 src/lib/extensions/discord.js/BushGuildManager.ts delete mode 100644 src/lib/extensions/discord.js/BushGuildMember.ts delete mode 100644 src/lib/extensions/discord.js/BushGuildMemberManager.ts delete mode 100644 src/lib/extensions/discord.js/BushMessage.ts delete mode 100644 src/lib/extensions/discord.js/BushMessageManager.ts delete mode 100644 src/lib/extensions/discord.js/BushMessageReaction.ts delete mode 100644 src/lib/extensions/discord.js/BushModalSubmitInteraction.ts delete mode 100644 src/lib/extensions/discord.js/BushNewsChannel.ts delete mode 100644 src/lib/extensions/discord.js/BushPresence.ts delete mode 100644 src/lib/extensions/discord.js/BushReactionEmoji.ts delete mode 100644 src/lib/extensions/discord.js/BushRole.ts delete mode 100644 src/lib/extensions/discord.js/BushSelectMenuInteraction.ts delete mode 100644 src/lib/extensions/discord.js/BushStageChannel.ts delete mode 100644 src/lib/extensions/discord.js/BushStageInstance.ts delete mode 100644 src/lib/extensions/discord.js/BushTextChannel.ts delete mode 100644 src/lib/extensions/discord.js/BushThreadChannel.ts delete mode 100644 src/lib/extensions/discord.js/BushThreadManager.ts delete mode 100644 src/lib/extensions/discord.js/BushThreadMember.ts delete mode 100644 src/lib/extensions/discord.js/BushThreadMemberManager.ts delete mode 100644 src/lib/extensions/discord.js/BushUser.ts delete mode 100644 src/lib/extensions/discord.js/BushUserManager.ts delete mode 100644 src/lib/extensions/discord.js/BushVoiceChannel.ts delete mode 100644 src/lib/extensions/discord.js/BushVoiceState.ts create mode 100644 src/lib/extensions/discord.js/ExtendedGuild.ts create mode 100644 src/lib/extensions/discord.js/ExtendedGuildMember.ts create mode 100644 src/lib/extensions/discord.js/ExtendedMessage.ts create mode 100644 src/lib/extensions/discord.js/ExtendedUser.ts delete mode 100644 src/lib/extensions/discord.js/other.ts (limited to 'src/lib/extensions') diff --git a/src/lib/extensions/discord-akairo/BushArgumentTypeCaster.ts b/src/lib/extensions/discord-akairo/BushArgumentTypeCaster.ts index 7a9a3db..def7ad6 100644 --- a/src/lib/extensions/discord-akairo/BushArgumentTypeCaster.ts +++ b/src/lib/extensions/discord-akairo/BushArgumentTypeCaster.ts @@ -1,3 +1,3 @@ -import { type BushMessage } from '#lib'; +import { type CommandMessage } from '#lib'; -export type BushArgumentTypeCaster = (message: BushMessage, phrase: string) => R; +export type BushArgumentTypeCaster = (message: CommandMessage, phrase: string) => R; diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts index db0ad91..2644231 100644 --- a/src/lib/extensions/discord-akairo/BushClient.ts +++ b/src/lib/extensions/discord-akairo/BushClient.ts @@ -10,28 +10,20 @@ import { roleWithDuration, snowflake } from '#args'; -import type { - BushBaseGuildEmojiManager, - BushChannelManager, - BushClientEvents, - BushClientUser, - BushGuildManager, - BushUserManager, - BushUserResolvable, - Config -} from '#lib'; +import type { BushClientEvents, Config } from '#lib'; import { patch, type PatchedElements } from '@notenoughupdates/events-intercept'; import * as Sentry from '@sentry/node'; import { AkairoClient, - ArgumentPromptData, ContextMenuCommandHandler, - OtherwiseContentSupplier, - version as akairoVersion + version as akairoVersion, + type ArgumentPromptData, + type ClientUtil, + type OtherwiseContentSupplier } from 'discord-akairo'; -import { GatewayIntentBits } from 'discord-api-types/v10'; import { ActivityType, + GatewayIntentBits, MessagePayload, Options, Partials, @@ -45,19 +37,21 @@ import { type MessageOptions, type ReplyMessageOptions, type Snowflake, + type UserResolvable, type WebhookEditMessageOptions } from 'discord.js'; -import EventEmitter from 'events'; +import type EventEmitter from 'events'; import { google } from 'googleapis'; import path from 'path'; import readline from 'readline'; import type { Options as SequelizeOptions, Sequelize as SequelizeType } from 'sequelize'; import { fileURLToPath } from 'url'; +import { tinyColor } from '../../../arguments/tinyColor.js'; import UpdateCacheTask from '../../../tasks/updateCache.js'; import UpdateStatsTask from '../../../tasks/updateStats.js'; import { HighlightManager } from '../../common/HighlightManager.js'; import { ActivePunishment } from '../../models/instance/ActivePunishment.js'; -import { Guild as GuildModel } from '../../models/instance/Guild.js'; +import { Guild as GuildDB } from '../../models/instance/Guild.js'; import { Highlight } from '../../models/instance/Highlight.js'; import { Level } from '../../models/instance/Level.js'; import { ModLog } from '../../models/instance/ModLog.js'; @@ -71,26 +65,10 @@ import { AllowedMentions } from '../../utils/AllowedMentions.js'; import { BushCache } from '../../utils/BushCache.js'; import { BushConstants } from '../../utils/BushConstants.js'; import { BushLogger } from '../../utils/BushLogger.js'; -import { BushButtonInteraction } from '../discord.js/BushButtonInteraction.js'; -import { BushCategoryChannel } from '../discord.js/BushCategoryChannel.js'; -import { BushChatInputCommandInteraction } from '../discord.js/BushChatInputCommandInteraction.js'; -import { BushDMChannel } from '../discord.js/BushDMChannel.js'; -import { BushGuild } from '../discord.js/BushGuild.js'; -import { BushGuildEmoji } from '../discord.js/BushGuildEmoji.js'; -import { BushGuildMember } from '../discord.js/BushGuildMember.js'; -import { BushMessage } from '../discord.js/BushMessage.js'; -import { BushMessageReaction } from '../discord.js/BushMessageReaction.js'; -import { BushModalSubmitInteraction } from '../discord.js/BushModalSubmitInteraction.js'; -import { BushNewsChannel } from '../discord.js/BushNewsChannel.js'; -import { BushPresence } from '../discord.js/BushPresence.js'; -import { BushRole } from '../discord.js/BushRole.js'; -import { BushSelectMenuInteraction } from '../discord.js/BushSelectMenuInteraction.js'; -import { BushTextChannel } from '../discord.js/BushTextChannel.js'; -import { BushThreadChannel } from '../discord.js/BushThreadChannel.js'; -import { BushThreadMember } from '../discord.js/BushThreadMember.js'; -import { BushUser } from '../discord.js/BushUser.js'; -import { BushVoiceChannel } from '../discord.js/BushVoiceChannel.js'; -import { BushVoiceState } from '../discord.js/BushVoiceState.js'; +import { ExtendedGuild } from '../discord.js/ExtendedGuild.js'; +import { ExtendedGuildMember } from '../discord.js/ExtendedGuildMember.js'; +import { ExtendedMessage } from '../discord.js/ExtendedMessage.js'; +import { ExtendedUser } from '../discord.js/ExtendedUser.js'; import { BushClientUtil } from './BushClientUtil.js'; import { BushCommandHandler } from './BushCommandHandler.js'; import { BushInhibitorHandler } from './BushInhibitorHandler.js'; @@ -98,11 +76,43 @@ import { BushListenerHandler } from './BushListenerHandler.js'; import { BushTaskHandler } from './BushTaskHandler.js'; const { Sequelize } = (await import('sequelize')).default; -export type BushReplyMessageType = string | MessagePayload | ReplyMessageOptions; -export type BushEditMessageType = string | MessageEditOptions | MessagePayload; -export type BushSlashSendMessageType = string | MessagePayload | InteractionReplyOptions; -export type BushSlashEditMessageType = string | MessagePayload | WebhookEditMessageOptions; -export type BushSendMessageType = string | MessagePayload | MessageOptions; +declare module 'discord.js' { + export interface Client extends EventEmitter { + /** + * The ID of the owner(s). + */ + ownerID: Snowflake | Snowflake[]; + /** + * The ID of the superUser(s). + */ + superUserID: Snowflake | Snowflake[]; + /** + * Utility methods. + */ + util: ClientUtil | BushClientUtil; + on(event: K, listener: (...args: BushClientEvents[K]) => Awaitable): this; + once(event: K, listener: (...args: BushClientEvents[K]) => Awaitable): this; + emit(event: K, ...args: BushClientEvents[K]): boolean; + off(event: K, listener: (...args: BushClientEvents[K]) => Awaitable): this; + removeAllListeners(event?: K): this; + /** + * Checks if a user is the owner of this bot. + * @param user - User to check. + */ + isOwner(user: UserResolvable): boolean; + /** + * Checks if a user is a super user of this bot. + * @param user - User to check. + */ + isSuperUser(user: UserResolvable): boolean; + } +} + +export type ReplyMessageType = string | MessagePayload | ReplyMessageOptions; +export type EditMessageType = string | MessageEditOptions | MessagePayload; +export type SlashSendMessageType = string | MessagePayload | InteractionReplyOptions; +export type SlashEditMessageType = string | MessagePayload | WebhookEditMessageOptions; +export type SendMessageType = string | MessagePayload | MessageOptions; const rl = readline.createInterface({ input: process.stdin, @@ -116,12 +126,9 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url)); * The main hub for interacting with the Discord API. */ export class BushClient extends AkairoClient { - public declare channels: BushChannelManager; - public declare guilds: BushGuildManager; - public declare user: If; - public declare users: BushUserManager; - public declare util: BushClientUtil; public declare ownerID: Snowflake[]; + public declare superUserID: Snowflake[]; + public declare util: BushClientUtil; /** * Whether or not the client is ready. @@ -272,7 +279,7 @@ export class BushClient extends AkairoClient { if (this.config.isDevelopment) return 'dev '; if (!guild) return this.config.prefix; - const prefix = await (guild as BushGuild).getSetting('prefix'); + const prefix = await guild.getSetting('prefix'); return (prefix ?? this.config.prefix) as string; }, allowMention: true, @@ -296,7 +303,6 @@ export class BushClient extends AkairoClient extends AkairoClient BushGuildEmoji); - Structures.extend('DMChannel', () => BushDMChannel); - Structures.extend('TextChannel', () => BushTextChannel); - Structures.extend('VoiceChannel', () => BushVoiceChannel); - Structures.extend('CategoryChannel', () => BushCategoryChannel); - Structures.extend('NewsChannel', () => BushNewsChannel); - Structures.extend('ThreadChannel', () => BushThreadChannel); - Structures.extend('GuildMember', () => BushGuildMember); - Structures.extend('ThreadMember', () => BushThreadMember); - Structures.extend('Guild', () => BushGuild); - Structures.extend('Message', () => BushMessage); - Structures.extend('MessageReaction', () => BushMessageReaction); - Structures.extend('Presence', () => BushPresence); - Structures.extend('VoiceState', () => BushVoiceState); - Structures.extend('Role', () => BushRole); - Structures.extend('User', () => BushUser); - Structures.extend('ChatInputCommandInteraction', () => BushChatInputCommandInteraction); - Structures.extend('ButtonInteraction', () => BushButtonInteraction); - Structures.extend('SelectMenuInteraction', () => BushSelectMenuInteraction); - Structures.extend('ModalSubmitInteraction', () => BushModalSubmitInteraction); + Structures.extend('GuildMember', () => ExtendedGuildMember); + Structures.extend('Guild', () => ExtendedGuild); + Structures.extend('Message', () => ExtendedMessage); + Structures.extend('User', () => ExtendedUser); } /** @@ -407,7 +397,8 @@ export class BushClient extends AkairoClient extends AkairoClient extends AkairoClient extends EventEmitter, PatchedElements, AkairoClient { - get emojis(): BushBaseGuildEmojiManager; - on(event: K, listener: (...args: BushClientEvents[K]) => Awaitable): this; - // on(event: Exclude, listener: (...args: any[]) => Awaitable): this; - once(event: K, listener: (...args: BushClientEvents[K]) => Awaitable): this; - // once(event: Exclude, listener: (...args: any[]) => Awaitable): this; - emit(event: K, ...args: BushClientEvents[K]): boolean; - // emit(event: Exclude, ...args: unknown[]): boolean; - off(event: K, listener: (...args: BushClientEvents[K]) => Awaitable): this; - // off(event: Exclude, listener: (...args: any[]) => Awaitable): this; - removeAllListeners(event?: K): this; - // removeAllListeners(event?: Exclude): this; } export interface BushStats { diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts index 9fe70fa..19810bd 100644 --- a/src/lib/extensions/discord-akairo/BushClientUtil.ts +++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts @@ -1,41 +1,43 @@ import { Arg, - BaseBushArgumentType, BushConstants, + CommandMessage, Global, Shared, - SharedCache, + type BaseBushArgumentType, type BushClient, type BushInspectOptions, - type BushMessage, - type BushSlashEditMessageType, - type BushSlashMessage, - type BushSlashSendMessageType, - type BushUser, type CodeBlockLang, type GlobalCache, type Pronoun, - type PronounCode + type PronounCode, + type SharedCache, + type SlashEditMessageType, + type SlashMessage, + type SlashSendMessageType } from '#lib'; import { humanizeDuration } from '@notenoughupdates/humanize-duration'; import assert from 'assert'; import { exec } from 'child_process'; import deepLock from 'deep-lock'; import { ClientUtil, Util as AkairoUtil } from 'discord-akairo'; -import { APIEmbed, APIMessage, OAuth2Scopes, Routes } from 'discord-api-types/v10'; import { Constants as DiscordConstants, EmbedBuilder, GuildMember, Message, + OAuth2Scopes, PermissionFlagsBits, PermissionsBitField, - PermissionsString, + Routes, ThreadMember, User, Util as DiscordUtil, + type APIEmbed, + type APIMessage, type CommandInteraction, type InteractionReplyOptions, + type PermissionsString, type Snowflake, type TextChannel, type UserResolvable @@ -377,7 +379,7 @@ export class BushClientUtil extends ClientUtil { */ public async slashRespond( interaction: CommandInteraction, - responseOptions: BushSlashSendMessageType | BushSlashEditMessageType + responseOptions: SlashSendMessageType | SlashEditMessageType ): Promise { const newResponseOptions = typeof responseOptions === 'string' ? { content: responseOptions } : responseOptions; if (interaction.replied || interaction.deferred) { @@ -696,17 +698,17 @@ export class BushClientUtil extends ClientUtil { * @param user The user to fetch * @returns Undefined if the user is not found, otherwise the user. */ - public async resolveNonCachedUser(user: UserResolvable | undefined | null): Promise { + public async resolveNonCachedUser(user: UserResolvable | undefined | null): Promise { if (user == null) return undefined; const resolvedUser = user instanceof User - ? user + ? user : user instanceof GuildMember - ? user.user + ? user.user : user instanceof ThreadMember - ? user.user + ? user.user : user instanceof Message - ? user.author + ? user.author : undefined; return resolvedUser ?? (await client.users.fetch(user as Snowflake).catch(() => undefined)); @@ -831,9 +833,10 @@ export class BushClientUtil extends ClientUtil { * @returns The missing permissions or null if none are missing. */ public userGuildPermCheck( - message: BushMessage | BushSlashMessage, + message: CommandMessage | SlashMessage, permissions: typeof PermissionFlagsBits[keyof typeof PermissionFlagsBits][] ): PermissionsString[] | null { + if (!message.inGuild()) return null; const missing = message.member?.permissions.missing(permissions) ?? []; return missing.length ? missing : null; @@ -845,7 +848,7 @@ export class BushClientUtil extends ClientUtil { * @param permissions The permissions to check for. * @returns The missing permissions or null if none are missing. */ - public clientGuildPermCheck(message: BushMessage | BushSlashMessage, permissions: bigint[]): PermissionsString[] | null { + public clientGuildPermCheck(message: CommandMessage | SlashMessage, permissions: bigint[]): PermissionsString[] | null { const missing = message.guild?.members.me?.permissions.missing(permissions) ?? []; return missing.length ? missing : null; @@ -860,7 +863,7 @@ export class BushClientUtil extends ClientUtil { * @returns The missing permissions or null if none are missing. */ public clientSendAndPermCheck( - message: BushMessage | BushSlashMessage, + message: CommandMessage | SlashMessage, permissions: bigint[] = [], checkChannel = false ): PermissionsString[] | null { @@ -868,7 +871,7 @@ export class BushClientUtil extends ClientUtil { const sendPerm = message.channel!.isThread() ? 'SendMessages' : 'SendMessagesInThreads'; if (!message.inGuild()) return null; - if (!message.guild.members.me!.permissionsIn(message.channel.id).has(sendPerm)) missing.push(sendPerm); + if (!message.guild.members.me!.permissionsIn(message.channel!.id).has(sendPerm)) missing.push(sendPerm); missing.push( ...(checkChannel @@ -884,7 +887,7 @@ export class BushClientUtil extends ClientUtil { * @param message The message to get the prefix from. * @returns The prefix. */ - public prefix(message: BushMessage | BushSlashMessage): string { + public prefix(message: CommandMessage | SlashMessage): string { return message.util.isSlash ? '/' : client.config.isDevelopment @@ -970,7 +973,7 @@ export class BushClientUtil extends ClientUtil { */ public async castDurationContent( arg: string | ParsedDuration | null, - message: BushMessage | BushSlashMessage + message: CommandMessage | SlashMessage ): Promise { const res = typeof arg === 'string' ? await util.arg.cast('contentWithDuration', message, arg) : arg; @@ -987,7 +990,7 @@ export class BushClientUtil extends ClientUtil { public async cast( type: T, arg: BaseBushArgumentType[T] | string, - message: BushMessage | BushSlashMessage + message: CommandMessage | SlashMessage ) { return typeof arg === 'string' ? await util.arg.cast(type, message, arg) : arg; } diff --git a/src/lib/extensions/discord-akairo/BushCommand.ts b/src/lib/extensions/discord-akairo/BushCommand.ts index c727e98..5fb4e06 100644 --- a/src/lib/extensions/discord-akairo/BushCommand.ts +++ b/src/lib/extensions/discord-akairo/BushCommand.ts @@ -1,33 +1,17 @@ import { type DiscordEmojiInfo, type RoleWithDuration } from '#args'; import { type BushArgumentTypeCaster, - type BushBaseGuildVoiceChannel, - type BushCategoryChannel, type BushClient, type BushCommandHandler, - type BushEmoji, - type BushGuild, - type BushGuildBasedChannel, - type BushGuildChannel, - type BushGuildEmoji, - type BushGuildMember, type BushInhibitor, type BushListener, - type BushMessage, - type BushNewsChannel, - type BushRole, - type BushSlashMessage, - type BushStageChannel, type BushTask, - type BushTextChannel, - type BushThreadChannel, - type BushUser, - type BushVoiceChannel, type ParsedDuration } from '#lib'; import { ArgumentMatch, Command, + CommandUtil, type AkairoApplicationCommandAutocompleteOption, type AkairoApplicationCommandChannelOptionData, type AkairoApplicationCommandChoicesData, @@ -47,51 +31,17 @@ import { type SlashResolveType } from 'discord-akairo'; import { + Message, + User, type ApplicationCommandOptionChoiceData, - type Collection, - type Invite, type PermissionResolvable, type PermissionsString, type Snowflake } from 'discord.js'; import _ from 'lodash'; +import { SlashMessage } from './SlashMessage.js'; export interface OverriddenBaseArgumentType extends BaseArgumentType { - user: BushUser | null; - users: Collection | null; - member: BushGuildMember | null; - members: Collection | null; - relevant: BushUser | BushGuildMember | null; - relevants: Collection | Collection | null; - channel: BushGuildBasedChannel | BushBaseGuildVoiceChannel | null; - channels: Collection | null; - textChannel: BushTextChannel | null; - textChannels: Collection | null; - voiceChannel: BushVoiceChannel | null; - voiceChannels: Collection | null; - categoryChannel: BushCategoryChannel | null; - categoryChannels: Collection | null; - newsChannel: BushNewsChannel | null; - newsChannels: Collection | null; - stageChannel: BushStageChannel | null; - stageChannels: Collection | null; - threadChannel: BushThreadChannel | null; - threadChannels: Collection | null; - role: BushRole | null; - roles: Collection | null; - emoji: BushEmoji | null; - emojis: Collection | null; - guild: BushGuild | null; - guilds: Collection | null; - message: BushMessage | null; - guildMessage: BushMessage | null; - relevantMessage: BushMessage | null; - invite: Invite | null; - userMention: BushUser | null; - memberMention: BushGuildMember | null; - channelMention: BushThreadChannel | BushGuildChannel | null; - roleMention: BushRole | null; - emojiMention: BushGuildEmoji | null; commandAlias: BushCommand | null; command: BushCommand | null; inhibitor: BushInhibitor | null; @@ -108,9 +58,10 @@ export interface BaseBushArgumentType extends OverriddenBaseArgumentType { discordEmoji: DiscordEmojiInfo | null; roleWithDuration: RoleWithDuration | null; abbreviatedNumber: number | null; - globalUser: BushUser | null; - messageLink: BushMessage | null; + globalUser: User | null; + messageLink: Message | null; durationSeconds: number | null; + tinyColor: string | null; } export type BushArgumentType = keyof BaseBushArgumentType | RegExp; @@ -247,6 +198,7 @@ export interface BushArgumentOptions extends BaseBushArgumentOptions { */ type?: BushArgumentType | (keyof BaseBushArgumentType)[] | BushArgumentTypeCaster; } + export interface CustomBushArgumentOptions extends BaseBushArgumentOptions { /** * An array of strings can be used to restrict input to only those strings, case insensitive. @@ -259,7 +211,7 @@ export interface CustomBushArgumentOptions extends BaseBushArgumentOptions { customType?: (string | string[])[] | RegExp | string | null; } -export type BushMissingPermissionSupplier = (message: BushMessage | BushSlashMessage) => Promise | any; +export type BushMissingPermissionSupplier = (message: CommandMessage | SlashMessage) => Promise | any; interface ExtendedCommandOptions { /** @@ -407,9 +359,7 @@ export interface ArgsInfo { export class BushCommand extends Command { public declare client: BushClient; - public declare handler: BushCommandHandler; - public declare description: string; /** @@ -595,13 +545,13 @@ export interface BushCommand extends Command { * @param message - Message that triggered the command. * @param args - Evaluated arguments. */ - exec(message: BushMessage, args: any): any; + exec(message: CommandMessage, args: any): any; /** * Executes the command. * @param message - Message that triggered the command. * @param args - Evaluated arguments. */ - exec(message: BushMessage | BushSlashMessage, args: any): any; + exec(message: CommandMessage | SlashMessage, args: any): any; } type SlashOptionKeys = @@ -615,7 +565,22 @@ type SlashOptionKeys = interface PseudoArguments extends BaseBushArgumentType { boolean: boolean; + flag: boolean; + regex: { match: RegExpMatchArray; matches: RegExpExecArray[] }; } export type ArgType = NonNullable; export type OptArgType = PseudoArguments[T]; + +/** + * `util` is always defined for messages after `'all'` inhibitors + */ +export type CommandMessage = Message & { + /** + * Extra properties applied to the Discord.js message object. + * Utilities for command responding. + * Available on all messages after 'all' inhibitors and built-in inhibitors (bot, client). + * Not all properties of the util are available, depending on the input. + * */ + util: CommandUtil; +}; diff --git a/src/lib/extensions/discord-akairo/BushCommandHandler.ts b/src/lib/extensions/discord-akairo/BushCommandHandler.ts index 2c1903f..f095356 100644 --- a/src/lib/extensions/discord-akairo/BushCommandHandler.ts +++ b/src/lib/extensions/discord-akairo/BushCommandHandler.ts @@ -1,35 +1,30 @@ -import { type BushClient, type BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { type BushClient, type BushCommand, type CommandMessage, type SlashMessage } from '#lib'; import { CommandHandler, type Category, type CommandHandlerEvents, type CommandHandlerOptions } from 'discord-akairo'; -import { type Collection, type PermissionsString } from 'discord.js'; +import { type Collection, type Message, type PermissionsString } from 'discord.js'; export type BushCommandHandlerOptions = CommandHandlerOptions; export interface BushCommandHandlerEvents extends CommandHandlerEvents { - commandBlocked: [message: BushMessage, command: BushCommand, reason: string]; - commandBreakout: [message: BushMessage, command: BushCommand, breakMessage: BushMessage]; - commandCancelled: [message: BushMessage, command: BushCommand, retryMessage?: BushMessage]; - commandFinished: [message: BushMessage, command: BushCommand, args: any, returnValue: any]; - commandInvalid: [message: BushMessage, command: BushCommand]; - commandLocked: [message: BushMessage, command: BushCommand]; - commandStarted: [message: BushMessage, command: BushCommand, args: any]; - cooldown: [message: BushMessage | BushSlashMessage, command: BushCommand, remaining: number]; - error: [error: Error, message: BushMessage, command?: BushCommand]; - inPrompt: [message: BushMessage]; + commandBlocked: [message: CommandMessage, command: BushCommand, reason: string]; + commandBreakout: [message: CommandMessage, command: BushCommand, /* no util */ breakMessage: Message]; + commandCancelled: [message: CommandMessage, command: BushCommand, /* no util */ retryMessage?: Message]; + commandFinished: [message: CommandMessage, command: BushCommand, args: any, returnValue: any]; + commandInvalid: [message: CommandMessage, command: BushCommand]; + commandLocked: [message: CommandMessage, command: BushCommand]; + commandStarted: [message: CommandMessage, command: BushCommand, args: any]; + cooldown: [message: CommandMessage | SlashMessage, command: BushCommand, remaining: number]; + error: [error: Error, message: /* no util */ Message, command?: BushCommand]; + inPrompt: [message: /* no util */ Message]; load: [command: BushCommand, isReload: boolean]; - messageBlocked: [message: BushMessage | BushSlashMessage, reason: string]; - messageInvalid: [message: BushMessage]; - missingPermissions: [message: BushMessage, command: BushCommand, type: 'client' | 'user', missing: PermissionsString[]]; + messageBlocked: [message: /* no util */ Message | CommandMessage | SlashMessage, reason: string]; + messageInvalid: [message: CommandMessage]; + missingPermissions: [message: CommandMessage, command: BushCommand, type: 'client' | 'user', missing: PermissionsString[]]; remove: [command: BushCommand]; - slashBlocked: [message: BushSlashMessage, command: BushCommand, reason: string]; - slashError: [error: Error, message: BushSlashMessage, command: BushCommand]; - slashFinished: [message: BushSlashMessage, command: BushCommand, args: any, returnValue: any]; - slashMissingPermissions: [ - message: BushSlashMessage, - command: BushCommand, - type: 'client' | 'user', - missing: PermissionsString[] - ]; - slashStarted: [message: BushSlashMessage, command: BushCommand, args: any]; + slashBlocked: [message: SlashMessage, command: BushCommand, reason: string]; + slashError: [error: Error, message: SlashMessage, command: BushCommand]; + slashFinished: [message: SlashMessage, command: BushCommand, args: any, returnValue: any]; + slashMissingPermissions: [message: SlashMessage, command: BushCommand, type: 'client' | 'user', missing: PermissionsString[]]; + slashStarted: [message: SlashMessage, command: BushCommand, args: any]; } export class BushCommandHandler extends CommandHandler { diff --git a/src/lib/extensions/discord-akairo/BushCommandUtil.ts b/src/lib/extensions/discord-akairo/BushCommandUtil.ts deleted file mode 100644 index 7a06b35..0000000 --- a/src/lib/extensions/discord-akairo/BushCommandUtil.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { type BushCommand, type BushCommandHandler, type BushMessage, type BushSlashMessage } from '#lib'; -import { CommandUtil, type ParsedComponentData } from 'discord-akairo'; -import { type Collection, type Snowflake } from 'discord.js'; - -export interface BushParsedComponentData extends ParsedComponentData { - command?: BushCommand; -} - -export class BushCommandUtil extends CommandUtil { - public declare parsed: BushParsedComponentData | null; - public declare handler: BushCommandHandler; - public declare message: BushMessageType; - public declare messages: Collection | null; - - public constructor(handler: BushCommandHandler, message: BushMessageType) { - super(handler, message); - } -} - -export interface BushCommandUtil extends CommandUtil { - isSlashMessage(message: BushMessage | BushSlashMessage): message is BushSlashMessage; -} diff --git a/src/lib/extensions/discord-akairo/BushInhibitor.ts b/src/lib/extensions/discord-akairo/BushInhibitor.ts index 7f13594..12b2baf 100644 --- a/src/lib/extensions/discord-akairo/BushInhibitor.ts +++ b/src/lib/extensions/discord-akairo/BushInhibitor.ts @@ -1,4 +1,4 @@ -import { type BushClient, type BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { type BushClient, type BushCommand, type CommandMessage, type SlashMessage } from '#lib'; import { Inhibitor } from 'discord-akairo'; export class BushInhibitor extends Inhibitor { @@ -10,9 +10,12 @@ export interface BushInhibitor { * Checks if message should be blocked. * A return value of true will block the message. * If returning a Promise, a resolved value of true will block the message. + * + * **Note:** `all` type inhibitors do not have `message.util` defined. + * * @param message - Message being handled. * @param command - Command to check. */ - exec(message: BushMessage, command: BushCommand): any; - exec(message: BushMessage | BushSlashMessage, command: BushCommand): any; + exec(message: CommandMessage, command: BushCommand): any; + exec(message: CommandMessage | SlashMessage, command: BushCommand): any; } diff --git a/src/lib/extensions/discord-akairo/BushInhibitorHandler.ts b/src/lib/extensions/discord-akairo/BushInhibitorHandler.ts index a607bf7..5e4fb6c 100644 --- a/src/lib/extensions/discord-akairo/BushInhibitorHandler.ts +++ b/src/lib/extensions/discord-akairo/BushInhibitorHandler.ts @@ -1,6 +1,3 @@ -import { type BushClient } from '#lib'; import { InhibitorHandler } from 'discord-akairo'; -export class BushInhibitorHandler extends InhibitorHandler { - public declare client: BushClient; -} +export class BushInhibitorHandler extends InhibitorHandler {} diff --git a/src/lib/extensions/discord-akairo/BushListener.ts b/src/lib/extensions/discord-akairo/BushListener.ts index f6247ec..3efe527 100644 --- a/src/lib/extensions/discord-akairo/BushListener.ts +++ b/src/lib/extensions/discord-akairo/BushListener.ts @@ -1,10 +1,7 @@ -import { type BushClient } from '#lib'; import { Listener } from 'discord-akairo'; import type EventEmitter from 'events'; export class BushListener extends Listener { - public declare client: BushClient; - public constructor( id: string, options: { diff --git a/src/lib/extensions/discord-akairo/BushListenerHandler.ts b/src/lib/extensions/discord-akairo/BushListenerHandler.ts index 517fb55..9c3e4af 100644 --- a/src/lib/extensions/discord-akairo/BushListenerHandler.ts +++ b/src/lib/extensions/discord-akairo/BushListenerHandler.ts @@ -1,6 +1,3 @@ -import { type BushClient } from '#lib'; import { ListenerHandler } from 'discord-akairo'; -export class BushListenerHandler extends ListenerHandler { - public declare client: BushClient; -} +export class BushListenerHandler extends ListenerHandler {} diff --git a/src/lib/extensions/discord-akairo/BushSlashMessage.ts b/src/lib/extensions/discord-akairo/BushSlashMessage.ts deleted file mode 100644 index 0860964..0000000 --- a/src/lib/extensions/discord-akairo/BushSlashMessage.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { - BushCommandHandler, - BushGuildTextBasedChannel, - type BushClient, - type BushCommandUtil, - type BushGuild, - type BushGuildMember, - type BushTextBasedChannel, - type BushUser -} from '#lib'; -import { AkairoMessage } from 'discord-akairo'; -import { type ChatInputCommandInteraction } from 'discord.js'; - -export class BushSlashMessage extends AkairoMessage { - public declare client: BushClient; - public declare util: BushCommandUtil & { handler: BushCommandHandler }; - public declare author: BushUser; - public declare member: BushGuildMember | null; - public declare interaction: ChatInputCommandInteraction; - public constructor(client: BushClient, interaction: ChatInputCommandInteraction) { - super(client, interaction); - } -} - -export interface BushSlashMessage extends AkairoMessage { - get channel(): BushTextBasedChannel | null; - get guild(): BushGuild | null; - inGuild(): this is BushSlashMessageInGuild & this; -} - -interface BushSlashMessageInGuild { - guild: BushGuild; - channel: BushGuildTextBasedChannel; -} diff --git a/src/lib/extensions/discord-akairo/BushTask.ts b/src/lib/extensions/discord-akairo/BushTask.ts index b4359ce..9f5c0cd 100644 --- a/src/lib/extensions/discord-akairo/BushTask.ts +++ b/src/lib/extensions/discord-akairo/BushTask.ts @@ -1,10 +1,3 @@ -import { type BushClient } from '#lib'; -import { Task, type TaskOptions } from 'discord-akairo'; +import { Task } from 'discord-akairo'; -export class BushTask extends Task { - public declare client: BushClient; - - public constructor(id: string, options: TaskOptions) { - super(id, options); - } -} +export class BushTask extends Task {} diff --git a/src/lib/extensions/discord-akairo/BushTaskHandler.ts b/src/lib/extensions/discord-akairo/BushTaskHandler.ts index ed6b91d..f667ead 100644 --- a/src/lib/extensions/discord-akairo/BushTaskHandler.ts +++ b/src/lib/extensions/discord-akairo/BushTaskHandler.ts @@ -1,12 +1,5 @@ -import { type BushClient } from '#lib'; import { TaskHandler, type AkairoHandlerOptions } from 'discord-akairo'; export type BushTaskHandlerOptions = AkairoHandlerOptions; -export class BushTaskHandler extends TaskHandler { - public declare client: BushClient; - - public constructor(client: BushClient, options: BushTaskHandlerOptions) { - super(client, options); - } -} +export class BushTaskHandler extends TaskHandler {} diff --git a/src/lib/extensions/discord-akairo/SlashMessage.ts b/src/lib/extensions/discord-akairo/SlashMessage.ts new file mode 100644 index 0000000..0a6669b --- /dev/null +++ b/src/lib/extensions/discord-akairo/SlashMessage.ts @@ -0,0 +1,3 @@ +import { AkairoMessage } from 'discord-akairo'; + +export class SlashMessage extends AkairoMessage {} 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 extends ApplicationCommand { - 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 - implements StripPrivate> -{ - public constructor(client: BushClient, iterable?: Iterable); - - /** - * 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; - - /** - * 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; - - /** - * 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; - public edit( - command: BushApplicationCommandResolvable, - data: ApplicationCommandData, - guildId: Snowflake - ): Promise; - - /** - * 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; - public fetch(options: FetchApplicationCommandOptions): Promise>; - public fetch(id: Snowflake, options?: FetchApplicationCommandOptions): Promise; - public fetch(id?: Snowflake, options?: FetchApplicationCommandOptions): Promise>; - - /** - * 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>; - public set(commands: ApplicationCommandData[], guildId: Snowflake): Promise>; - - /** - * 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; -} 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; - - /** - * 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; - - /** - * 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; - public fetch(options: BaseOptions): Promise>; - - /** - * 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; - - /** - * 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; - public set( - options: FullPermissionsOptions & { - fullPermissions: GuildApplicationCommandPermissionData[]; - } - ): Promise>; - - /** - * 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 & { 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 - implements BaseGuildEmojiManager -{ - public constructor(client: BushClient, iterable?: Iterable); - - /** - * 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; - 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; - 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; - 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 extends ButtonInteraction { - public declare member: CacheTypeReducer; - public declare user: BushUser; - - public constructor(client: BushClient, data: RawMessageButtonInteractionData) { - super(client, data); - } -} - -export interface BushButtonInteraction extends ButtonInteraction { - get channel(): CacheTypeReducer< - Cached, - BushGuildTextBasedChannel | null, - BushGuildTextBasedChannel | null, - BushGuildTextBasedChannel | null, - BushTextBasedChannel | null - >; - get guild(): CacheTypeReducer; - 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 Bu