diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-03-08 19:37:57 -0500 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-03-08 19:37:57 -0500 |
commit | b86a05f4b21c62e18bf669e00646b715a409bdb0 (patch) | |
tree | 6d3623c45fd321ade5f8bbf6de37385f43123759 | |
parent | 57e47b8b84dee001c65c1ab43833c09fef056a4b (diff) | |
download | tanzanite-b86a05f4b21c62e18bf669e00646b715a409bdb0.tar.gz tanzanite-b86a05f4b21c62e18bf669e00646b715a409bdb0.tar.bz2 tanzanite-b86a05f4b21c62e18bf669e00646b715a409bdb0.zip |
feat: misc changes for extentions
22 files changed, 163 insertions, 39 deletions
diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts index 1a748ed..5a911f7 100644 --- a/src/lib/extensions/discord-akairo/BushClient.ts +++ b/src/lib/extensions/discord-akairo/BushClient.ts @@ -73,6 +73,7 @@ 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'; @@ -330,6 +331,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re Structures.extend('ChatInputCommandInteraction', () => BushChatInputCommandInteraction); Structures.extend('ButtonInteraction', () => BushButtonInteraction); Structures.extend('SelectMenuInteraction', () => BushSelectMenuInteraction); + Structures.extend('ModalSubmitInteraction', () => BushModalSubmitInteraction); } /** @@ -349,7 +351,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re this.commandHandler.useContextMenuCommandHandler(this.contextMenuCommandHandler); this.commandHandler.ignorePermissions = this.config.owners; this.commandHandler.ignoreCooldown = [...new Set([...this.config.owners, ...this.cache.shared.superUsers])]; - this.listenerHandler.setEmitters({ + const emitters: Emitters = { client: this, commandHandler: this.commandHandler, inhibitorHandler: this.inhibitorHandler, @@ -361,7 +363,8 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re gateway: this.ws, rest: this.rest, ws: this.ws - }); + }; + this.listenerHandler.setEmitters(emitters); this.commandHandler.resolver.addTypes({ duration, contentWithDuration, @@ -495,7 +498,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re } } -export interface BushClient extends EventEmitter, PatchedElements { +export interface BushClient<Ready extends boolean = boolean> extends EventEmitter, PatchedElements, AkairoClient<Ready> { get emojis(): BushBaseGuildEmojiManager; on<K extends keyof BushClientEvents>(event: K, listener: (...args: BushClientEvents[K]) => Awaitable<void>): this; @@ -525,3 +528,17 @@ export interface BushStats { */ commandsUsed: bigint; } + +export interface Emitters { + client: BushClient; + commandHandler: BushClient['commandHandler']; + inhibitorHandler: BushClient['inhibitorHandler']; + listenerHandler: BushClient['listenerHandler']; + taskHandler: BushClient['taskHandler']; + contextMenuCommandHandler: BushClient['contextMenuCommandHandler']; + process: NodeJS.Process; + stdin: readline.Interface; + gateway: BushClient['ws']; + rest: BushClient['rest']; + ws: BushClient['ws']; +} diff --git a/src/lib/extensions/discord.js/BushBaseGuildTextChannel.ts b/src/lib/extensions/discord.js/BushBaseGuildTextChannel.ts index 5444a7f..5cc74c4 100644 --- a/src/lib/extensions/discord.js/BushBaseGuildTextChannel.ts +++ b/src/lib/extensions/discord.js/BushBaseGuildTextChannel.ts @@ -22,7 +22,7 @@ export class BushBaseGuildTextChannel extends BaseGuildTextChannel { } } -export interface BushBaseGuildTextChannel { +export interface BushBaseGuildTextChannel extends BaseGuildTextChannel { get members(): Collection<Snowflake, BushGuildMember>; get parent(): BushCategoryChannel | null; } diff --git a/src/lib/extensions/discord.js/BushButtonInteraction.ts b/src/lib/extensions/discord.js/BushButtonInteraction.ts index e72e277..89cfabd 100644 --- a/src/lib/extensions/discord.js/BushButtonInteraction.ts +++ b/src/lib/extensions/discord.js/BushButtonInteraction.ts @@ -15,7 +15,7 @@ export class BushButtonInteraction<Cached extends CacheType = CacheType> extends } } -export interface BushButtonInteraction<Cached extends CacheType = CacheType> { +export interface BushButtonInteraction<Cached extends CacheType = CacheType> extends ButtonInteraction<Cached> { get channel(): CacheTypeReducer< Cached, BushGuildTextBasedChannel | null, @@ -24,4 +24,7 @@ export interface BushButtonInteraction<Cached extends CacheType = CacheType> { 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/BushClientEvents.ts b/src/lib/extensions/discord.js/BushClientEvents.ts index 7437f7f..4a10ce5 100644 --- a/src/lib/extensions/discord.js/BushClientEvents.ts +++ b/src/lib/extensions/discord.js/BushClientEvents.ts @@ -1,6 +1,7 @@ import type { BanResponse, BushApplicationCommand, + BushButtonInteraction, BushClient, BushDMChannel, BushGuild, @@ -10,10 +11,12 @@ import type { BushGuildTextBasedChannel, BushMessage, BushMessageReaction, + BushModalSubmitInteraction, BushNewsChannel, BushNonThreadGuildBasedChannel, BushPresence, BushRole, + BushSelectMenuInteraction, BushStageInstance, BushTextBasedChannel, BushTextChannel, @@ -319,6 +322,10 @@ export interface BushClientEvents extends AkairoClientEvents { reason: string | undefined, results: Collection<Snowflake, BanResponse> ]; + /* components */ + button: [button: BushButtonInteraction]; + selectMenu: [selectMenu: BushSelectMenuInteraction]; + modal: [modal: BushModalSubmitInteraction]; } type Setting = diff --git a/src/lib/extensions/discord.js/BushGuild.ts b/src/lib/extensions/discord.js/BushGuild.ts index a131242..7fadd96 100644 --- a/src/lib/extensions/discord.js/BushGuild.ts +++ b/src/lib/extensions/discord.js/BushGuild.ts @@ -451,7 +451,7 @@ export class BushGuild extends Guild { } } -export interface BushGuild { +export interface BushGuild extends Guild { get me(): BushGuildMember | null; } diff --git a/src/lib/extensions/discord.js/BushGuildEmoji.ts b/src/lib/extensions/discord.js/BushGuildEmoji.ts index 29e0c4a..9b931bb 100644 --- a/src/lib/extensions/discord.js/BushGuildEmoji.ts +++ b/src/lib/extensions/discord.js/BushGuildEmoji.ts @@ -15,6 +15,6 @@ export class BushGuildEmoji extends GuildEmoji { } } -export interface BushGuildEmoji { +export interface BushGuildEmoji extends GuildEmoji { get roles(): BushGuildEmojiRoleManager; } diff --git a/src/lib/extensions/discord.js/BushMessageReaction.ts b/src/lib/extensions/discord.js/BushMessageReaction.ts index aed76df..7fe110d 100644 --- a/src/lib/extensions/discord.js/BushMessageReaction.ts +++ b/src/lib/extensions/discord.js/BushMessageReaction.ts @@ -15,6 +15,6 @@ export class BushMessageReaction extends MessageReaction { } } -export interface BushMessageReaction { +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 new file mode 100644 index 0000000..b05c0d7 --- /dev/null +++ b/src/lib/extensions/discord.js/BushModalSubmitInteraction.ts @@ -0,0 +1,95 @@ +import type { + BushClient, + BushGuild, + BushGuildCacheMessage, + BushGuildMember, + BushGuildTextBasedChannel, + BushTextBasedChannel, + BushUser +} from '#lib'; +import type { APIInteractionGuildMember, APIModalSubmitInteraction } from 'discord-api-types/v9'; +import { + InteractionDeferUpdateOptions, + 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> | null; + + /** + * 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<void>; + + /** + * 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<void>; + + /** + * 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 index fcb15d5..e262188 100644 --- a/src/lib/extensions/discord.js/BushNewsChannel.ts +++ b/src/lib/extensions/discord.js/BushNewsChannel.ts @@ -10,6 +10,6 @@ export class BushNewsChannel extends NewsChannel { public declare messages: BushMessageManager; } -export interface BushNewsChannel { +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 index f40570d..40873ac 100644 --- a/src/lib/extensions/discord.js/BushPresence.ts +++ b/src/lib/extensions/discord.js/BushPresence.ts @@ -13,7 +13,7 @@ export class BushPresence extends Presence { } } -export interface BushPresence { +export interface BushPresence extends Presence { get member(): BushGuildMember | null; get user(): BushUser | null; } diff --git a/src/lib/extensions/discord.js/BushRole.ts b/src/lib/extensions/discord.js/BushRole.ts index c0b9ae5..a9575bd 100644 --- a/src/lib/extensions/discord.js/BushRole.ts +++ b/src/lib/extensions/discord.js/BushRole.ts @@ -13,6 +13,6 @@ export class BushRole extends Role { } } -export interface BushRole { +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 index e5f84b4..35e6301 100644 --- a/src/lib/extensions/discord.js/BushSelectMenuInteraction.ts +++ b/src/lib/extensions/discord.js/BushSelectMenuInteraction.ts @@ -15,7 +15,7 @@ export class BushSelectMenuInteraction<Cached extends CacheType = CacheType> ext } } -export interface BushSelectMenuInteraction<Cached extends CacheType = CacheType> { +export interface BushSelectMenuInteraction<Cached extends CacheType = CacheType> extends SelectMenuInteraction<Cached> { get channel(): CacheTypeReducer< Cached, BushGuildTextBasedChannel | null, @@ -24,4 +24,7 @@ export interface BushSelectMenuInteraction<Cached extends CacheType = CacheType> 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 index 253b417..983bd56 100644 --- a/src/lib/extensions/discord.js/BushStageChannel.ts +++ b/src/lib/extensions/discord.js/BushStageChannel.ts @@ -13,7 +13,7 @@ export class BushStageChannel extends StageChannel { } } -export interface BushStageChannel { +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 index 0242314..96453a7 100644 --- a/src/lib/extensions/discord.js/BushStageInstance.ts +++ b/src/lib/extensions/discord.js/BushStageInstance.ts @@ -11,7 +11,7 @@ export class BushStageInstance extends StageInstance { } } -export interface BushStageInstance { +export interface BushStageInstance extends StageInstance { get channel(): BushStageChannel | null; get guild(): BushGuild | null; } diff --git a/src/lib/extensions/discord.js/BushThreadMember.ts b/src/lib/extensions/discord.js/BushThreadMember.ts index b3d8b50..90c9c9b 100644 --- a/src/lib/extensions/discord.js/BushThreadMember.ts +++ b/src/lib/extensions/discord.js/BushThreadMember.ts @@ -13,7 +13,7 @@ export class BushThreadMember extends ThreadMember { } } -export interface BushThreadMember { +export interface BushThreadMember extends ThreadMember { get guildMember(): BushGuildMember | null; get user(): BushUser | null; } diff --git a/src/lib/extensions/discord.js/BushUser.ts b/src/lib/extensions/discord.js/BushUser.ts index 10e2e4a..27ef2b2 100644 --- a/src/lib/extensions/discord.js/BushUser.ts +++ b/src/lib/extensions/discord.js/BushUser.ts @@ -29,6 +29,6 @@ export class BushUser extends User { } } -export interface BushUser { +export interface BushUser extends User { get dmChannel(): BushDMChannel | null; } diff --git a/src/lib/extensions/discord.js/BushVoiceState.ts b/src/lib/extensions/discord.js/BushVoiceState.ts index f5c6301..bbcdfa8 100644 --- a/src/lib/extensions/discord.js/BushVoiceState.ts +++ b/src/lib/extensions/discord.js/BushVoiceState.ts @@ -14,7 +14,7 @@ export class BushVoiceState extends VoiceState { } } -export interface BushVoiceState { +export interface BushVoiceState extends VoiceState { get channel(): BushVoiceBasedChannel | null; get getmember(): BushGuildMember | null; } diff --git a/src/lib/extensions/discord.js/other.ts b/src/lib/extensions/discord.js/other.ts index e4bc10b..7705c18 100644 --- a/src/lib/extensions/discord.js/other.ts +++ b/src/lib/extensions/discord.js/other.ts @@ -19,7 +19,8 @@ import type { BushVoiceChannel, PartialBushDMChannel } from '#lib'; -import type { ChannelType, Collection, Message, Snowflake } from 'discord.js'; +import { APIMessage } from 'discord-api-types/v9'; +import type { CacheType, CacheTypeReducer, ChannelType, Collection, Message, Snowflake } from 'discord.js'; /** * Data that resolves to give a ThreadMember object. @@ -150,16 +151,12 @@ export interface BushFetchedThreads { hasMore?: boolean; } -// for reverse key mapping - -/** - * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-type - */ -export enum BushInteractionType { - Ping = 1, - ApplicationCommand = 2, - MessageComponent = 3, - ApplicationCommandAutocomplete = 4 -} - export type BushNonCategoryGuildBasedChannel = Exclude<BushGuildBasedChannel, BushCategoryChannel>; + +export type BushGuildCacheMessage<Cached extends CacheType> = CacheTypeReducer< + Cached, + BushMessage<true>, + APIMessage, + BushMessage | APIMessage, + BushMessage | APIMessage +>; diff --git a/src/lib/index.ts b/src/lib/index.ts index 45d76b7..eb7cf76 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -49,6 +49,7 @@ export type { BushGuildMemberManager } from './extensions/discord.js/BushGuildMe export * from './extensions/discord.js/BushMessage.js'; export type { BushMessageManager } from './extensions/discord.js/BushMessageManager.js'; export * from './extensions/discord.js/BushMessageReaction.js'; +export * from './extensions/discord.js/BushModalSubmitInteraction.js'; export * from './extensions/discord.js/BushNewsChannel.js'; export * from './extensions/discord.js/BushPresence.js'; export * from './extensions/discord.js/BushReactionEmoji.js'; diff --git a/src/listeners/interaction/button.ts b/src/listeners/interaction/button.ts new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/listeners/interaction/button.ts diff --git a/src/listeners/client/interactionCreate.ts b/src/listeners/interaction/interactionCreate.ts index d123e09..6916134 100644 --- a/src/listeners/client/interactionCreate.ts +++ b/src/listeners/interaction/interactionCreate.ts @@ -1,11 +1,12 @@ -import { AutoMod, BushInteractionType, BushListener, type BushButtonInteraction, type BushClientEvents } from '#lib'; +import { AutoMod, BushListener, type BushButtonInteraction, type BushClientEvents } from '#lib'; +import { InteractionType } from 'discord-api-types/v9'; export default class InteractionCreateListener extends BushListener { public constructor() { super('interactionCreate', { emitter: 'client', event: 'interactionCreate', - category: 'client' + category: 'interaction' }); } @@ -14,7 +15,7 @@ export default class InteractionCreateListener extends BushListener { if ('customId' in interaction && (interaction as any)['customId'].startsWith('test')) return; void client.console.verbose( 'interactionVerbose', - `An interaction of type <<${BushInteractionType[interaction.type]}>> was received from <<${interaction.user.tag}>>.` + `An interaction of type <<${InteractionType[interaction.type]}>> was received from <<${interaction.user.tag}>>.` ); if (interaction.isCommand()) { return; @@ -1342,8 +1342,8 @@ __metadata: linkType: hard "discord.js@npm:@notenoughupdates/discord.js@dev": - version: 14.0.0-dev.1646510541.0275c3e - resolution: "@notenoughupdates/discord.js@npm:14.0.0-dev.1646510541.0275c3e" + version: 14.0.0-dev.1646516972.f238a8e + resolution: "@notenoughupdates/discord.js@npm:14.0.0-dev.1646516972.f238a8e" dependencies: "@discordjs/builders": ^0.13.0-dev "@discordjs/collection": ^0.6.0-dev @@ -1354,7 +1354,7 @@ __metadata: lodash.snakecase: ^4.1.1 undici: ^4.14.1 ws: ^8.5.0 - checksum: ef4092d2f0760d6ed282c9b621ae30d34831241c9ead2cc2bbadd7a6f5988bc6a680fbf18f35917810586aff6ae992f5f50b8f71a162c1ac9294f113cb765caa + checksum: 5894516eb8f8725ebdff86af6b545b7cd0a9bf3eceae121de33b27f83ddbfa5912e878dd2218caab99248a857c2f22a3159654fabea9f1db5b6f6e26b71a4d5d languageName: node linkType: hard @@ -1849,9 +1849,9 @@ __metadata: linkType: hard "fraction.js@npm:^4.1.3": - version: 4.1.3 - resolution: "fraction.js@npm:4.1.3" - checksum: d00065afce4814998b6e42fd439bbed17edbd9616b134927dbd75ebe1b94d6eb0820c0ce0e2cf8f26100e552cb72aff83f4816ef90cb1b329b6d12a531a26aaa + version: 4.2.0 + resolution: "fraction.js@npm:4.2.0" + checksum: 8c76a6e21dedea87109d6171a0ac77afa14205794a565d71cb10d2925f629a3922da61bf45ea52dbc30bce4d8636dc0a27213a88cbd600eab047d82f9a3a94c5 languageName: node linkType: hard |