honocord 2.1.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["key","Collection","ApplicationCommandOptionType","key","key","InteractionType","ApplicationCommandType","ComponentType","ModalBuilder","API","REST","key","Collection","ComponentType","SlashCommandBuilder","ContextMenuCommandBuilder","Hono","ApplicationWebhookType","Collection","Collection","Collection","Collection","InteractionType","ApplicationCommandType","ComponentType","NullCacheAdapter","key","ApplicationCommandType","ComponentType","REST","API","InteractionType","InteractionResponseType","Hono","ApplicationWebhookType","ApplicationCommandType"],"sources":["../src/resolvers/CommandOptionResolver.ts","../src/structures/utils.ts","../src/structures/AttachmentBuilder.ts","../src/utils/Fetcher.ts","../src/interactions/BaseInteraction.ts","../src/interactions/ModalCapableInteraction.ts","../src/interactions/CommandInteraction.ts","../src/interactions/ChatInputInteraction.ts","../src/utils/discordVerify.ts","../src/utils/Colors.ts","../src/utils/registerCommands.ts","../src/utils/index.ts","../src/interactions/UserContextCommandInteraction.ts","../src/interactions/MessageContextCommandInteraction.ts","../src/resolvers/ModalComponentResolver.ts","../src/interactions/ModalInteraction.ts","../src/interactions/AutocompleteInteraction.ts","../src/handlers/SlashCommandHandler.ts","../src/handlers/ContextCommandHandler.ts","../src/handlers/ComponentHandler.ts","../src/handlers/ModalHandler.ts","../src/handlers/WebhookEventHandler.ts","../src/interactions/MessageComponentInteraction.ts","../src/interactions/ButtonInteraction.ts","../src/interactions/StringSelectInteraction.ts","../src/interactions/UserSelectInteraction.ts","../src/interactions/RoleSelectInteraction.ts","../src/interactions/MentionableSelectInteraction.ts","../src/interactions/ChannelSelectInteraction.ts","../src/utils/CacheManager.ts","../src/Honocord.ts","../src/types/commands.ts"],"sourcesContent":["import { Collection } from \"@discordjs/collection\";\nimport {\n APIApplicationCommandInteractionDataOption,\n APIAttachment,\n APIInteractionDataResolved,\n APIInteractionDataResolvedChannel,\n APIRole,\n APIUser,\n ApplicationCommandOptionType,\n ChannelType,\n InteractionType,\n} from \"discord-api-types/v10\";\nimport { APIInteractionDataResolvedCollections, ResolvedSelectedGuildMember } from \"../types\";\n\ntype AutocompleteFocusedOption = {\n /**\n * The name of the option.\n */\n name: string;\n /**\n * The type of the application command option.\n */\n type: ApplicationCommandOptionType;\n /**\n * The value of the option.\n */\n value: string;\n /**\n * Whether the option is focused.\n */\n focused: boolean;\n};\n\n/**\n * A resolver for command interaction options.\n */\nclass CommandInteractionOptionResolver {\n /**\n * The name of the subcommand group.\n */\n private _group: string | null = null;\n /**\n * The name of the subcommand.\n */\n private _subcommand: string | null = null;\n /**\n * The bottom-level options for the interaction.\n * If there is a subcommand (or subcommand and group), this is the options for the subcommand.\n */\n private _hoistedOptions: APIApplicationCommandInteractionDataOption<\n InteractionType.ApplicationCommand | InteractionType.ApplicationCommandAutocomplete\n >[];\n\n private _resolved: APIInteractionDataResolvedCollections;\n\n constructor(\n options:\n | APIApplicationCommandInteractionDataOption<\n InteractionType.ApplicationCommand | InteractionType.ApplicationCommandAutocomplete\n >[]\n | undefined,\n resolved: APIInteractionDataResolved | undefined\n ) {\n this._hoistedOptions = options ?? [];\n this._resolved = Object.keys(resolved ?? {}).reduce((acc, key) => {\n const resolvedData = resolved?.[key as keyof APIInteractionDataResolved];\n if (key === \"members\") {\n // get users and combine them with members for easy access; a user is expected to ALWAYS be present if a member is\n const users = resolved?.users ? new Collection(Object.entries(resolved.users)) : new Collection();\n const members = resolvedData ? new Collection(Object.entries(resolvedData)) : new Collection();\n const combined = new Collection([...members.entries()].map(([id, member]) => [id, { ...member, user: users.get(id)! }]));\n acc[key] = combined;\n return acc;\n }\n const collection = new Collection(resolvedData ? Object.entries(resolvedData) : []);\n acc[key as keyof APIInteractionDataResolvedCollections] = collection;\n return acc;\n }, {} as any);\n\n // Hoist subcommand group if present\n if (this._hoistedOptions[0]?.type === ApplicationCommandOptionType.SubcommandGroup) {\n this._group = this._hoistedOptions[0].name;\n this._hoistedOptions = this._hoistedOptions[0].options ?? [];\n }\n\n // Hoist subcommand if present\n if (this._hoistedOptions[0]?.type === ApplicationCommandOptionType.Subcommand) {\n this._subcommand = this._hoistedOptions[0].name;\n this._hoistedOptions = this._hoistedOptions[0].options ?? [];\n }\n }\n\n public get data() {\n return this._hoistedOptions;\n }\n\n /**\n * Gets an option by its name.\n *\n * @param name The name of the option.\n * @param type The expected type of the option.\n * @param required Whether to throw an error if the option is not found.\n * @returns The option, if found.\n */\n get<T extends ApplicationCommandOptionType>(name: string, type: T, required = false) {\n const option = this._hoistedOptions.find((opt) => opt.name === name);\n if (!option) {\n if (required) {\n throw new TypeError(\"Option not found\", { cause: { name } });\n }\n\n return null;\n }\n\n if (option.type !== type) {\n throw new TypeError(\"Option type mismatch\", { cause: { name, type: option.type, expected: type } });\n }\n\n return option as Extract<APIApplicationCommandInteractionDataOption<InteractionType.ApplicationCommand>, { type: T }>;\n }\n\n /**\n * Gets the selected subcommand.\n *\n * @param {boolean} [required=true] Whether to throw an error if there is no subcommand.\n * @returns {?string} The name of the selected subcommand, or null if not set and not required.\n */\n getSubcommand(): string | null;\n getSubcommand(required: true): string;\n getSubcommand(required: boolean = true): string | null {\n if (required && !this._subcommand) {\n throw new TypeError(\"No subcommand selected\");\n }\n\n return this._subcommand;\n }\n\n /**\n * Gets the selected subcommand group.\n *\n * @param required Whether to throw an error if there is no subcommand group.\n * @returns The name of the selected subcommand group, or null if not set and not required.\n */\n getSubcommandGroup(required?: boolean): string | null;\n getSubcommandGroup(required: true): string;\n getSubcommandGroup(required: boolean = false): string | null {\n if (required && !this._group) {\n throw new TypeError(\"No subcommand group selected\");\n }\n\n return this._group;\n }\n\n getFocused(): AutocompleteFocusedOption | null {\n return (this._hoistedOptions as AutocompleteFocusedOption[]).find((option) => option.focused) || null;\n }\n\n /**\n * Gets a boolean option.\n *\n * @param name The name of the option.\n * @param required Whether to throw an error if the option is not found.\n * @returns The value of the option, or null if not set and not required.\n */\n getBoolean(name: string, required?: boolean): boolean | null;\n getBoolean(name: string, required: true): boolean;\n getBoolean(name: string, required: boolean = false): boolean | null {\n const option = this.get(name, ApplicationCommandOptionType.Boolean, required);\n return option ? option.value : null;\n }\n\n /**\n * Gets a channel option.\n *\n * @param name The name of the option.\n * @param required Whether to throw an error if the option is not found.\n * @param channelTypes The allowed types of channels. If empty, all channel types are allowed.\n * @returns The value of the option, or null if not set and not required.\n */\n getChannel(name: string, required: false, channelTypes: ChannelType[]): APIInteractionDataResolvedChannel | null;\n getChannel(name: string, required: true, channelTypes: ChannelType[]): APIInteractionDataResolvedChannel;\n getChannel(\n name: string,\n required: boolean = false,\n channelTypes: ChannelType[] = []\n ): APIInteractionDataResolvedChannel | null {\n const option = this.get(name, ApplicationCommandOptionType.Channel, required);\n const channel = option ? this._resolved.channels?.get(option.value) || null : null;\n\n if (channel && channelTypes.length > 0 && !channelTypes.includes(channel.type)) {\n throw new TypeError(\"Invalid channel type\", { cause: { name, type: channel.type, expected: channelTypes.join(\", \") } });\n }\n\n return channel;\n }\n\n /**\n * Gets a string option.\n *\n * @param name The name of the option.\n * @param required Whether to throw an error if the option is not found.\n * @returns The value of the option, or null if not set and not required.\n */\n getString<T extends string = string>(name: string, required?: boolean): T | null;\n getString<T extends string = string>(name: string, required: true): T;\n getString<T extends string = string>(name: string, required: boolean = false): T | null {\n const option = this.get(name, ApplicationCommandOptionType.String, required);\n return (option?.value as T) ?? null;\n }\n\n /**\n * Gets an integer option.\n *\n * @param name The name of the option.\n * @param required Whether to throw an error if the option is not found.\n * @returns The value of the option, or null if not set and not required.\n */\n getInteger(name: string, required?: boolean): number | null;\n getInteger(name: string, required: true): number;\n getInteger(name: string, required: boolean = false): number | null {\n const option = this.get(name, ApplicationCommandOptionType.Integer, required);\n return option?.value ?? null;\n }\n\n /**\n * Gets a number option.\n *\n * @param name The name of the option.\n * @param required Whether to throw an error if the option is not found.\n * @returns The value of the option, or null if not set and not required.\n */\n getNumber(name: string, required?: boolean): number | null;\n getNumber(name: string, required: true): number;\n getNumber(name: string, required: boolean = false): number | null {\n const option = this.get(name, ApplicationCommandOptionType.Number, required);\n return option?.value ?? null;\n }\n\n /**\n * Gets a user option.\n *\n * @param name The name of the option.\n * @param required Whether to throw an error if the option is not found.\n * @returns The value of the option, or null if not set and not required.\n */\n getUser(name: string, required?: boolean): APIUser | null;\n getUser(name: string, required: true): APIUser;\n getUser(name: string, required: boolean = false): APIUser | null {\n const option = this.get(name, ApplicationCommandOptionType.User, required);\n const user = option ? this._resolved.users?.get(option.value) || null : null;\n return user;\n }\n\n /**\n * Gets a member option.\n *\n * @param name The name of the option.\n * @returns The value of the option, or null if the user is not present in the guild or the option is not set.\n */\n getMember(name: string, required?: boolean): ResolvedSelectedGuildMember | null;\n getMember(name: string, required: true): ResolvedSelectedGuildMember;\n getMember(name: string, required: boolean = false): ResolvedSelectedGuildMember | null {\n const option = this.get(name, ApplicationCommandOptionType.User, required);\n const member = option ? this._resolved.members?.get(option.value) || null : null;\n return member;\n }\n\n /**\n * Gets a role option.\n *\n * @param name The name of the option.\n * @param required Whether to throw an error if the option is not found.\n * @returns The value of the option, or null if not set and not required.\n */\n getRole(name: string, required?: boolean): APIRole | null;\n getRole(name: string, required: true): APIRole;\n getRole(name: string, required: boolean = false): APIRole | null {\n const option = this.get(name, ApplicationCommandOptionType.Role, required);\n const role = option ? this._resolved.roles?.get(option.value) || null : null;\n return role;\n }\n\n /**\n * Gets an attachment option.\n *\n * @param name The name of the option.\n * @param required Whether to throw an error if the option is not found.\n * @returns The value of the option, or null if not set and not required.\n */\n getAttachment(name: string, required?: boolean): APIAttachment | null;\n getAttachment(name: string, required: true): APIAttachment;\n getAttachment(name: string, required: boolean = false): APIAttachment | null {\n const option = this.get(name, ApplicationCommandOptionType.Attachment, required);\n const attachment = option ? this._resolved.attachments?.get(option.value) || null : null;\n return attachment;\n }\n\n /**\n * Gets a mentionable option.\n *\n * @param name The name of the option.\n * @param required Whether to throw an error if the option is not found.\n * @returns The value of the option, or null if not set and not required.\n */\n getMentionable(name: string, required?: boolean): ResolvedSelectedGuildMember | APIUser | APIRole | null;\n getMentionable(name: string, required: true): ResolvedSelectedGuildMember | APIUser | APIRole;\n getMentionable(name: string, required: boolean = false): (ResolvedSelectedGuildMember | APIUser | APIRole) | null {\n const option = this.get(name, ApplicationCommandOptionType.Mentionable, required);\n const user = option ? this._resolved.users?.get(option.value) || null : null;\n const member = option ? this._resolved.members?.get(option.value) || null : null;\n const role = option ? this._resolved.roles?.get(option.value) || null : null;\n return member ?? user ?? role ?? null;\n }\n}\n\nexport { CommandInteractionOptionResolver };\n","import { parse } from \"node:path\";\n\n/**\n * Alternative to Node's `path.basename`, removing query string after the extension if it exists.\n * @param path Path to get the basename of\n * @param ext File extension to remove\n * @returns Basename of the path\n * @private\n */\nexport function basename(path: string, ext?: string): string {\n const res = parse(path);\n return ext && res.ext.startsWith(ext) ? res.name : res.base.split(\"?\")[0];\n}\n","import type { AttachmentPayload, BufferResolvable } from \"$types/utils\";\nimport Stream from \"node:stream\";\nimport { basename } from \"./utils\";\nimport { AttachmentData, RawFile } from \"$types/responses\";\nimport { RESTAPIAttachment } from \"discord-api-types/v10\";\n\n/**\n * Builder for message attachments, which can be used in several response methods across the library.\n */\nexport class AttachmentBuilder {\n private attachment: BufferResolvable | Stream;\n private name?: string;\n private description?: string;\n private contentType?: string;\n private key?: string; // Not really needed but allows users to set a custom key for their own reference if they want\n\n constructor(attachment: BufferResolvable | Stream, data: AttachmentData = {}) {\n this.attachment = attachment;\n this.name = data.name;\n this.description = data.description;\n this.contentType = data.contentType;\n this.key = data.key;\n }\n\n setDescription(description: string): this {\n this.description = description;\n return this;\n }\n setContentType(contentType: string): this {\n this.contentType = contentType;\n return this;\n }\n setKey(key: string): this {\n this.key = key;\n return this;\n }\n setFile(attachment: BufferResolvable | Stream): this {\n this.attachment = attachment;\n return this;\n }\n setName(name: string): this {\n this.name = name;\n return this;\n }\n\n setSpoiler(spoiler = true): this {\n if (!this.name) return this;\n if (spoiler === this.spoiler) return this;\n if (!spoiler) {\n while (this.spoiler) this.name = this.name.slice(\"SPOILER_\".length);\n return this;\n }\n this.name = `SPOILER_${this.name}`;\n return this;\n }\n\n get spoiler() {\n return this.name ? basename(this.name).startsWith(\"SPOILER_\") : false;\n }\n\n /** Produces the multipart file part (files[n]) */\n toRawFile(): RawFile {\n return {\n name: this.name ?? \"file\",\n data: this.attachment as Buffer | Uint8Array | string,\n contentType: this.contentType,\n key: this.key,\n };\n }\n\n /** Produces the attachments[] entry for the JSON payload */\n toRestAttachment(index: number): RESTAPIAttachment {\n return {\n id: index,\n filename: this.name ?? \"file\",\n ...(this.description && { description: this.description }),\n };\n }\n\n /**\n * Resolves this builder into the parallel `files` and `attachments` arrays ready to spread into your API call options.\n *\n * @example\n * const { files, attachments } = builder.resolve();\n * await interaction.reply({ content: \"Here!\", files, attachments });\n * // or even shorter:\n * await interaction.reply({ content: \"Here!\", ...builder.resolve() });\n */\n resolve(): { files: RawFile[]; attachments: RESTAPIAttachment[] } {\n return AttachmentBuilder.resolve(this);\n }\n\n /**\n * Resolves an array of AttachmentBuilders into parallel `files` and\n * `attachments` arrays ready to spread into your API call options.\n *\n * @example\n * const { files, attachments } = AttachmentBuilder.resolve(builder1, builder2);\n * await interaction.reply({ content: \"Here!\", files, attachments });\n */\n static resolve(...builders: AttachmentBuilder[]): {\n files: RawFile[];\n attachments: RESTAPIAttachment[];\n } {\n return {\n files: builders.map((b) => b.toRawFile()),\n attachments: builders.map((b, i) => b.toRestAttachment(i)),\n };\n }\n\n static from(other: AttachmentBuilder | AttachmentPayload): AttachmentBuilder {\n if (other instanceof AttachmentBuilder) {\n return new AttachmentBuilder(other.attachment, {\n name: other.name,\n description: other.description,\n contentType: other.contentType,\n key: other.key,\n });\n }\n return new AttachmentBuilder(other.attachment, {\n name: other.name,\n description: other.description,\n });\n }\n}\n","import { API } from \"@discordjs/core/http-only\";\nimport { CacheManager } from \"./CacheManager\";\nimport type { APIGuild, APIGuildMember, APIRole, APIUser } from \"discord-api-types/v10\";\nimport type { CachedChannel, CachedGuildMember } from \"$types/caching\";\n\nexport class Fetcher {\n constructor(\n public readonly api: API,\n private getCache: () => CacheManager | undefined | null\n ) {}\n\n private get cache() {\n return this.getCache() ?? null;\n }\n\n private async fetchAndCache<T>(\n cacheGetter: () => Promise<T | undefined | null>,\n cacheSetter: (data: T) => Promise<void>,\n fetcher: () => Promise<T>\n ): Promise<T> {\n const cache = this.cache;\n if (cache) {\n const cached = await cacheGetter();\n if (cached) return cached;\n }\n\n const data = await fetcher();\n if (cache) {\n await cacheSetter(data);\n }\n return data;\n }\n\n readonly users = {\n get: (userId: string): Promise<APIUser> =>\n this.fetchAndCache(\n () => this.cache?.users.get(userId) ?? Promise.resolve(null),\n (user) => this.cache!.users.set(user),\n () => this.api.users.get(userId)\n ),\n };\n\n readonly channels = {\n get: (channelId: string): Promise<CachedChannel> =>\n this.fetchAndCache(\n () => this.cache?.channels.get(channelId) ?? Promise.resolve(null),\n (channel) => this.cache!.channels.set(channel),\n () => this.api.channels.get(channelId) as Promise<CachedChannel>\n ),\n };\n\n readonly guilds = {\n get: (guildId: string): Promise<APIGuild> =>\n this.fetchAndCache(\n () => this.cache?.guilds.get(guildId) ?? Promise.resolve(null),\n (guild) => this.cache!.guilds.set(guild),\n () => this.api.guilds.get(guildId)\n ),\n };\n\n readonly roles = {\n get: (guildId: string, roleId: string): Promise<APIRole> =>\n this.fetchAndCache(\n () => this.cache?.roles.get(roleId) ?? Promise.resolve(null),\n (role) => this.cache!.roles.set(role),\n async () => {\n const roles = await this.api.guilds.getRoles(guildId);\n return roles.find((r) => r.id === roleId)!;\n }\n ),\n list: (guildId: string): Promise<APIRole[]> =>\n this.fetchAndCache(\n () => this.cache?.getGuildRoles(guildId) ?? Promise.resolve(null),\n async (roles) => {\n if (!this.cache) return;\n await this.cache.roles.mset(roles.map((r) => ({ value: r })));\n },\n () => this.api.guilds.getRoles(guildId)\n ),\n };\n\n readonly members = {\n get: (guildId: string, userId: string): Promise<APIGuildMember | CachedGuildMember> =>\n this.fetchAndCache(\n () => this.cache?.members.get(guildId, userId) ?? Promise.resolve(null),\n (member) => this.cache!.members.set(guildId, member),\n () => this.api.guilds.getMember(guildId, userId)\n ),\n };\n}\n","import {\n type Snowflake,\n APIInteractionResponseCallbackData,\n APIPartialInteractionGuild,\n APIUser,\n ApplicationCommandType,\n InteractionType,\n Locale,\n APIApplicationCommandInteraction,\n ComponentType,\n APIMessage,\n} from \"discord-api-types/v10\";\nimport { API } from \"@discordjs/core/http-only\";\nimport { REST } from \"@discordjs/rest\";\nimport { ModalInteraction } from \"./ModalInteraction\";\nimport type {\n BaseInteractionContext,\n InteractionResponseCallbackData,\n JSONEncodable,\n MessageComponentType,\n PreparedResponseOptions,\n RawFile,\n ValidInteraction,\n} from \"$types/index\";\nimport { MessageComponentInteraction } from \"./MessageComponentInteraction\";\nimport { AutocompleteInteraction } from \"./AutocompleteInteraction\";\nimport { CommandInteraction } from \"./CommandInteraction\";\nimport { ChatInputCommandInteraction } from \"./ChatInputInteraction\";\nimport { UserContextInteraction } from \"./UserContextCommandInteraction\";\nimport { MessageContextInteraction } from \"./MessageContextCommandInteraction\";\nimport { ButtonInteraction } from \"./ButtonInteraction\";\nimport { StringSelectInteraction } from \"./StringSelectInteraction\";\nimport { UserSelectInteraction } from \"./UserSelectInteraction\";\nimport { RoleSelectInteraction } from \"./RoleSelectInteraction\";\nimport { MentionableSelectInteraction } from \"./MentionableSelectInteraction\";\nimport { ChannelSelectInteraction } from \"./ChannelSelectInteraction\";\nimport { AttachmentBuilder } from \"../structures/AttachmentBuilder\";\nimport { Fetcher } from \"@utils/Fetcher\";\n\nfunction snakeCase(str: string): string {\n return str\n .replace(/([a-z0-9])([A-Z])/g, \"$1_$2\")\n .replace(/([A-Z])([A-Z][a-z])/g, \"$1_$2\")\n .toLowerCase();\n}\n\n/**\n * Transforms camel-cased keys into snake cased keys\n *\n * @param {*} obj The object to transform\n * @returns {*} The transformed object\n */\nfunction toSnakeCase(obj: any): any {\n if (typeof obj !== \"object\" || !obj) return obj;\n if (obj instanceof Date) return obj;\n if (isJSONEncodable(obj)) return toSnakeCase(obj.toJSON());\n if (Array.isArray(obj)) return obj.map(toSnakeCase);\n return Object.fromEntries(Object.entries(obj).map(([key, value]) => [snakeCase(key), toSnakeCase(value)]));\n}\n\n/**\n * Indicates if an object is encodable or not.\n *\n * @param maybeEncodable - The object to check against\n */\nfunction isJSONEncodable(maybeEncodable: unknown): maybeEncodable is JSONEncodable<unknown> {\n return (\n maybeEncodable !== null &&\n typeof maybeEncodable === \"object\" &&\n \"toJSON\" in maybeEncodable &&\n typeof maybeEncodable[\"toJSON\"] === \"function\"\n );\n}\n\nexport abstract class BaseInteraction<\n Type extends InteractionType,\n Context extends BaseInteractionContext = BaseInteractionContext,\n> {\n public readonly type: Type;\n /** The raw interaction data */\n protected readonly raw: Extract<ValidInteraction, { type: Type }>;\n public readonly rest: REST;\n protected _ephemeral: boolean | null = null;\n protected replied: boolean = false;\n protected deferred: boolean = false;\n public readonly context: Context;\n public readonly fetcher: Fetcher;\n\n constructor(\n protected api: API,\n data: Extract<ValidInteraction, { type: Type }>,\n context: Context\n ) {\n this.type = data.type as Type;\n this.raw = { ...data };\n this.rest = api.rest;\n this.context = context;\n this.fetcher = new Fetcher(api, () => this.context.get(\"cache\") as any);\n }\n\n get applicationId() {\n return this.raw.application_id;\n }\n\n get entitlements() {\n return this.raw.entitlements;\n }\n\n get channelId() {\n return this.raw.channel?.id;\n }\n\n get channel() {\n return this.raw.channel;\n }\n\n get guildId() {\n return this.raw.guild_id;\n }\n\n get guild() {\n return this.raw.guild;\n }\n\n get userId() {\n return this.raw.user?.id;\n }\n\n get user() {\n return (this.raw.member?.user || this.raw.user) as APIUser; // One is always given.\n }\n\n get member() {\n return this.raw.member;\n }\n\n get locale() {\n return this.raw.guild_locale;\n }\n\n get guildLocale() {\n return this.raw.guild_locale;\n }\n\n get token() {\n return this.raw.token;\n }\n\n get id() {\n return this.raw.id;\n }\n\n get appPermissions() {\n return this.raw.app_permissions;\n }\n\n get version() {\n return this.raw.version;\n }\n\n protected isJSONEncodable(obj: unknown): obj is JSONEncodable<unknown> {\n return isJSONEncodable(obj);\n }\n\n protected toSnakeCase<T = unknown>(obj: unknown): T {\n return toSnakeCase(obj) as T;\n }\n\n inGuild(): this is BaseInteraction<Type> & { guild_id: Snowflake; guild: APIPartialInteractionGuild; guild_locale: Locale } {\n return Boolean(this.raw.guild_id && this.raw.guild && this.raw.guild_locale);\n }\n\n inDM(): this is BaseInteraction<Type> & { guild_id: undefined; guild: undefined; guild_locale: undefined } {\n return !this.inGuild();\n }\n\n getAppEntitlements() {\n return this.entitlements.filter((entitlement) => entitlement.application_id === this.applicationId);\n }\n\n guildHavePremium(): boolean {\n return (\n this.getAppEntitlements().filter(\n (entitlement) =>\n entitlement.guild_id === this.guildId && (!entitlement.ends_at || new Date(entitlement.ends_at) > new Date())\n ).length > 0\n );\n }\n\n userHavePremium(): boolean {\n return (\n this.getAppEntitlements().filter(\n (entitlement) =>\n entitlement.user_id === this.userId && (!entitlement.ends_at || new Date(entitlement.ends_at) > new Date())\n ).length > 0\n );\n }\n\n protected prepareResponsePayload<T extends PreparedResponseOptions = PreparedResponseOptions>(\n options: InteractionResponseCallbackData\n ): T {\n const builders = (options.files ?? []).filter((f): f is AttachmentBuilder => f instanceof AttachmentBuilder);\n const rawFiles = (options.files ?? []).filter((f): f is RawFile => !(f instanceof AttachmentBuilder));\n\n const { files: resolvedFiles, attachments: resolvedMeta } = AttachmentBuilder.resolve(...builders);\n\n delete options.files;\n\n const components = options.components?.map((c) => (this.isJSONEncodable(c) ? c.toJSON() : c));\n const embeds = options.embeds?.map((e) => (this.isJSONEncodable(e) ? e.toJSON() : e));\n const attachments = [...resolvedMeta, ...(options.attachments ?? [])];\n const finalFiles = [...resolvedFiles, ...rawFiles];\n\n const body: any = {};\n if (options.content) body.content = options.content;\n if (options.tts) body.tts = options.tts;\n if (options.allowed_mentions) body.allowed_mentions = options.allowed_mentions;\n if (options.flags) body.flags = options.flags;\n if (options.applied_tags) body.applied_tags = options.applied_tags;\n if (options.poll) body.poll = options.poll;\n if (options.thread_name) body.thread_name = options.thread_name;\n if (components?.length) body.components = components;\n if (embeds?.length) body.embeds = embeds;\n if (attachments?.length) body.attachments = attachments;\n\n const finalBody = this.toSnakeCase<APIInteractionResponseCallbackData>(body);\n if (finalFiles.length) {\n return { ...finalBody, files: finalFiles } as T;\n }\n return { ...finalBody } as T;\n }\n\n async reply(options: InteractionResponseCallbackData | string, forceEphemeral = true) {\n const replyOptions = typeof options === \"string\" ? { content: options } : options;\n if (forceEphemeral) {\n replyOptions.flags = (replyOptions.flags ?? 0) | 64;\n }\n const response = await this.api.interactions.reply(\n this.id,\n this.token,\n { ...this.prepareResponsePayload(replyOptions), with_response: true },\n {\n signal: AbortSignal.timeout(5000),\n }\n );\n this.replied = true;\n return response;\n }\n\n async deferReply(forceEphemeral = true) {\n const response = await this.api.interactions.defer(this.id, this.token, {\n flags: forceEphemeral ? 64 : undefined,\n with_response: true,\n });\n this.deferred = true;\n return response;\n }\n\n /**\n * Defers the update of a component interaction.\n *\n * @returns A promise that resolves when the update is deferred\n *\n * Responding to a component interaction via the deferUpdate() method acknowledges the interaction and resets the message state.\n * This method can be used to suppress the need for further responses, however it's encouraged to provide meaningful feedback to users via an update() or ephemeral reply() at least.\\\n * Once deferUpdate() has been called, future messages can be sent by calling followUp() or edits can be made by calling editReply() on the component interaction.\n *\n * Example flow:\n * 1. User clicks a button.\n * 2. Bot calls `deferUpdate()` to acknowledge the interaction.\n * 3. Bot performs some processing.\n * 4. Bot calls `editReply()` to update the original message.\n *\n */\n deferUpdate() {\n return this.api.interactions.deferMessageUpdate(this.id, this.token, { with_response: true });\n }\n\n /**\n * Edits the original interaction response.\n *\n * @param options - The options to edit the message with\n * @param messageId - The message id to edit, defaults to `@original`\n * @returns The edited message\n *\n * This is used to edit the original interaction response message.\n *\n * Before using this method, the interaction needs to be replied to first before using this method - with `reply`, `deferReply` or `update`.\n */\n async editReply(options: InteractionResponseCallbackData | string, messageId: Snowflake | \"@original\" = \"@original\") {\n const replyOptions = typeof options === \"string\" ? { content: options } : options;\n const response = await this.api.interactions.editReply(\n this.applicationId,\n this.token,\n this.prepareResponsePayload(replyOptions),\n messageId,\n {\n signal: AbortSignal.timeout(5000),\n }\n );\n this.replied = true;\n return response;\n }\n\n /**\n * Deletes the original interaction response (or a follow-up message).\n *\n * @param messageId - The message id to delete, defaults to `@original`\n * @returns A promise that resolves when the message is deleted\n *\n * This is used to delete the original interaction response message or a follow-up message.\n */\n deleteReply(messageId?: Snowflake | \"@original\") {\n return this.api.interactions.deleteReply(this.applicationId, this.token, messageId);\n }\n\n /**\n * Updates the original interaction response.\n *\n * @param options - The options to update the message with\n * @returns The updated message\n *\n * This is mainly used for component interactions where you want to update the message the component is attached to OR for\n * moodal submit interactions to update the message that opened the modal.\n *\n * After calling this method, the interaction is considered replied and you need to use `editReply` to edit the original response.\n */\n async update(options: InteractionResponseCallbackData | string) {\n const updateOptions = typeof options === \"string\" ? { content: options } : options;\n const response = await this.api.interactions.updateMessage(\n this.id,\n this.token,\n { ...this.prepareResponsePayload(updateOptions), with_response: true },\n {\n signal: AbortSignal.timeout(5000),\n }\n );\n this.replied = true;\n return response;\n }\n\n /**\n * Sends a follow-up message to the interaction.\n *\n * @param options - The options to send the follow-up message with\n * @param forceEphemeral - Whether to force the message to be ephemeral\n * @returns The sent follow-up message\n *\n * This is used to send additional messages after the initial interaction response.\n */\n async followUp(options: InteractionResponseCallbackData | string, forceEphemeral = false) {\n const followUpOptions = typeof options === \"string\" ? { content: options } : options;\n if (forceEphemeral) {\n followUpOptions.flags = (followUpOptions.flags ?? 0) | 64;\n }\n const response = await this.api.interactions.followUp(\n this.applicationId,\n this.token,\n this.prepareResponsePayload(followUpOptions),\n {\n signal: AbortSignal.timeout(5000),\n }\n );\n return response;\n }\n\n // Typeguards\n isCommand(): this is CommandInteraction<ApplicationCommandType, Context> {\n return this.raw.type === InteractionType.ApplicationCommand;\n }\n\n isChatInputCommand(): this is ChatInputCommandInteraction<Context> {\n return (\n this.raw.type === InteractionType.ApplicationCommand &&\n (this.raw as APIApplicationCommandInteraction).data.type === ApplicationCommandType.ChatInput\n );\n }\n\n isUserContextCommand(): this is UserContextInteraction<Context> {\n return (\n this.raw.type === InteractionType.ApplicationCommand &&\n (this.raw as APIApplicationCommandInteraction).data.type === ApplicationCommandType.User\n );\n }\n\n isMessageContextCommand(): this is MessageContextInteraction<Context> {\n return (\n this.raw.type === InteractionType.ApplicationCommand &&\n (this.raw as APIApplicationCommandInteraction).data.type === ApplicationCommandType.Message\n );\n }\n\n isModal(): this is ModalInteraction {\n return this.raw.type === InteractionType.ModalSubmit;\n }\n\n isMessageModal(): this is ModalInteraction<Context & { message: APIMessage }> {\n return this.isModal() && !!this.message;\n }\n\n isMessageComponent(): this is MessageComponentInteraction<Context, MessageComponentType> {\n return this.raw.type === InteractionType.MessageComponent;\n }\n\n isButton(): this is ButtonInteraction<Context> {\n return this.isMessageComponent() && this.raw.data.component_type === ComponentType.Button;\n }\n\n isStringSelect(): this is StringSelectInteraction<Context> {\n return this.isMessageComponent() && this.raw.data.component_type === ComponentType.StringSelect;\n }\n\n isUserSelect(): this is UserSelectInteraction<Context> {\n return this.isMessageComponent() && this.raw.data.component_type === ComponentType.UserSelect;\n }\n\n isRoleSelect(): this is RoleSelectInteraction<Context> {\n return this.isMessageComponent() && this.raw.data.component_type === ComponentType.RoleSelect;\n }\n\n isMentionableSelect(): this is MentionableSelectInteraction<Context> {\n return this.isMessageComponent() && this.raw.data.component_type === ComponentType.MentionableSelect;\n }\n\n isChannelSelect(): this is ChannelSelectInteraction<Context> {\n return this.isMessageComponent() && this.raw.data.component_type === ComponentType.ChannelSelect;\n }\n\n isAutocomplete(): this is AutocompleteInteraction<Context> & { type: InteractionType.ApplicationCommandAutocomplete } {\n return this.raw.type === InteractionType.ApplicationCommandAutocomplete;\n }\n}\n","import { InteractionType } from \"discord-api-types/v10\";\nimport { ModalBuilder } from \"@discordjs/builders\";\nimport { BaseInteraction } from \"./BaseInteraction\";\nimport type { BaseInteractionContext, ModalInteractionResponseCallbackData } from \"../types\";\n\nclass ModalCapableInteraction<\n Type extends InteractionType,\n Context extends BaseInteractionContext = BaseInteractionContext,\n> extends BaseInteraction<Type, Context> {\n /**\n * Responds to the interaction with a modal.\n *\n * @param data - The modal data to send\n */\n showModal(data: ModalInteractionResponseCallbackData | ModalBuilder) {\n const responseData = {\n ...(data instanceof ModalBuilder ? data.toJSON() : data),\n components:\n data instanceof ModalBuilder\n ? data.components.map((row) => row.toJSON())\n : data.components.map((row) => (this.isJSONEncodable(row) ? row.toJSON() : row)),\n };\n return this.api.interactions.createModal(this.id, this.token, responseData);\n }\n}\n\nexport { ModalCapableInteraction };\n","import { APIApplicationCommandInteraction, ApplicationCommandType, InteractionType } from \"discord-api-types/v10\";\nimport { API } from \"@discordjs/core/http-only\";\nimport { BaseInteractionContext } from \"../types\";\nimport { ModalCapableInteraction } from \"./ModalCapableInteraction\";\n\nabstract class CommandInteraction<\n CType extends ApplicationCommandType = ApplicationCommandType,\n Context extends BaseInteractionContext = BaseInteractionContext,\n> extends ModalCapableInteraction<InteractionType.ApplicationCommand, Context> {\n public readonly commandType: CType;\n\n constructor(api: API, interaction: Extract<APIApplicationCommandInteraction, { data: { type: CType } }>, c: Context) {\n super(api, interaction, c);\n this.commandType = interaction.data.type;\n }\n\n get commandName() {\n return this.raw.data.name;\n }\n\n get commandId() {\n return this.raw.data.id;\n }\n\n isOfType<T extends ApplicationCommandType>(type: T): this is CommandInteraction<T, Context> {\n return (this.commandType as ApplicationCommandType) === type;\n }\n}\n\nexport { CommandInteraction };\n","import { ApplicationCommandType, type APIChatInputApplicationCommandInteraction } from \"discord-api-types/v10\";\nimport { CommandInteractionOptionResolver } from \"@resolvers/CommandOptionResolver\";\nimport { API } from \"@discordjs/core/http-only\";\nimport { BaseInteractionContext } from \"../types\";\nimport { CommandInteraction } from \"./CommandInteraction\";\n\nclass ChatInputCommandInteraction<Context extends BaseInteractionContext = BaseInteractionContext> extends CommandInteraction<\n ApplicationCommandType.ChatInput,\n Context\n> {\n public readonly options: CommandInteractionOptionResolver;\n constructor(api: API, interaction: APIChatInputApplicationCommandInteraction, c: Context) {\n super(api, interaction, c);\n this.options = new CommandInteractionOptionResolver(interaction.data.options, interaction.data.resolved);\n }\n}\n\nexport { ChatInputCommandInteraction };\n","import type { APIInteraction, APIWebhookEvent } from \"discord-api-types/v10\";\nimport { cloneRawRequest, type HonoRequest } from \"hono/request\";\nimport { BufferSource } from \"../types\";\n\nexport const subtleCrypto = crypto.subtle;\n\n/**\n * Converts different types to Uint8Array.\n *\n * @param value - Value to convert. Strings are parsed as hex.\n * @param format - Format of value. Valid options: 'hex'. Defaults to utf-8.\n * @returns Value in Uint8Array form.\n */\nfunction valueToUint8Array(value: Uint8Array | ArrayBuffer | Buffer | string, format?: string): Uint8Array {\n if (value == null) {\n return new Uint8Array();\n }\n if (typeof value === \"string\") {\n if (format === \"hex\") {\n const matches = value.match(/.{1,2}/g);\n if (matches == null) {\n throw new Error(\"Value is not a valid hex string\");\n }\n const hexVal = matches.map((byte: string) => Number.parseInt(byte, 16));\n return new Uint8Array(hexVal);\n }\n\n return new TextEncoder().encode(value);\n }\n try {\n if (Buffer.isBuffer(value)) {\n return new Uint8Array(value);\n }\n } catch (_ex) {\n // Runtime doesn't have Buffer\n }\n if (value instanceof ArrayBuffer) {\n return new Uint8Array(value);\n }\n if (value instanceof Uint8Array) {\n return value;\n }\n throw new Error(\"Unrecognized value type, must be one of: string, Buffer, ArrayBuffer, Uint8Array\");\n}\n\n/**\n * Merge two arrays.\n *\n * @param arr1 - First array\n * @param arr2 - Second array\n * @returns Concatenated arrays\n */\nfunction concatUint8Arrays(arr1: Uint8Array, arr2: Uint8Array): Uint8Array {\n const merged = new Uint8Array(arr1.length + arr2.length);\n merged.set(arr1);\n merged.set(arr2, arr1.length);\n return merged;\n}\n\n/**\n * Validates a payload from Discord against its signature and key.\n *\n * @param rawBody - The raw payload data\n * @param signature - The signature from the `X-Signature-Ed25519` header\n * @param timestamp - The timestamp from the `X-Signature-Timestamp` header\n * @param clientPublicKey - The public key from the Discord developer dashboard\n * @returns Whether or not validation was successful\n */\nexport async function verifyKey(\n rawBody: Uint8Array | ArrayBuffer | Buffer | string,\n signature: string | null,\n timestamp: string | null,\n clientPublicKey: string | CryptoKey\n): Promise<boolean> {\n if (!signature || !timestamp) return false;\n try {\n const timestampData = valueToUint8Array(timestamp);\n const bodyData = valueToUint8Array(rawBody);\n const message = concatUint8Arrays(timestampData, bodyData);\n const publicKey =\n typeof clientPublicKey === \"string\"\n ? await subtleCrypto.importKey(\n \"raw\",\n valueToUint8Array(clientPublicKey, \"hex\").buffer as BufferSource,\n {\n name: \"ed25519\",\n },\n false,\n [\"verify\"]\n )\n : clientPublicKey;\n const isValid = await subtleCrypto.verify(\n {\n name: \"ed25519\",\n },\n publicKey,\n valueToUint8Array(signature, \"hex\").buffer as ArrayBuffer,\n message.buffer as ArrayBuffer\n );\n return isValid;\n } catch (_ex) {\n return false;\n }\n}\n\nexport async function verifyDiscordRequest<T extends APIInteraction | APIWebhookEvent>(\n req: HonoRequest<any, any>,\n discordPublicKey: string | CryptoKey\n) {\n const signature = req.header(\"x-signature-ed25519\");\n const timestamp = req.header(\"x-signature-timestamp\");\n const body = await (await cloneRawRequest(req)).text();\n const isValidRequest = signature && timestamp && (await verifyKey(body, signature, timestamp, discordPublicKey));\n if (!isValidRequest) {\n return { isValid: false } as const;\n }\n\n return { data: JSON.parse(body) as T, isValid: true } as const;\n}\n","// From discord.js\ninterface Colors {\n /** 0x1ABC9C | rgb(26,188,156) */\n Aqua: number;\n /** 0x3498DB | rgb(52,152,219) */\n Blue: number;\n /** 0x5865F2 | rgb(88,101,242) */\n Blurple: number;\n /** 0x11806A | rgb(17,128,106) */\n DarkAqua: number;\n /** 0x206694 | rgb(32,102,148) */\n DarkBlue: number;\n /** 0x2C2F33 | rgb(44,47,51) */\n DarkButNotBlack: number;\n /** 0x7F8C8D | rgb(127,140,141) */\n DarkerGrey: number;\n /** 0xC27C0E | rgb(194,124,14) */\n DarkGold: number;\n /** 0x1F8B4C | rgb(31,139,76) */\n DarkGreen: number;\n /** 0x979C9F | rgb(151,156,159) */\n DarkGrey: number;\n /** 0x2C3E50 | rgb(44,62,80) */\n DarkNavy: number;\n /** 0xA84300 | rgb(168,67,0) */\n DarkOrange: number;\n /** 0x71368A | rgb(113,54,138) */\n DarkPurple: number;\n /** 0x992D22 | rgb(153,45,34) */\n DarkRed: number;\n /** 0xAD1457 | rgb(173,20,87) */\n DarkVividPink: number;\n /** 0x000000 | rgb(0,0,0) */\n Default: number;\n /** 0xEB459E | rgb(235,69,158) */\n Fuchsia: number;\n /** 0xF1C40F | rgb(241,196,15) */\n Gold: number;\n /** 0x57F287 | rgb(87,242,135) */\n Green: number;\n /** 0x95A5A6 | rgb(149,165,166) */\n Grey: number;\n /** 0x99AAb5 | rgb(153,170,181) */\n Greyple: number;\n /** 0xBCC0C0 | rgb(188,192,192) */\n LightGrey: number;\n /** 0xE91E63 | rgb(233,30,99) */\n LuminousVividPink: number;\n /** 0x34495E | rgb(52,73,94) */\n Navy: number;\n /** 0x23272A | rgb(35,39,42) */\n NotQuiteBlack: number;\n /** 0xE67E22 | rgb(230,126,34) */\n Orange: number;\n /** 0x9B59B6 | rgb(155,89,182) */\n Purple: number;\n /** 0xED4245 | rgb(237,66,69) */\n Red: number;\n /** 0xFFFFFF | rgb(255,255,255) */\n White: number;\n /** 0xFEE75C | rgb(254,231,92) */\n Yellow: number;\n}\n\nexport const Colors: Colors = {\n Aqua: 0x1abc9c,\n Blue: 0x3498db,\n Blurple: 0x5865f2,\n DarkAqua: 0x11806a,\n DarkBlue: 0x206694,\n DarkButNotBlack: 0x2c2f33,\n DarkerGrey: 0x7f8c8d,\n DarkGold: 0xc27c0e,\n DarkGreen: 0x1f8b4c,\n DarkGrey: 0x979c9f,\n DarkNavy: 0x2c3e50,\n DarkOrange: 0xa84300,\n DarkPurple: 0x71368a,\n DarkRed: 0x992d22,\n DarkVividPink: 0xad1457,\n Default: 0x000000,\n Fuchsia: 0xeb459e,\n Gold: 0xf1c40f,\n Green: 0x57f287,\n Grey: 0x95a5a6,\n Greyple: 0x99aab5,\n LightGrey: 0xbcc0c0,\n LuminousVividPink: 0xe91e63,\n Navy: 0x34495e,\n NotQuiteBlack: 0x23272a,\n Orange: 0xe67e22,\n Purple: 0x9b59b6,\n Red: 0xed4245,\n White: 0xffffff,\n Yellow: 0xfee75c,\n};\n","import { AnyHandler } from \"@handlers/index\";\nimport { API } from \"@discordjs/core/http-only\";\nimport { REST } from \"@discordjs/rest\";\nimport { FlatOrNestedArray } from \"../types\";\nimport type { RESTPostAPIApplicationCommandsJSONBody, RESTPostAPIApplicationGuildCommandsJSONBody } from \"discord-api-types/v10\";\n\n/**\n * Registers application commands (Slash and Context Menus) with Discord's API.\n *\n * This function flattens the provided handlers, separates global from guild-specific\n * commands, and performs a bulk overwrite for both.\n *\n * @param token - The Discord Bot token.\n * @param applicationId - The Discord Application ID.\n * @param handlers - A rest parameter of handlers or arrays of handlers to register.\n *\n * @throws {Error} If the API request to Discord fails.\n */\nexport async function registerCommands(\n token: string | undefined,\n applicationId: string | undefined,\n ...handlers: FlatOrNestedArray<AnyHandler>\n) {\n const flatCommands = handlers.flat(Infinity) as AnyHandler[];\n const { globalCommands, guildCommands } = flatCommands\n .map((handler) => {\n if (handler.handlerType === \"slash\" || handler.handlerType === \"context\") {\n return handler;\n }\n return undefined;\n })\n .filter((cmd) => cmd !== undefined)\n .reduce(\n (acc, cmd) => {\n if (cmd.isGuildCommand()) {\n for (const guildId of cmd.guildIds.values()) {\n if (!acc.guildCommands[guildId]) {\n acc.guildCommands[guildId] = [];\n }\n acc.guildCommands[guildId].push(cmd.toJSON());\n }\n } else {\n acc.globalCommands.push(cmd.toJSON());\n }\n return acc;\n },\n {\n globalCommands: [] as RESTPostAPIApplicationCommandsJSONBody[],\n guildCommands: {} as Record<string, RESTPostAPIApplicationGuildCommandsJSONBody[]>,\n }\n );\n\n if (!token || !applicationId) {\n console.warn(\"Token or Application ID not provided, skipping command registration.\");\n return;\n }\n\n const api = new API(new REST({ version: \"10\" }).setToken(token));\n try {\n await api.applicationCommands.bulkOverwriteGlobalCommands(applicationId, globalCommands);\n console.log(`---- ✅ Successfully registered ${globalCommands.length} global commands ----`);\n } catch (error) {\n console.error(\"---- ❌ Error registering global commands ----\");\n throw error;\n }\n\n if (Object.keys(guildCommands).length === 0) {\n return;\n }\n\n const guildCommandsArray = Object.entries(guildCommands).map(([guildId, commands]) => ({ guildId, commands }));\n\n for (const { guildId, commands } of guildCommandsArray) {\n try {\n await api.applicationCommands.bulkOverwriteGuildCommands(applicationId, guildId, commands);\n console.log(`---- ✅ Successfully registered ${commands.length} guild commands for guild ${guildId} ----`);\n } catch (error) {\n console.error(`---- ❌ Error registering guild commands for guild ${guildId} ----`);\n throw error;\n }\n }\n}\n","export * from \"@utils/Colors\";\nexport * from \"@utils/registerCommands\";\n\n/**\n * Parse a custom ID string into its parts.\n *\n * Supports two modes:\n * - onlyPrefix = true: returns the prefix string before the first '/' or '?'.\n * - onlyPrefix = false (default): returns an object with parsed pieces.\n *\n * Expected customId shapes:\n * - \"prefix/component/other/path?param1/param2\"\n * - \"prefix?param1/param2\"\n *\n * @param customId - The custom ID to parse.\n * @param onlyPrefix - If true, only return the prefix string (default: false).\n * @returns If onlyPrefix is true: string (the prefix). Otherwise an object with:\n * - compPath: string[] (full path split by '/'),\n * - prefix: string (first item of compPath),\n * - lastPathItem: string (last item of compPath),\n * - component: string | null (second item of compPath or null),\n * - params: string[] (params split by '/'; empty array when none),\n * - firstParam: string | null,\n * - lastParam: string | null\n *\n * @example\n * parseCustomId(\"modal/user/profile?123/abc\")\n * // => { compPath: [\"modal\",\"user\",\"profile\"], prefix: \"modal\", ... params: [\"123\",\"abc\"], ... }\n *\n * parseCustomId(\"button/click\", true)\n * // => \"button\"\n */\nexport function parseCustomId(customId: string, onlyPrefix: true): string;\nexport function parseCustomId(\n customId: string,\n onlyPrefix?: false\n): {\n compPath: string[];\n prefix: string;\n lastPathItem: string;\n component: string | null;\n params: string[];\n firstParam: string | null;\n lastParam: string | null;\n};\nexport function parseCustomId(customId: string, onlyPrefix: boolean = false) {\n if (onlyPrefix) {\n const match = customId.match(/^(.+?)(\\/|\\?)/i);\n return match ? match[1] : customId;\n }\n const [path, params] = customId.split(\"?\") as [string, string | undefined];\n const pathS = path.split(\"/\");\n const parms = params?.split(\"/\") || [];\n return {\n compPath: pathS,\n prefix: pathS[0],\n lastPathItem: pathS[pathS.length - 1],\n component: pathS[1] || null,\n params: parms || [],\n firstParam: parms[0] || null,\n lastParam: parms[parms.length - 1] || null,\n };\n}\n","import { APIUserApplicationCommandInteraction, APIUser, ApplicationCommandType } from \"discord-api-types/v10\";\nimport { API } from \"@discordjs/core/http-only\";\nimport { BaseInteractionContext } from \"../types\";\nimport { CommandInteraction } from \"./CommandInteraction\";\n\nclass UserContextInteraction<Context extends BaseInteractionContext = BaseInteractionContext> extends CommandInteraction<\n ApplicationCommandType.User,\n Context\n> {\n public readonly targetUser: APIUser;\n\n constructor(api: API, interaction: APIUserApplicationCommandInteraction, c: Context) {\n super(api, interaction, c);\n this.targetUser = interaction.data.resolved.users[interaction.data.target_id];\n }\n}\n\nexport { UserContextInteraction };\n","import { APIMessage, APIMessageApplicationCommandInteraction, ApplicationCommandType } from \"discord-api-types/v10\";\nimport { API } from \"@discordjs/core/http-only\";\nimport { BaseInteractionContext } from \"../types\";\nimport { CommandInteraction } from \"./CommandInteraction\";\n\nclass MessageContextInteraction<Context extends BaseInteractionContext = BaseInteractionContext> extends CommandInteraction<\n ApplicationCommandType.Message,\n Context\n> {\n public readonly targetMessage: APIMessage;\n\n constructor(api: API, interaction: APIMessageApplicationCommandInteraction, c: Context) {\n super(api, interaction, c);\n this.targetMessage = interaction.data.resolved.messages[interaction.data.target_id];\n }\n}\n\nexport { MessageContextInteraction };\n","import {\n APIAttachment,\n APIInteractionDataResolved,\n APIInteractionDataResolvedChannel,\n APIInteractionDataResolvedGuildMember,\n APIModalSubmitCheckboxComponent,\n APIModalSubmitCheckboxGroupComponent,\n APIModalSubmitFileUploadComponent,\n APIModalSubmitRadioGroupComponent,\n APIRole,\n APIUser,\n ComponentType,\n ModalSubmitLabelComponent,\n ModalSubmitTextDisplayComponent,\n Snowflake,\n} from \"discord-api-types/v10\";\nimport { APIInteractionDataResolvedCollections, ResolvedSelectedGuildMember } from \"../types\";\nimport { Collection, ReadonlyCollection } from \"@discordjs/collection\";\n\nexport interface BaseModalData<Type extends ComponentType> {\n id?: number;\n type: Type;\n}\n\nexport interface TextInputModalData extends BaseModalData<ComponentType.TextInput> {\n custom_id: string;\n value: string;\n}\n\nexport interface SelectMenuModalData extends BaseModalData<\n | ComponentType.ChannelSelect\n | ComponentType.MentionableSelect\n | ComponentType.RoleSelect\n | ComponentType.StringSelect\n | ComponentType.UserSelect\n> {\n custom_id: string;\n channels?: ReadonlyCollection<Snowflake, APIInteractionDataResolvedChannel>;\n members?: ReadonlyCollection<Snowflake, APIInteractionDataResolvedGuildMember>;\n roles?: ReadonlyCollection<Snowflake, APIRole>;\n users?: ReadonlyCollection<Snowflake, APIUser>;\n /**\n * The raw values selected by the user.\n */\n values: readonly string[];\n}\n\n// Technically, we had to add file uploads too, but we ain't using them anyway\ntype APIModalData =\n | TextInputModalData\n | SelectMenuModalData\n | APIModalSubmitCheckboxComponent\n | APIModalSubmitCheckboxGroupComponent\n | APIModalSubmitRadioGroupComponent\n | APIModalSubmitFileUploadComponent;\n\nexport class ModalComponentResolver {\n private _resolved: APIInteractionDataResolvedCollections;\n private hoistedComponents: Collection<string, APIModalData>;\n\n constructor(\n private components: (ModalSubmitLabelComponent | ModalSubmitTextDisplayComponent)[],\n resolved?: APIInteractionDataResolved\n ) {\n this._resolved = Object.keys(resolved ?? {}).reduce((acc, key) => {\n const resolvedData = resolved?.[key as keyof APIInteractionDataResolved];\n if (key === \"members\") {\n // get users and combine them with members for easy access; a user is expected to ALWAYS be present if a member is\n const users = resolved?.users ? new Collection(Object.entries(resolved.users)) : new Collection();\n const members = resolvedData ? new Collection(Object.entries(resolvedData)) : new Collection();\n const combined = new Collection([...members.entries()].map(([id, member]) => [id, { ...member, user: users.get(id)! }]));\n acc[key] = combined;\n return acc;\n }\n const collection = new Collection(resolvedData ? Object.entries(resolvedData) : []);\n acc[key] = collection;\n return acc;\n }, {} as any);\n\n this.hoistedComponents = this.components.reduce(\n (accumulator, next) => {\n // For label components\n if (next.type === ComponentType.Label) {\n accumulator.set(next.component.custom_id, next.component);\n }\n\n return accumulator;\n },\n new Collection() as Collection<string, APIModalData>\n );\n }\n\n public get data() {\n return this.hoistedComponents.map((component) => component);\n }\n\n /**\n * Checks if a component with the given custom ID exists in the modal.\n * @param custom_id The custom ID of the component to check for.\n * @returns True if a component with the given custom ID exists, false otherwise.\n */\n fieldExists(custom_id: string): boolean {\n return this.hoistedComponents.has(custom_id);\n }\n\n getComponent(custom_id: string): APIModalData {\n const component = this.hoistedComponents.get(custom_id);\n\n if (!component) throw new TypeError(\"No component found with the provided custom_id.\");\n\n return component;\n }\n\n /**\n * Gets the value of a text input component.\n *\n * @param custom_id The custom ID of the component.\n * @param required Whether to throw an error if the component is not found or not a text input.\n * @returns The value of the text input, or null if not set and not required.\n */\n getString(custom_id: string, required?: boolean): string | null;\n getString(custom_id: string, required: true): string;\n getString(custom_id: string, required: boolean = false): string | null {\n const component = this.getComponent(custom_id);\n if (component.type !== ComponentType.TextInput) {\n throw new TypeError(\"Component is not a text input\", { cause: { custom_id, type: component.type } });\n }\n return component.value;\n }\n\n /**\n * Gets the selected values of a select menu component.\n *\n * @param custom_id The custom ID of the component.\n * @param required Whether to throw an error if the component is not found or not a select menu.\n * @returns The selected values, or null if not set and not required.\n */\n getSelectedValues(custom_id: string, required?: boolean): readonly string[] | null;\n getSelectedValues(custom_id: string, required: true): readonly string[];\n getSelectedValues(custom_id: string, required: boolean = false): readonly string[] | null {\n const component = this.getComponent(custom_id);\n if (!(\"values\" in component)) {\n throw new TypeError(\"Component is not a select menu\", { cause: { custom_id, type: component.type } });\n }\n return component.values;\n }\n\n /**\n * Gets the selected channels from a channel select menu.\n *\n * @param custom_id The custom ID of the component.\n * @param required Whether to throw an error if the component is not found or not a channel select.\n * @returns The selected channels, or null if not set and not required.\n */\n getSelectedChannels(custom_id: string, required?: boolean): Collection<string, APIInteractionDataResolvedChannel> | null;\n getSelectedChannels(custom_id: string, required: true): Collection<string, APIInteractionDataResolvedChannel>;\n getSelectedChannels(\n custom_id: string,\n required: boolean = false\n ): Collection<string, APIInteractionDataResolvedChannel> | null {\n const component = this.getComponent(custom_id);\n if (component.type !== ComponentType.ChannelSelect) {\n throw new TypeError(\"Component is not a channel select\", { cause: { custom_id, type: component.type } });\n }\n const values = component.values;\n const channels = values.map((id) => this._resolved.channels?.get(id)).filter(Boolean) as APIInteractionDataResolvedChannel[];\n return channels.length > 0\n ? new Collection(channels.map((channel) => [channel.id, channel]))\n : required\n ? new Collection()\n : null;\n }\n\n /**\n * Gets the selected users from a user select menu.\n *\n * @param custom_id The custom ID of the component.\n * @param required Whether to throw an error if the component is not found or not a user select.\n * @returns The selected users, or null if not set and not required.\n */\n getSelectedUsers(custom_id: string, required?: boolean): Collection<string, APIUser> | null;\n getSelectedUsers(custom_id: string, required: true): Collection<string, APIUser>;\n getSelectedUsers(custom_id: string, required: boolean = false): Collection<string, APIUser> | null {\n const component = this.getComponent(custom_id);\n if (component.type !== ComponentType.UserSelect) {\n throw new TypeError(\"Component is not a user select\", { cause: { custom_id, type: component.type } });\n }\n const values = component.values;\n const users = values.map((id) => this._resolved.users?.get(id)).filter(Boolean) as APIUser[];\n return users.length > 0 ? new Collection(users.map((user) => [user.id, user])) : required ? new Collection() : null;\n }\n\n /**\n * Gets the selected members from a user select menu (if in guild).\n *\n * @param custom_id The custom ID of the component.\n * @param required Whether to throw an error if the component is not found or not a user select.\n * @returns The selected members, or null if not set and not required.\n */\n getSelectedMembers(custom_id: string, required?: boolean): Collection<string, ResolvedSelectedGuildMember> | null;\n getSelectedMembers(custom_id: string, required: true): Collection<string, ResolvedSelectedGuildMember>;\n getSelectedMembers(custom_id: string, required: boolean = false): Collection<string, ResolvedSelectedGuildMember> | null {\n const component = this.getComponent(custom_id);\n if (component.type !== ComponentType.UserSelect) {\n throw new TypeError(\"Component is not a user select\", { cause: { custom_id, type: component.type } });\n }\n const values = component.values;\n const members = values.map((id) => this._resolved.members?.get(id)).filter(Boolean) as ResolvedSelectedGuildMember[];\n return members.length > 0\n ? new Collection(members.map((member) => [member.user.id, member]))\n : required\n ? new Collection()\n : null;\n }\n\n /**\n * Gets the selected roles from a role select menu.\n *\n * @param custom_id The custom ID of the component.\n * @param required Whether to throw an error if the component is not found or not a role select.\n * @returns The selected roles, or null if not set and not required.\n */\n getSelectedRoles(custom_id: string, required?: boolean): Collection<string, APIRole> | null;\n getSelectedRoles(custom_id: string, required: true): Collection<string, APIRole>;\n getSelectedRoles(custom_id: string, required: boolean = false): Collection<string, APIRole> | null {\n const component = this.getComponent(custom_id);\n if (component.type !== ComponentType.RoleSelect) {\n throw new TypeError(\"Component is not a role select\", { cause: { custom_id, type: component.type } });\n }\n const values = component.values;\n const roles = values.map((id) => this._resolved.roles?.get(id)).filter(Boolean) as APIRole[];\n return roles.length > 0 ? new Collection(roles.map((role) => [role.id, role])) : required ? new Collection() : null;\n }\n\n /**\n * Gets the selected mentionables from a mentionable select menu.\n *\n * @param custom_id The custom ID of the component.\n * @param required Whether to throw an error if the component is not found or not a mentionable select.\n * @returns The selected mentionables (users, members, or roles), or null if not set and not required.\n */\n getSelectedMentionables(custom_id: string, required?: boolean): (ResolvedSelectedGuildMember | APIUser | APIRole)[] | null;\n getSelectedMentionables(custom_id: string, required: true): (ResolvedSelectedGuildMember | APIUser | APIRole)[];\n getSelectedMentionables(\n custom_id: string,\n required: boolean = false\n ): (ResolvedSelectedGuildMember | APIUser | APIRole)[] | null {\n const component = this.getComponent(custom_id);\n if (component.type !== ComponentType.MentionableSelect) {\n throw new TypeError(\"Component is not a mentionable select\", { cause: { custom_id, type: component.type } });\n }\n const values = component.values;\n const mentionables: (ResolvedSelectedGuildMember | APIUser | APIRole)[] = [];\n for (const id of values) {\n const member = this._resolved.members?.get(id);\n if (member) mentionables.push(member);\n else {\n const user = this._resolved.users?.get(id);\n if (user) mentionables.push(user);\n else {\n const role = this._resolved.roles?.get(id);\n if (role) mentionables.push(role);\n }\n }\n }\n return mentionables.length > 0 ? mentionables : required ? [] : null;\n }\n\n getFiles(custom_id: string, required?: boolean): Collection<string, APIAttachment> | null;\n getFiles(custom_id: string, required: true): Collection<string, APIAttachment>;\n getFiles(custom_id: string, required?: boolean): Collection<string, APIAttachment> | null {\n const component = this.getComponent(custom_id);\n if (component.type !== ComponentType.FileUpload) {\n throw new TypeError(\"Component is not a file upload\", { cause: { custom_id, type: component.type } });\n }\n const values = component.values;\n const attachments = values.map((id) => this._resolved.attachments?.get(id)).filter(Boolean) as APIAttachment[];\n if (attachments.length === 0) {\n return required ? new Collection() : null;\n }\n return new Collection(attachments.map((attachment) => [attachment.id, attachment]));\n }\n\n getRadioGroupValue(custom_id: string, required?: boolean): string | null;\n getRadioGroupValue(custom_id: string, required: true): string;\n getRadioGroupValue(custom_id: string, required?: boolean): string | null {\n const component = this.getComponent(custom_id);\n if (component.type !== ComponentType.RadioGroup) {\n throw new TypeError(\"Component is not a radio group\", { cause: { custom_id, type: component.type } });\n }\n return component.value ?? (required ? \"\" : null);\n }\n\n getCheckboxGroupValues(custom_id: string, required?: boolean): string[] | null;\n getCheckboxGroupValues(custom_id: string, required: true): string[];\n getCheckboxGroupValues(custom_id: string, required?: boolean): string[] | null {\n const component = this.getComponent(custom_id);\n if (component.type !== ComponentType.CheckboxGroup) {\n throw new TypeError(\"Component is not a checkbox group\", { cause: { custom_id, type: component.type } });\n }\n return component.values.length > 0 ? component.values : required ? [] : null;\n }\n\n getCheckboxValue(custom_id: string, required?: boolean): boolean | null;\n getCheckboxValue(custom_id: string, required: true): boolean;\n getCheckboxValue(custom_id: string, required?: boolean): boolean | null {\n const component = this.getComponent(custom_id);\n if (component.type !== ComponentType.Checkbox) {\n throw new TypeError(\"Component is not a checkbox\", { cause: { custom_id, type: component.type } });\n }\n return component.value ?? (required ? false : null);\n }\n\n getAllComponents(): APIModalData[] {\n return this.hoistedComponents.map((component) => component);\n }\n}\n","import {\n APIMessage,\n APIModalSubmitInteraction,\n InteractionType,\n ModalSubmitLabelComponent,\n ModalSubmitTextDisplayComponent,\n} from \"discord-api-types/v10\";\nimport { API } from \"@discordjs/core/http-only\";\nimport { ModalComponentResolver } from \"@resolvers/ModalComponentResolver\";\nimport { BaseInteraction } from \"./BaseInteraction\";\nimport { BaseInteractionContext } from \"../types\";\n\nclass ModalInteraction<Context extends BaseInteractionContext = BaseInteractionContext> extends BaseInteraction<\n InteractionType.ModalSubmit,\n Context\n> {\n public readonly fields: ModalComponentResolver;\n public readonly message?: APIMessage;\n public readonly customId: string;\n\n constructor(api: API, interaction: APIModalSubmitInteraction, c: Context) {\n super(api, interaction, c);\n this.customId = interaction.data.custom_id;\n this.fields = new ModalComponentResolver(\n interaction.data.components as (ModalSubmitLabelComponent | ModalSubmitTextDisplayComponent)[],\n interaction.data.resolved\n );\n if (\"message\" in interaction && interaction.message) {\n this.message = interaction.message;\n }\n }\n}\n\nexport { ModalInteraction };\n","import {\n APIApplicationCommandAutocompleteInteraction,\n APIApplicationCommandOptionChoice,\n InteractionType,\n type APIChatInputApplicationCommandInteraction,\n} from \"discord-api-types/v10\";\nimport { CommandInteractionOptionResolver } from \"@resolvers/CommandOptionResolver\";\nimport { API } from \"@discordjs/core/http-only\";\nimport { BaseInteraction } from \"./BaseInteraction\";\nimport { BaseInteractionContext } from \"../types\";\n\nclass AutocompleteInteraction<Context extends BaseInteractionContext = BaseInteractionContext> extends BaseInteraction<\n InteractionType.ApplicationCommandAutocomplete,\n Context\n> {\n public readonly options: CommandInteractionOptionResolver;\n public responded = false;\n\n constructor(api: API, interaction: APIApplicationCommandAutocompleteInteraction, c: Context) {\n super(api, interaction, c);\n this.options = new CommandInteractionOptionResolver(interaction.data.options, interaction.data.resolved);\n }\n\n get commandName() {\n return this.raw.data.name;\n }\n\n get commandId() {\n return this.raw.data.id;\n }\n\n async respond(choices: APIApplicationCommandOptionChoice[]) {\n await this.api.interactions.createAutocompleteResponse(this.id, this.token, { choices });\n this.responded = true;\n }\n}\n\nexport { AutocompleteInteraction };\n","import type { ChatInputCommandInteraction } from \"@ctx/ChatInputInteraction\";\nimport type { AutocompleteInteraction } from \"@ctx/AutocompleteInteraction\";\nimport { SlashCommandBuilder } from \"@discordjs/builders\";\nimport type {\n SlashCommandBooleanOption,\n SlashCommandUserOption,\n SlashCommandChannelOption,\n SlashCommandRoleOption,\n SlashCommandAttachmentOption,\n SlashCommandMentionableOption,\n SlashCommandStringOption,\n SlashCommandIntegerOption,\n SlashCommandNumberOption,\n SlashCommandSubcommandBuilder,\n SlashCommandSubcommandGroupBuilder,\n} from \"@discordjs/builders\";\nimport type { BaseInteractionContext } from \"../types\";\n\n/**\n * Handler for chat input commands with optional autocomplete support\n */\nexport class SlashCommandHandler<Context extends BaseInteractionContext = BaseInteractionContext> extends SlashCommandBuilder {\n readonly handlerType = \"slash\";\n private handlerFn?: (interaction: ChatInputCommandInteraction<Context>) => Promise<any> | any;\n private autocompleteFn?: (interaction: AutocompleteInteraction<Context>) => Promise<any> | any;\n /**\n * Set of guild IDs where this command is registered (empty for global commands)\n */\n readonly guildIds = new Set<string>();\n\n isGuildCommand(): boolean {\n return this.guildIds.size > 0;\n }\n\n setGuildIds(guildIds: string[]): this {\n this.guildIds.clear();\n for (const guildId of guildIds) {\n this.guildIds.add(guildId);\n }\n return this;\n }\n\n addGuildIds(...guildIds: string[]): this {\n for (const guildId of guildIds) {\n this.guildIds.add(guildId);\n }\n return this;\n }\n\n removeGuildIds(...guildIds: string[]): this {\n for (const guildId of guildIds) {\n this.guildIds.delete(guildId);\n }\n return this;\n }\n\n /**\n * Adds the command handler function.\n *\n * @param handler The function to handle the command interaction\n * @returns The current SlashCommandHandler instance\n */\n public addHandler(\n handler: (interaction: ChatInputCommandInteraction<Context>) => Promise<any> | any\n ): SlashCommandHandler<Context> {\n this.handlerFn = handler;\n return this;\n }\n\n /**\n * Adds the autocomplete handler function.\n *\n * @param handler The function to handle the autocomplete interaction\n * @returns The current SlashCommandHandler instance\n */\n public addAutocompleteHandler(\n handler: (interaction: AutocompleteInteraction<Context>) => Promise<any> | any\n ): SlashCommandHandler<Context> {\n this.autocompleteFn = handler;\n return this;\n }\n\n /**\n * Executes the command handler\n */\n async execute(interaction: ChatInputCommandInteraction<Context>): Promise<void> {\n if (!this.handlerFn) {\n throw new Error(`Command \"${this.name}\" does not have a handler`);\n }\n await this.handlerFn(interaction);\n }\n\n /**\n * Executes the autocomplete handler if it exists\n */\n async executeAutocomplete(interaction: AutocompleteInteraction<Context>): Promise<void> {\n if (this.autocompleteFn == undefined) {\n throw new Error(`Command \"${this.name}\" does not have an autocomplete handler`);\n }\n await this.autocompleteFn(interaction);\n }\n\n /**\n * Override option/subcommand adders so they return `this` (the handler),\n * preserving chaining when options/subcommands are added.\n */\n addBooleanOption(input: SlashCommandBooleanOption | ((builder: SlashCommandBooleanOption) => SlashCommandBooleanOption)): this {\n super.addBooleanOption(input);\n return this;\n }\n\n addUserOption(input: SlashCommandUserOption | ((builder: SlashCommandUserOption) => SlashCommandUserOption)): this {\n super.addUserOption(input);\n return this;\n }\n\n addChannelOption(input: SlashCommandChannelOption | ((builder: SlashCommandChannelOption) => SlashCommandChannelOption)): this {\n super.addChannelOption(input);\n return this;\n }\n\n addRoleOption(input: SlashCommandRoleOption | ((builder: SlashCommandRoleOption) => SlashCommandRoleOption)): this {\n super.addRoleOption(input);\n return this;\n }\n\n addAttachmentOption(\n input: SlashCommandAttachmentOption | ((builder: SlashCommandAttachmentOption) => SlashCommandAttachmentOption)\n ): this {\n super.addAttachmentOption(input);\n return this;\n }\n\n addMentionableOption(\n input: SlashCommandMentionableOption | ((builder: SlashCommandMentionableOption) => SlashCommandMentionableOption)\n ): this {\n super.addMentionableOption(input);\n return this;\n }\n\n addStringOption(input: SlashCommandStringOption | ((builder: SlashCommandStringOption) => SlashCommandStringOption)): this {\n super.addStringOption(input);\n return this;\n }\n\n addIntegerOption(input: SlashCommandIntegerOption | ((builder: SlashCommandIntegerOption) => SlashCommandIntegerOption)): this {\n super.addIntegerOption(input);\n return this;\n }\n\n addNumberOption(input: SlashCommandNumberOption | ((builder: SlashCommandNumberOption) => SlashCommandNumberOption)): this {\n super.addNumberOption(input);\n return this;\n }\n\n addSubcommand(\n input: SlashCommandSubcommandBuilder | ((sub: SlashCommandSubcommandBuilder) => SlashCommandSubcommandBuilder)\n ): this {\n super.addSubcommand(input);\n return this;\n }\n\n addSubcommandGroup(\n input:\n | SlashCommandSubcommandGroupBuilder\n | ((group: SlashCommandSubcommandGroupBuilder) => SlashCommandSubcommandGroupBuilder)\n ): this {\n super.addSubcommandGroup(input);\n return this;\n }\n}\n","import { ContextMenuCommandBuilder } from \"@discordjs/builders\";\nimport { MessageContextInteraction } from \"@ctx/MessageContextCommandInteraction\";\nimport { UserContextInteraction } from \"@ctx/UserContextCommandInteraction\";\nimport { BaseInteractionContext, ContextCommandType } from \"../types\";\n\nexport class ContextCommandHandler<\n Context extends BaseInteractionContext = BaseInteractionContext,\n T extends ContextCommandType = ContextCommandType,\n InteractionData = T extends ContextCommandType.User ? UserContextInteraction<Context> : MessageContextInteraction<Context>,\n> extends ContextMenuCommandBuilder {\n constructor(public readonly commandType: T) {\n super();\n this.setType(commandType as any); // ContextMenuCommandType is a type, not an enum so the values of the enum ContextCommandType isn't assignable to it directly\n }\n\n readonly handlerType = \"context\";\n private handlerFn?: (interaction: InteractionData) => Promise<any> | any;\n /**\n * Set of guild IDs where this command is registered (empty for global commands)\n */\n readonly guildIds = new Set<string>();\n\n isGuildCommand(): boolean {\n return this.guildIds.size > 0;\n }\n\n setGuildIds(guildIds: string[]): this {\n this.guildIds.clear();\n for (const guildId of guildIds) {\n this.guildIds.add(guildId);\n }\n return this;\n }\n\n addGuildIds(...guildIds: string[]): this {\n for (const guildId of guildIds) {\n this.guildIds.add(guildId);\n }\n return this;\n }\n\n removeGuildIds(...guildIds: string[]): this {\n for (const guildId of guildIds) {\n this.guildIds.delete(guildId);\n }\n return this;\n }\n\n public addHandler(\n handler: (interaction: InteractionData) => Promise<any> | any\n ): ContextCommandHandler<Context, T, InteractionData> {\n this.handlerFn = handler;\n return this;\n }\n\n /**\n * Executes the command handler\n */\n async execute(interaction: InteractionData): Promise<void> {\n if (!this.handlerFn) {\n throw new Error(`Command \"${this.name}\" does not have a handler`);\n }\n await this.handlerFn(interaction);\n }\n}\n","import { parseCustomId } from \"@utils/index\";\nimport { BaseInteractionContext, MessageComponentInteractionObj, MessageComponentType } from \"../types\";\n\n/**\n * Handler for message components (buttons, select menus) based on custom ID prefix\n */\nexport class ComponentHandler<\n Context extends BaseInteractionContext = BaseInteractionContext,\n CType extends MessageComponentType = MessageComponentType,\n> {\n readonly handlerType = \"component\";\n public readonly prefix: string;\n public readonly componentType: CType;\n private handlerFn?: (interaction: MessageComponentInteractionObj<Context, CType>) => Promise<any> | any;\n\n constructor(\n prefix: string,\n componentType: CType,\n handler?: (interaction: MessageComponentInteractionObj<Context, CType>) => Promise<any> | any\n ) {\n this.componentType = componentType;\n if (!prefix || typeof prefix !== \"string\") {\n throw new TypeError(\"Component handler prefix must be a non-empty string\");\n }\n\n this.prefix = prefix;\n if (handler) this.handlerFn = handler;\n }\n\n addHandler(\n handler: (interaction: MessageComponentInteractionObj<Context, CType>) => Promise<any> | any\n ): ComponentHandler<Context, CType> {\n this.handlerFn = handler;\n return this;\n }\n\n /**\n * Executes the component handler\n */\n async execute(interaction: MessageComponentInteractionObj<Context, CType>): Promise<void> {\n if (!this.handlerFn) {\n throw new Error(`Component handler with prefix \"${this.prefix}\" does not have a handler`);\n }\n await this.handlerFn(interaction);\n }\n\n /**\n * Checks if this handler matches the given custom ID\n */\n matches(customId: string): boolean {\n const prefix = parseCustomId(customId, true);\n return prefix === this.prefix;\n }\n}\n","import type { ModalInteraction } from \"@ctx/ModalInteraction\";\nimport { parseCustomId } from \"@utils/index\";\nimport type { BaseInteractionContext } from \"../types\";\n\n/**\n * Handler for modal submits based on custom ID prefix\n */\nexport class ModalHandler<Context extends BaseInteractionContext = BaseInteractionContext> {\n readonly handlerType = \"modal\";\n public readonly prefix: string;\n private handlerFn?: (interaction: ModalInteraction<Context>) => Promise<any> | any;\n\n constructor(prefix: string, handler?: (interaction: ModalInteraction<Context>) => Promise<any> | any) {\n if (!prefix || typeof prefix !== \"string\") {\n throw new TypeError(\"Modal handler prefix must be a non-empty string\");\n }\n\n this.prefix = prefix;\n if (handler) this.handlerFn = handler;\n }\n\n addHandler(handler: (interaction: ModalInteraction<Context>) => Promise<any> | any): ModalHandler<Context> {\n this.handlerFn = handler;\n return this;\n }\n\n /**\n * Executes the modal handler\n */\n async execute(interaction: ModalInteraction<Context>): Promise<void> {\n if (!this.handlerFn) {\n throw new Error(`Modal handler with prefix \"${this.prefix}\" does not have a handler`);\n }\n await this.handlerFn(interaction);\n }\n\n /**\n * Checks if this handler matches the given custom ID\n */\n matches(customId: string): boolean {\n const prefix = parseCustomId(customId, true);\n return prefix === this.prefix;\n }\n}\n","import { Hono, type Context } from \"hono\";\nimport { APIWebhookEvent, ApplicationWebhookEventType, ApplicationWebhookType } from \"discord-api-types/v10\";\nimport type { APIWebhookEventPayload, WebhookEventHandlerFnForWorkers, WebhookEventHandlerFnWithRequest } from \"$types/webhook\";\nimport { verifyDiscordRequest } from \"@utils/discordVerify\";\n\ntype BlankVariables = Record<string, any>;\n\n/**\n * Represents a webhook event handler to be used by an Honocord instance or standalone fetch handler or Hono app.\n *\n * @template T - Discord webhook event type\n * @template Env - Environment bindings type\n * @template Variables - Additional context variables\n * @template ForWorker - Set to `true` for Cloudflare Workers mode (no return type required), `false` for standard mode (must return Response)\n * @template Data - Typed webhook event data\n */\nexport class WebhookEventHandler<\n T extends ApplicationWebhookEventType,\n Env extends { DISCORD_PUBLIC_KEY?: string } = {},\n Variables extends BlankVariables = BlankVariables,\n ForWorker extends boolean = false,\n Data extends APIWebhookEventPayload<T> = APIWebhookEventPayload<T>,\n> {\n readonly handlerType = \"webhook\";\n public readonly eventType: T;\n private handlerFn?: ForWorker extends true\n ? WebhookEventHandlerFnForWorkers<Data, Env, BlankVariables & { data: Data }>\n : WebhookEventHandlerFnWithRequest<Data, Env, BlankVariables & { data: Data }>;\n private app = new Hono<{ Bindings: Env; Variables: Omit<Variables, \"data\"> & { data: Data } }>();\n private isForWorker: boolean;\n\n constructor(eventType: T, forWorker?: ForWorker) {\n this.eventType = eventType;\n this.isForWorker = forWorker ?? false;\n }\n\n /**\n * Internal wrapper that handles Discord request verification and delegates to the user-defined handler.\n * This is used by the standalone `fetch` and `getApp()` methods.\n *\n * @private\n * @internal\n */\n private handlerWrapper = async (c: Context<{ Bindings: Env; Variables: BlankVariables & { data: Data } }>) => {\n if (!this.handlerFn) {\n console.error(\"No handler function defined for webhook event handler.\");\n return c.body(null, 500);\n } else if (!c.env.DISCORD_PUBLIC_KEY) {\n console.error(\"No Discord public key provided in environment variables.\");\n return c.body(null, 500);\n }\n\n // validate request body and type\n const { isValid, data } = await verifyDiscordRequest<APIWebhookEvent>(c.req, c.env.DISCORD_PUBLIC_KEY);\n if (!isValid || !data) {\n console.error(\"Invalid request signature or body.\");\n return c.body(null, 401);\n }\n\n if (data.type === ApplicationWebhookType.Ping) {\n return c.json({ type: ApplicationWebhookType.Ping }, 200);\n } else if (data.event.type !== this.eventType) {\n console.error(\n `Received event type ${data.event.type} does not match handler event type ${this.eventType}. How did this happen?`\n );\n return c.body(null, 400);\n }\n\n c.set(\"data\", data.event as Data);\n\n try {\n return await this.handlerFn(c);\n } catch (error) {\n console.error(\"Error executing webhook event handler:\", error);\n return c.body(null, 500);\n }\n };\n\n /**\n * Registers the handler function for this webhook event.\n *\n * @param handlerFn - The function to execute when this webhook event is received\n *\n * @example\n * Standard mode (must return Response):\n * ```typescript\n * const handler = new WebhookEventHandler(ApplicationWebhookEventType.MessageCreate);\n *\n * handler.addHandler(async (c) => {\n * const message = c.var.data;\n * console.log(\"Received message:\", message.content);\n * return c.json({ success: true }); // Must return Response\n * });\n * ```\n *\n * @example\n * Worker mode (no return required):\n * ```typescript\n * const handler = new WebhookEventHandler(ApplicationWebhookEventType.MessageCreate, true);\n *\n * handler.addHandler(async (c) => {\n * const message = c.var.data;\n * console.log(\"Received message:\", message.content);\n * // No return required in worker mode\n * });\n * ```\n */\n addHandler(\n handlerFn: ForWorker extends true\n ? WebhookEventHandlerFnForWorkers<Data, Env, BlankVariables & { data: Data }>\n : WebhookEventHandlerFnWithRequest<Data, Env, BlankVariables & { data: Data }>\n ) {\n this.handlerFn = handlerFn as any;\n if (!this.isForWorker) {\n this.app.post(\"/\", this.handlerWrapper);\n }\n return this;\n }\n\n /**\n * Execute the handler with pre-verified event data.\n *\n * **When to use:** This method is automatically called when the handler is registered with Honocord via `loadHandlers()`.\n * The Honocord instance handles request verification and ping events once, then delegates to this method.\n *\n * **You typically don't call this directly** - it's used internally by Honocord's `webhookHandler`.\n *\n * @param eventData - The pre-verified webhook event data\n * @param c - The Hono context\n * @returns The response from the handler function\n *\n * @example\n * ```typescript\n * // This is handled automatically when using Honocord:\n * const bot = new Honocord();\n * const handler = new WebhookEventHandler(ApplicationWebhookEventType.MessageCreate);\n * handler.addHandler(async (c) => c.json({ ok: true }));\n *\n * bot.loadHandlers(handler); // execute() is called internally\n * export default bot.getApp(); // POST /webhook\n * ```\n */\n async execute(eventData: Data, c: Context<{ Bindings: Env; Variables: BlankVariables & { data: Data } }>) {\n if (!this.handlerFn) {\n console.error(\"No handler function defined for webhook event handler.\");\n return c.body(null, 500);\n }\n\n c.set(\"data\", eventData);\n\n try {\n return await this.handlerFn(c);\n } catch (error) {\n console.error(\"Error executing webhook event handler:\", error);\n return c.body(null, 500);\n }\n }\n\n /**\n * Returns the fetch handler for standalone usage.\n *\n * **Note:** This method is only available in standard mode (`ForWorker = false`).\n * When using worker mode, this method returns `never` and will throw a runtime error.\n *\n * **When to use:** Use this when you want a self-contained webhook endpoint that handles its own\n * Discord request verification and ping events, independent of a Honocord instance.\n *\n * This is ideal for:\n * - Microservices architecture where webhooks are separate from interaction handlers\n * - Multiple bots with different webhook endpoints\n * - Testing individual webhook handlers in isolation\n * - Deploying webhooks on different paths or domains\n *\n * @returns A fetch-compatible handler function\n *\n * @example\n * ```typescript\n * import { Hono } from \"hono\";\n * import { WebhookEventHandler } from \"honocord/handlers\";\n * import { ApplicationWebhookEventType } from \"discord-api-types/v10\";\n *\n * const app = new Hono();\n *\n * // Standalone webhook handler with built-in verification\n * const messageHandler = new WebhookEventHandler(\n * ApplicationWebhookEventType.MessageCreate\n * );\n *\n * messageHandler.addHandler(async (c) => {\n * const message = c.var.data;\n * return c.json({ received: true });\n * });\n *\n * // Use as a standalone endpoint\n * app.post(\"/discord-webhook\", messageHandler.fetch);\n *\n * export default app;\n * ```\n */\n get fetch(): ForWorker extends true ? never : typeof this.app.fetch {\n if (this.isForWorker) {\n throw new Error(\n \"fetch() is not available when handler is configured for Cloudflare Workers mode. Use it with Honocord's webhookHandler instead.\"\n );\n }\n return this.app.fetch as any;\n }\n\n /**\n * Returns the internal Hono app for standalone usage.\n *\n * **Note:** This method is only available in standard mode (`ForWorker = false`).\n * When using worker mode, this method returns `never` and will throw a runtime error.\n *\n * **When to use:** Similar to `fetch`, but allows you to mount the handler on a route prefix.\n * This provides the same self-contained verification as `fetch`.\n *\n * @returns A Hono app instance\n *\n * @example\n * ```typescript\n * import { Hono } from \"hono\";\n * import { WebhookEventHandler } from \"honocord/handlers\";\n * import { ApplicationWebhookEventType } from \"discord-api-types/v10\";\n *\n * const app = new Hono();\n *\n * const messageHandler = new WebhookEventHandler(\n * ApplicationWebhookEventType.MessageCreate\n * );\n *\n * messageHandler.addHandler(async (c) => {\n * return c.json({ ok: true });\n * });\n *\n * // Mount on a prefix\n * app.route(\"/discord\", messageHandler.getApp());\n * // Available at POST /discord\n *\n * export default app;\n * ```\n */\n getApp(): ForWorker extends true ? never : typeof this.app {\n if (this.isForWorker) {\n throw new Error(\n \"getApp() is not available when handler is configured for Cloudflare Workers mode. Use it with Honocord's webhookHandler instead.\"\n );\n }\n return this.app as any;\n }\n}\n","import { APIMessage, InteractionType } from \"discord-api-types/v10\";\nimport { API } from \"@discordjs/core/http-only\";\nimport type { BaseInteractionContext, MessageComponentInteractionPayload, MessageComponentType } from \"../types\";\nimport { ModalCapableInteraction } from \"./ModalCapableInteraction\";\n\nabstract class MessageComponentInteraction<\n Context extends BaseInteractionContext = BaseInteractionContext,\n T extends MessageComponentType = MessageComponentType,\n> extends ModalCapableInteraction<InteractionType.MessageComponent, Context> {\n public readonly message: APIMessage;\n public readonly customId: string;\n public readonly componentType: T;\n\n constructor(api: API, interaction: MessageComponentInteractionPayload<T>, c: Context) {\n super(api, interaction, c);\n this.customId = interaction.data.custom_id;\n this.message = interaction.message;\n this.componentType = interaction.data.component_type as T;\n }\n}\n\nexport { MessageComponentInteraction };\n","import { ComponentType } from \"discord-api-types/v10\";\nimport { API } from \"@discordjs/core/http-only\";\nimport type { BaseInteractionContext, MessageComponentInteractionPayload } from \"../types\";\nimport { MessageComponentInteraction } from \"./MessageComponentInteraction\";\n\nclass ButtonInteraction<Context extends BaseInteractionContext = BaseInteractionContext> extends MessageComponentInteraction<\n Context,\n ComponentType.Button\n> {\n constructor(api: API, interaction: MessageComponentInteractionPayload<ComponentType.Button>, c: Context) {\n super(api, interaction, c);\n }\n}\n\nexport { ButtonInteraction };\n","import { ComponentType } from \"discord-api-types/v10\";\nimport { API } from \"@discordjs/core/http-only\";\nimport type { BaseInteractionContext, MessageComponentInteractionPayload } from \"../types\";\nimport { MessageComponentInteraction } from \"./MessageComponentInteraction\";\n\nclass StringSelectInteraction<\n Context extends BaseInteractionContext = BaseInteractionContext,\n> extends MessageComponentInteraction<Context, ComponentType.StringSelect> {\n public readonly values: string[];\n constructor(api: API, interaction: MessageComponentInteractionPayload<ComponentType.StringSelect>, c: Context) {\n super(api, interaction, c);\n this.values = interaction.data.values;\n }\n}\n\nexport { StringSelectInteraction };\n","import { APIUser, ComponentType } from \"discord-api-types/v10\";\nimport { API } from \"@discordjs/core/http-only\";\nimport type { BaseInteractionContext, MessageComponentInteractionPayload, ResolvedSelectedGuildMember } from \"../types\";\nimport { MessageComponentInteraction } from \"./MessageComponentInteraction\";\nimport { Collection } from \"@discordjs/collection\";\n\nclass UserSelectInteraction<Context extends BaseInteractionContext = BaseInteractionContext> extends MessageComponentInteraction<\n Context,\n ComponentType.UserSelect\n> {\n public readonly values: string[];\n public readonly users: Collection<string, APIUser>;\n public readonly members: Collection<string, ResolvedSelectedGuildMember> = new Collection();\n constructor(api: API, interaction: MessageComponentInteractionPayload<ComponentType.UserSelect>, c: Context) {\n super(api, interaction, c);\n this.values = interaction.data.values;\n this.users = new Collection(interaction.data.resolved.users ? Object.entries(interaction.data.resolved.users) : []);\n if (this.inGuild()) {\n this.members = new Collection(\n this.values\n .map((id) => {\n // We can technically assume that the member and user will always be present if the ID is in the values array, but we should still check just in case\n const member = interaction.data.resolved.members?.[id];\n if (member) {\n const user = this.users.get(id);\n if (user) {\n return [id, { ...member, user } as ResolvedSelectedGuildMember] as const;\n }\n }\n return null;\n })\n .filter((entry) => entry !== null)\n );\n }\n }\n}\n\nexport { UserSelectInteraction };\n","import { APIRole, ComponentType } from \"discord-api-types/v10\";\nimport { API } from \"@discordjs/core/http-only\";\nimport type { BaseInteractionContext, MessageComponentInteractionPayload } from \"../types\";\nimport { MessageComponentInteraction } from \"./MessageComponentInteraction\";\nimport { Collection } from \"@discordjs/collection\";\n\nclass RoleSelectInteraction<Context extends BaseInteractionContext = BaseInteractionContext> extends MessageComponentInteraction<\n Context,\n ComponentType.RoleSelect\n> {\n public readonly values: string[];\n public readonly roles: Collection<string, APIRole>;\n constructor(api: API, interaction: MessageComponentInteractionPayload<ComponentType.RoleSelect>, c: Context) {\n super(api, interaction, c);\n this.values = interaction.data.values;\n this.roles = new Collection(interaction.data.resolved.roles ? Object.entries(interaction.data.resolved.roles) : []);\n }\n}\n\nexport { RoleSelectInteraction };\n","import { APIRole, APIUser, ComponentType } from \"discord-api-types/v10\";\nimport { API } from \"@discordjs/core/http-only\";\nimport type { BaseInteractionContext, MessageComponentInteractionPayload } from \"../types\";\nimport { MessageComponentInteraction } from \"./MessageComponentInteraction\";\nimport { Collection } from \"@discordjs/collection\";\n\nclass MentionableSelectInteraction<\n Context extends BaseInteractionContext = BaseInteractionContext,\n> extends MessageComponentInteraction<Context, ComponentType.MentionableSelect> {\n public readonly values: string[];\n public readonly roles: Collection<string, APIRole>;\n public readonly users: Collection<string, APIUser>;\n constructor(api: API, interaction: MessageComponentInteractionPayload<ComponentType.MentionableSelect>, c: Context) {\n super(api, interaction, c);\n this.values = interaction.data.values;\n this.roles = new Collection(interaction.data.resolved.roles ? Object.entries(interaction.data.resolved.roles) : []);\n this.users = new Collection(interaction.data.resolved.users ? Object.entries(interaction.data.resolved.users) : []);\n }\n}\n\nexport { MentionableSelectInteraction };\n","import { APIInteractionDataResolvedChannel, ComponentType } from \"discord-api-types/v10\";\nimport { API } from \"@discordjs/core/http-only\";\nimport type { BaseInteractionContext, MessageComponentInteractionPayload } from \"../types\";\nimport { MessageComponentInteraction } from \"./MessageComponentInteraction\";\nimport { Collection } from \"@discordjs/collection\";\n\nclass ChannelSelectInteraction<\n Context extends BaseInteractionContext = BaseInteractionContext,\n> extends MessageComponentInteraction<Context, ComponentType.ChannelSelect> {\n public readonly values: string[];\n public readonly channels: Collection<string, APIInteractionDataResolvedChannel>;\n constructor(api: API, interaction: MessageComponentInteractionPayload<ComponentType.ChannelSelect>, c: Context) {\n super(api, interaction, c);\n this.values = interaction.data.values;\n this.channels = new Collection(interaction.data.resolved.channels ? Object.entries(interaction.data.resolved.channels) : []);\n }\n}\n\nexport { ChannelSelectInteraction };\n","import {\n APIInteractionDataResolved,\n APIMessageApplicationCommandInteractionDataResolved,\n APIUserInteractionDataResolved,\n ApplicationCommandType,\n ChannelType,\n ComponentType,\n InteractionType,\n type APIGuild,\n type APIRole,\n type APIUser,\n} from \"discord-api-types/v10\";\nimport type { BaseCacheAdapter } from \"@honocord/cache-base\";\nimport { ValidInteraction } from \"$types/interactions\";\nimport { CachedChannel, CachedGuildMember, CacheNamespace, MemberNamespaceAccessor, NamespaceAccessor } from \"$types/caching\";\n\nfunction key(ns: CacheNamespace, ...parts: string[]): string {\n return `${ns}:${parts.join(\":\")}`;\n}\n\nexport class CacheManager {\n readonly channels: NamespaceAccessor<CachedChannel>;\n readonly roles: NamespaceAccessor<APIRole>;\n readonly users: NamespaceAccessor<APIUser>;\n readonly guilds: NamespaceAccessor<APIGuild>;\n readonly members: MemberNamespaceAccessor;\n\n constructor(\n private adapter: BaseCacheAdapter,\n private defaultTtlMs: number = 5 * 60 * 1000 /* 5 minutes */\n ) {\n this.channels = {\n get: (id) => this.adapter.get<CachedChannel>(key(\"channel\", id)),\n set: (channel, ttlMs) => this.adapter.set(key(\"channel\", channel.id), channel, ttlMs ?? this.defaultTtlMs),\n delete: (id) => this.adapter.delete(key(\"channel\", id)),\n has: (id) => this.adapter.has(key(\"channel\", id)),\n mset: (entries) => this.adapter.mset(entries.map((e) => ({ ...e, key: key(\"channel\", e.value.id) }))),\n };\n\n this.roles = {\n get: (id) => this.adapter.get<APIRole>(key(\"role\", id)),\n set: (role, ttlMs) => this.adapter.set(key(\"role\", role.id), role, ttlMs ?? this.defaultTtlMs),\n delete: (id) => this.adapter.delete(key(\"role\", id)),\n has: (id) => this.adapter.has(key(\"role\", id)),\n mset: (entries) => this.adapter.mset(entries.map((e) => ({ ...e, key: key(\"role\", e.value.id) }))),\n };\n\n this.users = {\n get: (id) => this.adapter.get<APIUser>(key(\"user\", id)),\n set: (user, ttlMs) => this.adapter.set(key(\"user\", user.id), user, ttlMs ?? this.defaultTtlMs),\n delete: (id) => this.adapter.delete(key(\"user\", id)),\n has: (id) => this.adapter.has(key(\"user\", id)),\n mset: (entries) => this.adapter.mset(entries.map((e) => ({ ...e, key: key(\"user\", e.value.id) }))),\n };\n\n this.guilds = {\n get: (id) => this.adapter.get<APIGuild>(key(\"guild\", id)),\n set: (guild, ttlMs) => this.adapter.set(key(\"guild\", guild.id), guild, ttlMs ?? this.defaultTtlMs),\n delete: (id) => this.adapter.delete(key(\"guild\", id)),\n has: (id) => this.adapter.has(key(\"guild\", id)),\n mset: (entries) => this.adapter.mset(entries.map((e) => ({ ...e, key: key(\"guild\", e.value.id) }))),\n };\n\n // Members are guild-scoped: key = \"member:{guildId}:{userId}\"\n this.members = {\n get: (guildId, userId) => this.adapter.get<CachedGuildMember>(key(\"member\", guildId, userId)),\n set: (guildId, member, ttlMs) =>\n this.adapter.set(key(\"member\", guildId, member.user!.id), member, ttlMs ?? this.defaultTtlMs),\n delete: (guildId, userId) => this.adapter.delete(key(\"member\", guildId, userId)),\n has: (guildId, userId) => this.adapter.has(key(\"member\", guildId, userId)),\n mset: (guildId, entries) => this.adapter.mset(entries.map((e) => ({ ...e, key: key(\"member\", guildId, e.value.user.id) }))),\n };\n }\n\n async getGuildRoles(guildId: string): Promise<APIRole[]> {\n const roleIds = await this.adapter.get<string[]>(key(\"guild-roles\", guildId));\n if (!roleIds) return [];\n const roles = await Promise.all(roleIds.map((roleId) => this.roles.get(roleId)));\n return roles.filter(Boolean) as APIRole[];\n }\n\n private async addRolesToGuild(guildId: string, roleIds: string[]): Promise<void> {\n if (!roleIds.length) return;\n const existing = (await this.adapter.get<string[]>(key(\"guild-roles\", guildId))) ?? [];\n const toAdd = roleIds.filter((id) => !existing.includes(id));\n if (toAdd.length) {\n await this.adapter.set(key(\"guild-roles\", guildId), [...existing, ...toAdd], this.defaultTtlMs);\n }\n }\n\n populate(i: ValidInteraction) {\n switch (i.type) {\n case InteractionType.ApplicationCommand: // Chat Input Command\n return this.populateCommand(i);\n case InteractionType.MessageComponent: // Message Component\n return this.populateMessageComponent(i);\n case InteractionType.ModalSubmit: // Modal Submit\n if (i.data.resolved) {\n return this.populateResolved(i.data.resolved, i.guild_id);\n }\n break;\n default:\n break;\n }\n return Promise.resolve();\n }\n\n private async populateResolved(\n resolved: APIInteractionDataResolved | APIUserInteractionDataResolved | APIMessageApplicationCommandInteractionDataResolved,\n guildId?: string\n ) {\n if (resolved) {\n // channels can't be used as the partial objects are only ID and type\n if (\"users\" in resolved && resolved.users) {\n await this.users.mset(Object.values(resolved.users).map((user) => ({ value: user })));\n }\n if (\"roles\" in resolved && resolved.roles) {\n const roles = Object.values(resolved.roles);\n await this.roles.mset(roles.map((role) => ({ value: role })));\n if (guildId) {\n await this.addRolesToGuild(\n guildId,\n roles.map((r) => r.id)\n );\n }\n }\n if (\"members\" in resolved && resolved.members && guildId) {\n // We need the guildId to cache members, but it's not included in the resolved data. We can only cache the member if we also have the user object, which includes the ID.\n const entries = Object.entries(resolved.members).flatMap(([userId, member]) => {\n const user = resolved.users?.[userId];\n return user ? [{ value: { ...member, user } }] : [];\n });\n if (entries.length) {\n await this.members.mset(guildId, entries);\n }\n }\n }\n }\n\n private async populateCommand(i: Extract<ValidInteraction, { type: InteractionType.ApplicationCommand }>) {\n if (i.data.type === ApplicationCommandType.PrimaryEntryPoint) return; // Doesnt have any data\n\n // i.guild is somehow only the APIPartialInteractionGuild which only carries id, features and preferred_locale/locale (buggy)\n\n if (i.data.resolved) {\n await this.populateResolved(i.data.resolved, i.guild_id);\n }\n\n if (i.user) {\n await this.users.set(i.user);\n }\n if (i.member && i.guild_id) {\n await this.users.set(i.member.user);\n await this.members.set(i.guild_id, i.member);\n }\n if (i.channel) {\n await this.channels.set(i.channel as CachedChannel);\n }\n }\n\n private async populateMessageComponent(i: Extract<ValidInteraction, { type: InteractionType.MessageComponent }>) {\n if (i.channel) {\n await this.channels.set(i.channel as CachedChannel);\n }\n\n if (i.user) {\n await this.users.set(i.user);\n }\n if (i.member && i.guild_id) {\n await this.users.set(i.member.user);\n await this.members.set(i.guild_id, i.member);\n }\n\n if (\n i.data.component_type !== ComponentType.Button &&\n i.data.component_type !== ComponentType.StringSelect &&\n \"resolved\" in i.data &&\n i.data.resolved\n ) {\n const resolved = i.data.resolved;\n if (\"users\" in resolved && resolved.users) {\n await this.users.mset(Object.values(resolved.users).map((user) => ({ value: user })));\n }\n if (\"roles\" in resolved && resolved.roles) {\n await this.roles.mset(Object.values(resolved.roles).map((role) => ({ value: role })));\n }\n if (\"members\" in resolved && resolved.members && i.guild_id) {\n const resolvedUsers = \"users\" in resolved ? resolved.users : undefined;\n const entries = Object.entries(resolved.members).flatMap(([userId, member]) => {\n const user = resolvedUsers?.[userId];\n return user ? [{ value: { ...member, user } }] : [];\n });\n if (entries.length) {\n await this.members.mset(i.guild_id, entries);\n }\n }\n }\n }\n}\n","import {\n APIApplicationCommandAutocompleteInteraction,\n APIApplicationCommandInteraction,\n APIInteraction,\n APIWebhookEvent,\n ApplicationCommandType,\n ApplicationWebhookType,\n ComponentType,\n InteractionResponseType,\n InteractionType,\n} from \"discord-api-types/v10\";\nimport { ChatInputCommandInteraction } from \"@ctx/ChatInputInteraction\";\nimport { API } from \"@discordjs/core/http-only\";\nimport { REST } from \"@discordjs/rest\";\nimport { Context, Hono } from \"hono\";\nimport { verifyDiscordRequest } from \"@utils/discordVerify\";\nimport { parseCustomId } from \"@utils/index\";\nimport type {\n BaseVariables,\n BaseInteractionContext,\n ValidInteraction,\n MessageComponentInteractionPayload,\n MessageComponentType,\n FlatOrNestedArray,\n MiddlewareFunction,\n ApplicationWebhookEventType,\n} from \"$types/index\";\nimport { UserContextInteraction } from \"@ctx/UserContextCommandInteraction\";\nimport { MessageContextInteraction } from \"@ctx/MessageContextCommandInteraction\";\nimport { ModalInteraction } from \"@ctx/ModalInteraction\";\nimport { AutocompleteInteraction } from \"@ctx/AutocompleteInteraction\";\nimport {\n SlashCommandHandler,\n ContextCommandHandler,\n ComponentHandler,\n ModalHandler,\n type Handler,\n type AnyHandler,\n WebhookEventHandler,\n} from \"@handlers/index\";\nimport { ButtonInteraction } from \"@ctx/ButtonInteraction\";\nimport { StringSelectInteraction } from \"@ctx/StringSelectInteraction\";\nimport { UserSelectInteraction } from \"@ctx/UserSelectInteraction\";\nimport { RoleSelectInteraction } from \"@ctx/RoleSelectInteraction\";\nimport { MentionableSelectInteraction } from \"@ctx/MentionableSelectInteraction\";\nimport { ChannelSelectInteraction } from \"@ctx/ChannelSelectInteraction\";\nimport { BaseCacheAdapter, NullCacheAdapter } from \"@honocord/cache-base\";\nimport { CacheManager } from \"@utils/CacheManager\";\n\ninterface HonocordOptions {\n /**\n * Indicates whether the Honocord instance is running on Cloudflare Workers.\n *\n * This affects how interactions are processed, allowing for asynchronous handling using the Workers' execution context.\n *\n * @default c.env.IS_CF_WORKER === \"true\" # later determined from environment variable\n */\n isCFWorker?: boolean;\n /**\n * Whether to turn on debug logging for REST API requests.\n *\n * @default false\n */\n debugRest?: boolean;\n /**\n * Default TTL (in MILLISECONDS) for cached entities when a cache adapter is registered via `withCache`.\n *\n * Set `0` to disable expiration.\n */\n cacheTtlMs?: number;\n}\n\ninterface HonocordAppOptions {\n interactionsPath?: `/${string}`;\n webhookPath?: `/${string}`;\n}\n\nexport class Honocord {\n /**\n * Map of commandName to CommandHandler instances for global commands.\n */\n private globalCommandHandlers = new Map<string, SlashCommandHandler | ContextCommandHandler>();\n /**\n * Map of `guildId:commandName` to CommandHandler instances for guild-specific commands.\n */\n private guildCommandHandlers = new Map<string, SlashCommandHandler | ContextCommandHandler>();\n private componentHandlers = new Map<string, ComponentHandler>();\n private modalHandlers = new Map<string, ModalHandler>();\n private middleware = new Array<MiddlewareFunction<any>>();\n private webhookHandlers = new Map<ApplicationWebhookEventType, WebhookEventHandler<any>>();\n private isCFWorker: boolean;\n private debugRest: boolean;\n private _cacheAdapterFactory: (env: any) => BaseCacheAdapter = () => new NullCacheAdapter();\n private _cacheManager: CacheManager | null = null;\n private _defaultCacheTtlMs: number | undefined = undefined; // ← add this\n\n /**\n * Executes all registered middleware in sequence.\n *\n * @param ctx - The interaction context\n * @param finalHandler - The final handler to execute after all middleware\n */\n private async runMiddleware(ctx: BaseInteractionContext, finalHandler: () => Promise<void>): Promise<void> {\n if (this.middleware.length === 0) {\n return await finalHandler();\n }\n\n /**\n * Executes the next middleware in the chain.\n */\n const dispatch = async (i: number = 0): Promise<void> => {\n if (i >= this.middleware.length) {\n return await finalHandler();\n }\n\n await this.middleware[i](ctx, () => dispatch(i + 1));\n };\n\n await dispatch();\n }\n\n constructor({ isCFWorker, debugRest }: HonocordOptions = {}) {\n this.isCFWorker = isCFWorker ?? false;\n this.debugRest = debugRest ?? false;\n }\n\n /**\n * Registers handlers for interactions.\n *\n * @param handlers - Array of CommandHandler, ComponentHandler, or ModalHandler instances\n *\n * For an example of usage, see the [Example Repository](https://github.com/The-LukeZ/honocord-examples).\n */\n loadHandlers(...handlers: FlatOrNestedArray<AnyHandler>): void {\n const flattenedHandlers = handlers.flat(Infinity) as Handler[];\n\n for (const handler of flattenedHandlers) {\n if (handler instanceof SlashCommandHandler || handler instanceof ContextCommandHandler) {\n if (handler.isGuildCommand()) {\n for (const guildId of handler.guildIds.values()) {\n const key = `${guildId}:${handler.name}`;\n if (this.guildCommandHandlers.has(key)) {\n console.warn(`Guild command handler for \"${handler.name}\" in guild \"${guildId}\" already exists. Overwriting.`);\n }\n this.guildCommandHandlers.set(key, handler as SlashCommandHandler | ContextCommandHandler);\n }\n continue;\n }\n\n if (this.globalCommandHandlers.has(handler.name)) {\n console.warn(`Command handler for \"${handler.name}\" already exists. Overwriting.`);\n }\n this.globalCommandHandlers.set(handler.name, handler as SlashCommandHandler | ContextCommandHandler);\n } else if (handler instanceof ComponentHandler) {\n const prefix = handler.prefix;\n if (this.componentHandlers.has(prefix)) {\n console.warn(`Component handler with prefix \"${prefix}\" already exists. Overwriting.`);\n }\n this.componentHandlers.set(prefix, handler as ComponentHandler<any>);\n } else if (handler instanceof ModalHandler) {\n const prefix = handler.prefix;\n if (this.modalHandlers.has(prefix)) {\n console.warn(`Modal handler with prefix \"${prefix}\" already exists. Overwriting.`);\n }\n this.modalHandlers.set(prefix, handler);\n } else if (handler instanceof WebhookEventHandler) {\n if (this.webhookHandlers.has(handler.eventType)) {\n console.warn(`Webhook handler for event type \"${handler.eventType}\" already exists. Overwriting.`);\n }\n this.webhookHandlers.set(handler.eventType, handler);\n }\n }\n }\n\n private createCommandInteraction(ctx: BaseInteractionContext, interaction: APIApplicationCommandInteraction, api: API) {\n switch (interaction.data.type) {\n case ApplicationCommandType.ChatInput:\n return new ChatInputCommandInteraction(api, interaction as any, ctx);\n case ApplicationCommandType.User:\n return new UserContextInteraction(api, interaction as any, ctx);\n case ApplicationCommandType.Message:\n return new MessageContextInteraction(api, interaction as any, ctx);\n default:\n throw new Error(\n `Unsupported application command type: ${interaction.data.type} (${ApplicationCommandType[interaction.data.type]})`\n );\n }\n }\n\n private executeCommandHandler(\n handler: SlashCommandHandler | ContextCommandHandler,\n interactionObj: ReturnType<typeof this.createCommandInteraction>,\n commandType: ApplicationCommandType\n ) {\n if (handler instanceof SlashCommandHandler && commandType === ApplicationCommandType.ChatInput) {\n return handler.execute(interactionObj as ChatInputCommandInteraction);\n } else if (handler instanceof ContextCommandHandler) {\n if (commandType === ApplicationCommandType.User) {\n return handler.execute(interactionObj as UserContextInteraction);\n } else if (commandType === ApplicationCommandType.Message) {\n return handler.execute(interactionObj as MessageContextInteraction);\n }\n }\n }\n\n private async handleCommandInteraction(ctx: BaseInteractionContext, interaction: APIApplicationCommandInteraction, api: API) {\n const interactionObj = this.createCommandInteraction(ctx, interaction, api);\n const commandName = interaction.data.name;\n const handler = this.globalCommandHandlers.get(commandName);\n\n // Store interaction in context for middleware access\n ctx.set(\"command\", interactionObj as any);\n\n await this.runMiddleware(ctx, async () => {\n if (handler) {\n try {\n await this.executeCommandHandler(handler, interactionObj, interaction.data.type);\n } catch (error) {\n console.error(`Error executing command handler for \"${commandName}\"`, error);\n throw error;\n }\n }\n\n // Could be a guild command\n const guildId = interaction.guild_id;\n if (guildId) {\n const key = `${guildId}:${commandName}`;\n const guildHandler = this.guildCommandHandlers.get(key);\n if (guildHandler) {\n try {\n await this.executeCommandHandler(guildHandler, interactionObj, interaction.data.type);\n } catch (error) {\n console.error(`Error executing guild command handler for \"${commandName}\" in guild \"${guildId}\"`, error);\n throw error;\n }\n }\n }\n });\n\n return interactionObj;\n }\n\n private async handleAutocompleteInteraction(\n ctx: BaseInteractionContext,\n interaction: APIApplicationCommandAutocompleteInteraction,\n api: API\n ) {\n const interactionObj = new AutocompleteInteraction(api, interaction, ctx);\n const commandName = interaction.data.name;\n const handler = this.globalCommandHandlers.get(commandName);\n\n // Store interaction in context for middleware access\n ctx.set(\"autocomplete\", interactionObj as any);\n\n await this.runMiddleware(ctx, async () => {\n if (handler && handler instanceof SlashCommandHandler) {\n try {\n await handler.executeAutocomplete(interactionObj);\n } catch (error) {\n console.error(`Error executing autocomplete handler for \"${commandName}\"`, error);\n throw error;\n }\n }\n\n // Could be a guild command\n const guildId = interaction.guild_id;\n if (guildId) {\n const key = `${guildId}:${commandName}`;\n const guildHandler = this.guildCommandHandlers.get(key);\n if (guildHandler && guildHandler instanceof SlashCommandHandler) {\n try {\n await guildHandler.executeAutocomplete(interactionObj);\n } catch (error) {\n console.error(`Error executing guild autocomplete handler for \"${commandName}\" in guild \"${guildId}\"`, error);\n throw error;\n }\n }\n }\n });\n }\n\n private createMessageComponentInteraction<T extends MessageComponentType>(\n ctx: BaseInteractionContext,\n interactionObj: MessageComponentInteractionPayload<T>,\n api: API\n ) {\n switch (interactionObj.data.component_type) {\n case ComponentType.Button:\n return new ButtonInteraction(api, interactionObj as any, ctx);\n case ComponentType.StringSelect:\n return new StringSelectInteraction(api, interactionObj as any, ctx);\n case ComponentType.UserSelect:\n return new UserSelectInteraction(api, interactionObj as any, ctx);\n case ComponentType.RoleSelect:\n return new RoleSelectInteraction(api, interactionObj as any, ctx);\n case ComponentType.MentionableSelect:\n return new MentionableSelectInteraction(api, interactionObj as any, ctx);\n case ComponentType.ChannelSelect:\n return new ChannelSelectInteraction(api, interactionObj as any, ctx);\n default:\n throw new Error(`Unsupported message component type: ${(interactionObj.data as any).component_type}`);\n }\n }\n\n private async handleComponentInteraction<T extends MessageComponentType>(\n ctx: BaseInteractionContext,\n interaction: MessageComponentInteractionPayload<T>,\n api: API\n ) {\n const interactionObj = this.createMessageComponentInteraction(ctx, interaction, api);\n const prefix = parseCustomId(interaction.data.custom_id, true);\n\n // Store interaction in context for middleware access\n ctx.set(\"component\", interactionObj as any);\n\n await this.runMiddleware(ctx, async () => {\n // Lookup handler by prefix\n const handler = this.componentHandlers.get(prefix);\n if (handler?.componentType === interaction.data.component_type) {\n try {\n await handler.execute(interactionObj);\n } catch (error) {\n console.error(`Error executing component handler for prefix \"${prefix}\"`, error);\n throw error;\n }\n } else {\n throw new Error(\n `No component handler found for prefix \"${prefix}\" and component type \"${interaction.data.component_type}\"`\n );\n }\n });\n\n return interactionObj;\n }\n\n private async handleModalInteraction(\n ctx: BaseInteractionContext,\n interaction: Extract<ValidInteraction, { type: InteractionType.ModalSubmit }>,\n api: API\n ) {\n const interactionObj = new ModalInteraction(api, interaction, ctx);\n const customId = interaction.data.custom_id;\n const prefix = parseCustomId(customId, true);\n\n // Store interaction in context for middleware access\n ctx.set(\"modal\", interactionObj);\n\n await this.runMiddleware(ctx, async () => {\n // Lookup handler by prefix\n const handler = this.modalHandlers.get(prefix);\n\n if (handler) {\n try {\n await handler.execute(interactionObj);\n } catch (error) {\n console.error(`Error executing modal handler for prefix \"${prefix}\"`, error);\n throw error;\n }\n }\n });\n\n return interactionObj;\n }\n\n private async createInteraction(ctx: BaseInteractionContext, interaction: ValidInteraction) {\n const cache = this._getCacheManager(ctx.env);\n if (this._cacheManager) {\n // TODO: Find out what performance impact this has\n await cache.populate(interaction as ValidInteraction);\n }\n ctx.set(\"cache\", cache);\n\n const rest = new REST({ authPrefix: \"Bot\" }).setToken(ctx.env.DISCORD_TOKEN as string);\n if (this.debugRest) {\n rest\n .addListener(\"response\", (request, response) => {\n console.debug(\n `[REST] ${request.method} ${request.path} -> ${response.status} ${response.statusText} (${request.route})`\n );\n })\n .addListener(\"restDebug\", (info) => {\n console.debug(`[REST DEBUG] ${info}`);\n });\n }\n const api = new API(rest);\n\n switch (interaction.type) {\n case InteractionType.ApplicationCommand:\n return await this.handleCommandInteraction(ctx, interaction, api);\n case InteractionType.MessageComponent:\n return await this.handleComponentInteraction(ctx, interaction, api);\n case InteractionType.ModalSubmit:\n return await this.handleModalInteraction(ctx, interaction, api);\n case InteractionType.ApplicationCommandAutocomplete:\n return await this.handleAutocompleteInteraction(ctx, interaction, api);\n default:\n throw new Error(`Unknown interaction type: ${(interaction as any).type} (${InteractionType[(interaction as any).type]})`);\n }\n }\n\n /**\n * Returns a Hono handler for POST Requests handling Discord interactions.\n *\n * @example\n * ```typescript\n * import { Hono } from \"hono\";\n * import { Honocord } from \"honocord\";\n *\n * const app = new Hono();\n * const bot = new Honocord();\n *\n * app.get(\"/\", (c) => c.text(\"🔥 Honocord is running!\"));\n * app.post(\"/interactions\", bot.interactionsHandler);\n *\n * export default app;\n * ```\n */\n interactionsHandler = async (c: BaseInteractionContext) => {\n // Check if running on CF Workers\n const isCFWorker = this.isCFWorker || c.env.IS_CF_WORKER === \"true\";\n\n // Verify the request\n const { isValid, data: interaction } = await verifyDiscordRequest<APIInteraction>(c.req, c.env.DISCORD_PUBLIC_KEY as string);\n if (!isValid) {\n return c.text(\"Bad request signature.\", 401);\n } else if (!interaction) {\n console.log(\"No interaction found in request\");\n return c.text(\"No interaction found.\", 400);\n }\n\n if (interaction.type === InteractionType.Ping) {\n console.log(\"Received Discord Ping\");\n return c.json({ type: InteractionResponseType.Pong });\n }\n\n // Handle CF Workers execution context\n if (isCFWorker && c.executionCtx?.waitUntil) {\n // Process interaction asynchronously\n c.executionCtx.waitUntil(\n new Promise(async (resolve) => {\n try {\n await this.createInteraction(c, interaction);\n } catch (error) {\n console.error(\"Error handling interaction:\", error);\n }\n resolve(undefined);\n })\n );\n return c.json({}, 202); // Accepted for processing\n }\n\n // Standard non-CF Workers execution\n try {\n await this.createInteraction(c, interaction);\n } catch (error) {\n console.error(\"Error handling interaction:\", error);\n return c.text(\"Internal server error.\", 500);\n }\n };\n\n /**\n * Returns a Hono App instance with the interaction handler mounted at the root path and a GET Handler for all paths, which returns a simple Health response.\n *\n * @example\n * ```typescript\n * import { Honocord } from \"honocord\";\n *\n * const honoCord = new Honocord();\n *\n * export default honoCord.getApp();\n * // Supports both \"/\" and \"/interactions\" for the interactions handler, if any are loaded\n * // And `/webhook` for the webhook handler if any are loaded\n * ```\n */\n getApp(options: HonocordAppOptions = {}) {\n options = {\n interactionsPath: \"/interactions\",\n webhookPath: \"/webhook\",\n ...options,\n };\n const app = new Hono<{ Variables: BaseVariables }>();\n app.get(\"*\", (c) => c.text(\"🔥 Honocord is running!\"));\n if (this.globalCommandHandlers.size > 0 || this.guildCommandHandlers.size > 0) {\n app.post(\"/\", this.interactionsHandler);\n app.post(options.interactionsPath || \"/interactions\", this.interactionsHandler);\n }\n if (this.webhookHandlers.size > 0) app.post(options.webhookPath || \"/webhook\", this.webhookHandler);\n return app;\n }\n\n /**\n * Registers a middleware function to process interaction contexts.\n *\n * Middleware receives the Hono context and a `next` callback:\n * - Access/modify context variables via `c.get()` and `c.set()`\n * - Access the interaction object via `c.var.command`, `c.var.component`, `c.var.modal`, or `c.var.autocomplete`\n * - Access environment bindings via `c.env`\n * - Call `await next()` to continue to the next middleware or handler\n *\n * The context is passed by reference, so all modifications persist through the middleware chain and into handlers.\n *\n * @example\n * ```typescript\n * bot.use(async (c, next) => {\n * // Set custom data in context\n * c.set('startTime', Date.now());\n *\n * // Continue to next middleware/handler\n * // you can also return next() directly if no post-processing is needed\n * await next();\n *\n * // Code here runs after the handler completes\n * console.log('Duration:', Date.now() - c.get('startTime'));\n * });\n * ```\n *\n * @param middleware - The middleware function(s) to register.\n * @returns The Honocord instance for chaining.\n */\n use<Context extends BaseInteractionContext = BaseInteractionContext>(...middleware: MiddlewareFunction<Context>[]): this {\n this.middleware.push(...middleware);\n return this;\n }\n\n /**\n * Returns a Hono handler for POST requests handling Discord webhook events.\n *\n * On Cloudflare Workers, webhook events are processed asynchronously using `waitUntil`,\n * allowing immediate response to Discord while extending the worker's lifetime to complete processing.\n *\n * @example\n * ```typescript\n * import { Hono } from \"hono\";\n * import { Honocord } from \"honocord\";\n *\n * const app = new Hono();\n * const bot = new Honocord();\n *\n * app.post(\"/webhook\", bot.webhookHandler);\n *\n * export default app;\n * ```\n */\n webhookHandler = async (c: Context) => {\n const isCFWorker = this.isCFWorker || c.env.IS_CF_WORKER === \"true\";\n\n if (typeof c.env.DISCORD_PUBLIC_KEY !== \"string\") {\n console.error(\"No Discord public key provided in environment variables.\");\n return c.body(null, 500);\n }\n const { isValid, data } = await verifyDiscordRequest<APIWebhookEvent>(c.req, c.env.DISCORD_PUBLIC_KEY);\n\n if (!isValid || !data) {\n return c.text(\"Bad request signature.\", 401);\n }\n\n if (data.type === ApplicationWebhookType.Ping) {\n return c.json({ type: ApplicationWebhookType.Ping }, 200);\n }\n\n const handler = this.webhookHandlers.get(data.event.type);\n if (!handler) {\n return c.text(\"No handler found for this event type.\", 404);\n }\n\n // CF Workers async processing\n if (isCFWorker && c.executionCtx?.waitUntil) {\n c.executionCtx.waitUntil(\n new Promise(async (resolve) => {\n try {\n await handler.execute(data.event, c);\n } catch (error) {\n console.error(`Error handling webhook event ${data.event.type}:`, error);\n }\n resolve(undefined);\n })\n );\n return c.json({ ok: true }, 200);\n }\n\n // Standard execution for other platforms\n return handler.execute(data.event, c);\n };\n\n /**\n * Registers a cache adapter factory for use throughout the bot.\n * The factory receives the request environment and returns a `BaseCacheAdapter` instance.\n *\n * On Cloudflare Workers, use `DurableObjectCacheAdapter`.\n * On self-hosted environments, use `MemoryCacheAdapter`, `MongoCacheAdapter`, or `RedisAdapter`.\n *\n * @example\n * ```typescript\n * // Cloudflare Workers\n * bot.withCache((env) => new DurableObjectCacheAdapter(env.MY_CACHE));\n *\n * // Self-hosted (pre-initialized)\n * const cache = new MongoCacheAdapter(process.env.MONGO_URI!);\n * await cache.connect();\n * bot.withCache(() => cache);\n * ```\n *\n * @param factory - A function that receives the environment and returns a cache adapter.\n * @returns The Honocord instance for chaining.\n */\n withCache<TheEnv = any>(factory: (env: TheEnv) => BaseCacheAdapter): this {\n this._cacheAdapterFactory = factory;\n this._cacheManager = null; // Reset cache manager to ensure new factory is used\n return this;\n }\n\n /**\n * Returns the cache manager for the given environment.\n * If no cache manager exists for the environment, a new one is created.\n * @param env - The environment to get the cache manager for.\n * @returns The cache manager for the given environment.\n */\n private _getCacheManager(env: unknown): CacheManager {\n if (!this._cacheManager) {\n this._cacheManager = new CacheManager(this._cacheAdapterFactory(env), this._defaultCacheTtlMs);\n }\n return this._cacheManager;\n }\n\n /**\n * Clears all registered middleware functions.\n * @returns The Honocord instance for chaining.\n */\n clearMiddleware(): this {\n this.middleware = [];\n return this;\n }\n}\n","import { ApplicationCommandType } from \"discord-api-types/v10\";\n\nexport enum ContextCommandType {\n User = ApplicationCommandType.User,\n Message = ApplicationCommandType.Message,\n}\n"],"mappings":";;;;;;;;;;;;;;AAoCA,IAAM,mCAAN,MAAuC;;;;CAIrC,AAAQ,SAAwB;;;;CAIhC,AAAQ,cAA6B;;;;;CAKrC,AAAQ;CAIR,AAAQ;CAER,YACE,SAKA,UACA;AACA,OAAK,kBAAkB,WAAW,EAAE;AACpC,OAAK,YAAY,OAAO,KAAK,YAAY,EAAE,CAAC,CAAC,QAAQ,KAAK,UAAQ;GAChE,MAAM,eAAe,WAAWA;AAChC,OAAIA,UAAQ,WAAW;IAErB,MAAM,QAAQ,UAAU,QAAQ,IAAIC,iCAAW,OA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AO,YAAY;AAC7B,QAAI;AACF,WAAM,QAAQ,QAAQ,KAAK,OAAO,EAAE;aAC7B,OAAO;AACd,aAAQ,MAAM,gCAAgC,KAAK,MAAM,KAAK,IAAI,MAAM;;AAE1E,YAAQ,OAAU;KAClB,CACH;AACD,UAAO,EAAE,KAAK,EAAE,IAAI,MAAM,EAAE,IAAI;;AAIlC,SAAO,QAAQ,QAAQ,KAAK,OAAO,EAAE;;;;;;;;;;;;;;;;;;;;;;;CAwBvC,UAAwB,SAAkD;AACxE,OAAK,uBAAuB;AAC5B,OAAK,gBAAgB;AACrB,SAAO;;;;;;;;CAST,AAAQ,iBAAiB,KAA4B;AACnD,MAAI,CAAC,KAAK,cACR,MAAK,gBAAgB,IAAI,aAAa,KAAK,qBAAqB,IAAI,EAAE,KAAK,mBAAmB;AAEhG,SAAO,KAAK;;;;;;CAOd,kBAAwB;AACtB,OAAK,aAAa,EAAE;AACpB,SAAO;;;;;;ACpnBX,IAAY,oEAAL;AACL,qDAAOC,6CAAuB;AAC9B,wDAAUA,6CAAuB"}
1
+ {"version":3,"file":"index.cjs","names":["key","Collection","ApplicationCommandOptionType","key","key","InteractionType","ApplicationCommandType","ComponentType","ModalBuilder","API","REST","key","Collection","ComponentType","SlashCommandBuilder","ContextMenuCommandBuilder","Hono","ApplicationWebhookType","Collection","Collection","Collection","Collection","ChannelType","InteractionType","ApplicationCommandType","ComponentType","NullCacheAdapter","key","ApplicationCommandType","ComponentType","REST","API","InteractionType","InteractionResponseType","Hono","ApplicationWebhookType","ApplicationCommandType"],"sources":["../src/resolvers/CommandOptionResolver.ts","../src/structures/utils.ts","../src/structures/AttachmentBuilder.ts","../src/utils/Fetcher.ts","../src/interactions/BaseInteraction.ts","../src/interactions/ModalCapableInteraction.ts","../src/interactions/CommandInteraction.ts","../src/interactions/ChatInputInteraction.ts","../src/utils/discordVerify.ts","../src/utils/Colors.ts","../src/utils/registerCommands.ts","../src/utils/index.ts","../src/interactions/UserContextCommandInteraction.ts","../src/interactions/MessageContextCommandInteraction.ts","../src/resolvers/ModalComponentResolver.ts","../src/interactions/ModalInteraction.ts","../src/interactions/AutocompleteInteraction.ts","../src/handlers/SlashCommandHandler.ts","../src/handlers/ContextCommandHandler.ts","../src/handlers/ComponentHandler.ts","../src/handlers/ModalHandler.ts","../src/handlers/WebhookEventHandler.ts","../src/interactions/MessageComponentInteraction.ts","../src/interactions/ButtonInteraction.ts","../src/interactions/StringSelectInteraction.ts","../src/interactions/UserSelectInteraction.ts","../src/interactions/RoleSelectInteraction.ts","../src/interactions/MentionableSelectInteraction.ts","../src/interactions/ChannelSelectInteraction.ts","../src/utils/CacheManager.ts","../src/Honocord.ts","../src/types/commands.ts"],"sourcesContent":["import { Collection } from \"@discordjs/collection\";\nimport {\n APIApplicationCommandInteractionDataOption,\n APIAttachment,\n APIInteractionDataResolved,\n APIInteractionDataResolvedChannel,\n APIRole,\n APIUser,\n ApplicationCommandOptionType,\n ChannelType,\n InteractionType,\n} from \"discord-api-types/v10\";\nimport { APIInteractionDataResolvedCollections, ResolvedSelectedGuildMember } from \"../types\";\n\ntype AutocompleteFocusedOption = {\n /**\n * The name of the option.\n */\n name: string;\n /**\n * The type of the application command option.\n */\n type: ApplicationCommandOptionType;\n /**\n * The value of the option.\n */\n value: string;\n /**\n * Whether the option is focused.\n */\n focused: boolean;\n};\n\n/**\n * A resolver for command interaction options.\n */\nclass CommandInteractionOptionResolver {\n /**\n * The name of the subcommand group.\n */\n private _group: string | null = null;\n /**\n * The name of the subcommand.\n */\n private _subcommand: string | null = null;\n /**\n * The bottom-level options for the interaction.\n * If there is a subcommand (or subcommand and group), this is the options for the subcommand.\n */\n private _hoistedOptions: APIApplicationCommandInteractionDataOption<\n InteractionType.ApplicationCommand | InteractionType.ApplicationCommandAutocomplete\n >[];\n\n private _resolved: APIInteractionDataResolvedCollections;\n\n constructor(\n options:\n | APIApplicationCommandInteractionDataOption<\n InteractionType.ApplicationCommand | InteractionType.ApplicationCommandAutocomplete\n >[]\n | undefined,\n resolved: APIInteractionDataResolved | undefined\n ) {\n this._hoistedOptions = options ?? [];\n this._resolved = Object.keys(resolved ?? {}).reduce((acc, key) => {\n const resolvedData = resolved?.[key as keyof APIInteractionDataResolved];\n if (key === \"members\") {\n // get users and combine them with members for easy access; a user is expected to ALWAYS be present if a member is\n const users = resolved?.users ? new Collection(Object.entries(resolved.users)) : new Collection();\n const members = resolvedData ? new Collection(Object.entries(resolvedData)) : new Collection();\n const combined = new Collection([...members.entries()].map(([id, member]) => [id, { ...member, user: users.get(id)! }]));\n acc[key] = combined;\n return acc;\n }\n const collection = new Collection(resolvedData ? Object.entries(resolvedData) : []);\n acc[key as keyof APIInteractionDataResolvedCollections] = collection;\n return acc;\n }, {} as any);\n\n // Hoist subcommand group if present\n if (this._hoistedOptions[0]?.type === ApplicationCommandOptionType.SubcommandGroup) {\n this._group = this._hoistedOptions[0].name;\n this._hoistedOptions = this._hoistedOptions[0].options ?? [];\n }\n\n // Hoist subcommand if present\n if (this._hoistedOptions[0]?.type === ApplicationCommandOptionType.Subcommand) {\n this._subcommand = this._hoistedOptions[0].name;\n this._hoistedOptions = this._hoistedOptions[0].options ?? [];\n }\n }\n\n public get data() {\n return this._hoistedOptions;\n }\n\n /**\n * Gets an option by its name.\n *\n * @param name The name of the option.\n * @param type The expected type of the option.\n * @param required Whether to throw an error if the option is not found.\n * @returns The option, if found.\n */\n get<T extends ApplicationCommandOptionType>(name: string, type: T, required = false) {\n const option = this._hoistedOptions.find((opt) => opt.name === name);\n if (!option) {\n if (required) {\n throw new TypeError(\"Option not found\", { cause: { name } });\n }\n\n return null;\n }\n\n if (option.type !== type) {\n throw new TypeError(\"Option type mismatch\", { cause: { name, type: option.type, expected: type } });\n }\n\n return option as Extract<APIApplicationCommandInteractionDataOption<InteractionType.ApplicationCommand>, { type: T }>;\n }\n\n /**\n * Gets the selected subcommand.\n *\n * @param {boolean} [required=true] Whether to throw an error if there is no subcommand.\n * @returns {?string} The name of the selected subcommand, or null if not set and not required.\n */\n getSubcommand(): string | null;\n getSubcommand(required: true): string;\n getSubcommand(required: boolean = true): string | null {\n if (required && !this._subcommand) {\n throw new TypeError(\"No subcommand selected\");\n }\n\n return this._subcommand;\n }\n\n /**\n * Gets the selected subcommand group.\n *\n * @param required Whether to throw an error if there is no subcommand group.\n * @returns The name of the selected subcommand group, or null if not set and not required.\n */\n getSubcommandGroup(required?: boolean): string | null;\n getSubcommandGroup(required: true): string;\n getSubcommandGroup(required: boolean = false): string | null {\n if (required && !this._group) {\n throw new TypeError(\"No subcommand group selected\");\n }\n\n return this._group;\n }\n\n getFocused(): AutocompleteFocusedOption | null {\n return (this._hoistedOptions as AutocompleteFocusedOption[]).find((option) => option.focused) || null;\n }\n\n /**\n * Gets a boolean option.\n *\n * @param name The name of the option.\n * @param required Whether to throw an error if the option is not found.\n * @returns The value of the option, or null if not set and not required.\n */\n getBoolean(name: string, required?: boolean): boolean | null;\n getBoolean(name: string, required: true): boolean;\n getBoolean(name: string, required: boolean = false): boolean | null {\n const option = this.get(name, ApplicationCommandOptionType.Boolean, required);\n return option ? option.value : null;\n }\n\n /**\n * Gets a channel option.\n *\n * @param name The name of the option.\n * @param required Whether to throw an error if the option is not found.\n * @param channelTypes The allowed types of channels. If empty, all channel types are allowed.\n * @returns The value of the option, or null if not set and not required.\n */\n getChannel(name: string, required: false, channelTypes: ChannelType[]): APIInteractionDataResolvedChannel | null;\n getChannel(name: string, required: true, channelTypes: ChannelType[]): APIInteractionDataResolvedChannel;\n getChannel(\n name: string,\n required: boolean = false,\n channelTypes: ChannelType[] = []\n ): APIInteractionDataResolvedChannel | null {\n const option = this.get(name, ApplicationCommandOptionType.Channel, required);\n const channel = option ? this._resolved.channels?.get(option.value) || null : null;\n\n if (channel && channelTypes.length > 0 && !channelTypes.includes(channel.type)) {\n throw new TypeError(\"Invalid channel type\", { cause: { name, type: channel.type, expected: channelTypes.join(\", \") } });\n }\n\n return channel;\n }\n\n /**\n * Gets a string option.\n *\n * @param name The name of the option.\n * @param required Whether to throw an error if the option is not found.\n * @returns The value of the option, or null if not set and not required.\n */\n getString<T extends string = string>(name: string, required?: boolean): T | null;\n getString<T extends string = string>(name: string, required: true): T;\n getString<T extends string = string>(name: string, required: boolean = false): T | null {\n const option = this.get(name, ApplicationCommandOptionType.String, required);\n return (option?.value as T) ?? null;\n }\n\n /**\n * Gets an integer option.\n *\n * @param name The name of the option.\n * @param required Whether to throw an error if the option is not found.\n * @returns The value of the option, or null if not set and not required.\n */\n getInteger(name: string, required?: boolean): number | null;\n getInteger(name: string, required: true): number;\n getInteger(name: string, required: boolean = false): number | null {\n const option = this.get(name, ApplicationCommandOptionType.Integer, required);\n return option?.value ?? null;\n }\n\n /**\n * Gets a number option.\n *\n * @param name The name of the option.\n * @param required Whether to throw an error if the option is not found.\n * @returns The value of the option, or null if not set and not required.\n */\n getNumber(name: string, required?: boolean): number | null;\n getNumber(name: string, required: true): number;\n getNumber(name: string, required: boolean = false): number | null {\n const option = this.get(name, ApplicationCommandOptionType.Number, required);\n return option?.value ?? null;\n }\n\n /**\n * Gets a user option.\n *\n * @param name The name of the option.\n * @param required Whether to throw an error if the option is not found.\n * @returns The value of the option, or null if not set and not required.\n */\n getUser(name: string, required?: boolean): APIUser | null;\n getUser(name: string, required: true): APIUser;\n getUser(name: string, required: boolean = false): APIUser | null {\n const option = this.get(name, ApplicationCommandOptionType.User, required);\n const user = option ? this._resolved.users?.get(option.value) || null : null;\n return user;\n }\n\n /**\n * Gets a member option.\n *\n * @param name The name of the option.\n * @returns The value of the option, or null if the user is not present in the guild or the option is not set.\n */\n getMember(name: string, required?: boolean): ResolvedSelectedGuildMember | null;\n getMember(name: string, required: true): ResolvedSelectedGuildMember;\n getMember(name: string, required: boolean = false): ResolvedSelectedGuildMember | null {\n const option = this.get(name, ApplicationCommandOptionType.User, required);\n const member = option ? this._resolved.members?.get(option.value) || null : null;\n return member;\n }\n\n /**\n * Gets a role option.\n *\n * @param name The name of the option.\n * @param required Whether to throw an error if the option is not found.\n * @returns The value of the option, or null if not set and not required.\n */\n getRole(name: string, required?: boolean): APIRole | null;\n getRole(name: string, required: true): APIRole;\n getRole(name: string, required: boolean = false): APIRole | null {\n const option = this.get(name, ApplicationCommandOptionType.Role, required);\n const role = option ? this._resolved.roles?.get(option.value) || null : null;\n return role;\n }\n\n /**\n * Gets an attachment option.\n *\n * @param name The name of the option.\n * @param required Whether to throw an error if the option is not found.\n * @returns The value of the option, or null if not set and not required.\n */\n getAttachment(name: string, required?: boolean): APIAttachment | null;\n getAttachment(name: string, required: true): APIAttachment;\n getAttachment(name: string, required: boolean = false): APIAttachment | null {\n const option = this.get(name, ApplicationCommandOptionType.Attachment, required);\n const attachment = option ? this._resolved.attachments?.get(option.value) || null : null;\n return attachment;\n }\n\n /**\n * Gets a mentionable option.\n *\n * @param name The name of the option.\n * @param required Whether to throw an error if the option is not found.\n * @returns The value of the option, or null if not set and not required.\n */\n getMentionable(name: string, required?: boolean): ResolvedSelectedGuildMember | APIUser | APIRole | null;\n getMentionable(name: string, required: true): ResolvedSelectedGuildMember | APIUser | APIRole;\n getMentionable(name: string, required: boolean = false): (ResolvedSelectedGuildMember | APIUser | APIRole) | null {\n const option = this.get(name, ApplicationCommandOptionType.Mentionable, required);\n const user = option ? this._resolved.users?.get(option.value) || null : null;\n const member = option ? this._resolved.members?.get(option.value) || null : null;\n const role = option ? this._resolved.roles?.get(option.value) || null : null;\n return member ?? user ?? role ?? null;\n }\n}\n\nexport { CommandInteractionOptionResolver };\n","import { parse } from \"node:path\";\n\n/**\n * Alternative to Node's `path.basename`, removing query string after the extension if it exists.\n * @param path Path to get the basename of\n * @param ext File extension to remove\n * @returns Basename of the path\n * @private\n */\nexport function basename(path: string, ext?: string): string {\n const res = parse(path);\n return ext && res.ext.startsWith(ext) ? res.name : res.base.split(\"?\")[0];\n}\n","import type { AttachmentPayload, BufferResolvable } from \"$types/utils\";\nimport Stream from \"node:stream\";\nimport { basename } from \"./utils\";\nimport { AttachmentData, RawFile } from \"$types/responses\";\nimport { RESTAPIAttachment } from \"discord-api-types/v10\";\n\n/**\n * Builder for message attachments, which can be used in several response methods across the library.\n */\nexport class AttachmentBuilder {\n private attachment: BufferResolvable | Stream;\n private name?: string;\n private description?: string;\n private contentType?: string;\n private key?: string; // Not really needed but allows users to set a custom key for their own reference if they want\n\n constructor(attachment: BufferResolvable | Stream, data: AttachmentData = {}) {\n this.attachment = attachment;\n this.name = data.name;\n this.description = data.description;\n this.contentType = data.contentType;\n this.key = data.key;\n }\n\n setDescription(description: string): this {\n this.description = description;\n return this;\n }\n setContentType(contentType: string): this {\n this.contentType = contentType;\n return this;\n }\n setKey(key: string): this {\n this.key = key;\n return this;\n }\n setFile(attachment: BufferResolvable | Stream): this {\n this.attachment = attachment;\n return this;\n }\n setName(name: string): this {\n this.name = name;\n return this;\n }\n\n setSpoiler(spoiler = true): this {\n if (!this.name) return this;\n if (spoiler === this.spoiler) return this;\n if (!spoiler) {\n while (this.spoiler) this.name = this.name.slice(\"SPOILER_\".length);\n return this;\n }\n this.name = `SPOILER_${this.name}`;\n return this;\n }\n\n get spoiler() {\n return this.name ? basename(this.name).startsWith(\"SPOILER_\") : false;\n }\n\n /** Produces the multipart file part (files[n]) */\n toRawFile(): RawFile {\n return {\n name: this.name ?? \"file\",\n data: this.attachment as Buffer | Uint8Array | string,\n contentType: this.contentType,\n key: this.key,\n };\n }\n\n /** Produces the attachments[] entry for the JSON payload */\n toRestAttachment(index: number): RESTAPIAttachment {\n return {\n id: index,\n filename: this.name ?? \"file\",\n ...(this.description && { description: this.description }),\n };\n }\n\n /**\n * Resolves this builder into the parallel `files` and `attachments` arrays ready to spread into your API call options.\n *\n * @example\n * const { files, attachments } = builder.resolve();\n * await interaction.reply({ content: \"Here!\", files, attachments });\n * // or even shorter:\n * await interaction.reply({ content: \"Here!\", ...builder.resolve() });\n */\n resolve(): { files: RawFile[]; attachments: RESTAPIAttachment[] } {\n return AttachmentBuilder.resolve(this);\n }\n\n /**\n * Resolves an array of AttachmentBuilders into parallel `files` and\n * `attachments` arrays ready to spread into your API call options.\n *\n * @example\n * const { files, attachments } = AttachmentBuilder.resolve(builder1, builder2);\n * await interaction.reply({ content: \"Here!\", files, attachments });\n */\n static resolve(...builders: AttachmentBuilder[]): {\n files: RawFile[];\n attachments: RESTAPIAttachment[];\n } {\n return {\n files: builders.map((b) => b.toRawFile()),\n attachments: builders.map((b, i) => b.toRestAttachment(i)),\n };\n }\n\n static from(other: AttachmentBuilder | AttachmentPayload): AttachmentBuilder {\n if (other instanceof AttachmentBuilder) {\n return new AttachmentBuilder(other.attachment, {\n name: other.name,\n description: other.description,\n contentType: other.contentType,\n key: other.key,\n });\n }\n return new AttachmentBuilder(other.attachment, {\n name: other.name,\n description: other.description,\n });\n }\n}\n","import { API } from \"@discordjs/core/http-only\";\nimport { CacheManager } from \"./CacheManager\";\nimport type { APIGuild, APIGuildMember, APIRole, APIUser, ChannelType } from \"discord-api-types/v10\";\nimport type { CachedChannel, CachedGuildMember } from \"$types/caching\";\n\nexport class Fetcher {\n constructor(\n public readonly api: API,\n private getCache: () => CacheManager | undefined | null\n ) {}\n\n private get cache() {\n return this.getCache() ?? null;\n }\n\n private async fetchAndCache<T>(\n cacheGetter: () => Promise<T | undefined | null>,\n cacheSetter: (data: T) => Promise<void>,\n fetcher: () => Promise<T>\n ): Promise<T> {\n const cache = this.cache;\n if (cache) {\n const cached = await cacheGetter();\n if (cached) return cached;\n }\n\n const data = await fetcher();\n if (cache) {\n await cacheSetter(data);\n }\n return data;\n }\n\n readonly users = {\n get: (userId: string): Promise<APIUser> =>\n this.fetchAndCache(\n () => this.cache?.users.get(userId) ?? Promise.resolve(null),\n (user) => this.cache!.users.set(user),\n () => this.api.users.get(userId)\n ),\n };\n\n readonly channels = {\n get: (channelId: string): Promise<CachedChannel> =>\n this.fetchAndCache(\n () => this.cache?.channels.get(channelId) ?? Promise.resolve(null),\n (channel) => this.cache!.channels.set(channel),\n () => this.api.channels.get(channelId) as Promise<CachedChannel>\n ),\n };\n\n readonly dmChannels = {\n get: (userId: string): Promise<Extract<CachedChannel, { type: ChannelType.DM | ChannelType.GroupDM }>> =>\n this.fetchAndCache(\n () => this.cache?.getDMChannel(userId) ?? Promise.resolve(null),\n (channel) => this.cache!.setDMChannel(userId, channel),\n () => this.api.users.createDM(userId) as Promise<Extract<CachedChannel, { type: ChannelType.DM | ChannelType.GroupDM }>>\n ),\n };\n\n readonly guilds = {\n get: (guildId: string): Promise<APIGuild> =>\n this.fetchAndCache(\n () => this.cache?.guilds.get(guildId) ?? Promise.resolve(null),\n (guild) => this.cache!.guilds.set(guild),\n () => this.api.guilds.get(guildId)\n ),\n };\n\n readonly roles = {\n get: (guildId: string, roleId: string): Promise<APIRole> =>\n this.fetchAndCache(\n () => this.cache?.roles.get(roleId) ?? Promise.resolve(null),\n (role) => this.cache!.roles.set(role),\n async () => {\n const roles = await this.api.guilds.getRoles(guildId);\n return roles.find((r) => r.id === roleId)!;\n }\n ),\n list: (guildId: string): Promise<APIRole[]> =>\n this.fetchAndCache(\n () => this.cache?.getGuildRoles(guildId) ?? Promise.resolve(null),\n async (roles) => {\n if (!this.cache) return;\n await this.cache.roles.mset(roles.map((r) => ({ value: r })));\n },\n () => this.api.guilds.getRoles(guildId)\n ),\n };\n\n readonly members = {\n get: (guildId: string, userId: string): Promise<APIGuildMember | CachedGuildMember> =>\n this.fetchAndCache(\n () => this.cache?.members.get(guildId, userId) ?? Promise.resolve(null),\n (member) => this.cache!.members.set(guildId, member),\n () => this.api.guilds.getMember(guildId, userId)\n ),\n };\n}\n","import {\n type Snowflake,\n APIInteractionResponseCallbackData,\n APIPartialInteractionGuild,\n APIUser,\n ApplicationCommandType,\n InteractionType,\n Locale,\n APIApplicationCommandInteraction,\n ComponentType,\n APIMessage,\n} from \"discord-api-types/v10\";\nimport { API } from \"@discordjs/core/http-only\";\nimport { REST } from \"@discordjs/rest\";\nimport { ModalInteraction } from \"./ModalInteraction\";\nimport type {\n BaseInteractionContext,\n InteractionResponseCallbackData,\n JSONEncodable,\n MessageComponentType,\n PreparedResponseOptions,\n RawFile,\n ValidInteraction,\n} from \"$types/index\";\nimport { MessageComponentInteraction } from \"./MessageComponentInteraction\";\nimport { AutocompleteInteraction } from \"./AutocompleteInteraction\";\nimport { CommandInteraction } from \"./CommandInteraction\";\nimport { ChatInputCommandInteraction } from \"./ChatInputInteraction\";\nimport { UserContextInteraction } from \"./UserContextCommandInteraction\";\nimport { MessageContextInteraction } from \"./MessageContextCommandInteraction\";\nimport { ButtonInteraction } from \"./ButtonInteraction\";\nimport { StringSelectInteraction } from \"./StringSelectInteraction\";\nimport { UserSelectInteraction } from \"./UserSelectInteraction\";\nimport { RoleSelectInteraction } from \"./RoleSelectInteraction\";\nimport { MentionableSelectInteraction } from \"./MentionableSelectInteraction\";\nimport { ChannelSelectInteraction } from \"./ChannelSelectInteraction\";\nimport { AttachmentBuilder } from \"../structures/AttachmentBuilder\";\nimport { Fetcher } from \"@utils/Fetcher\";\n\nfunction snakeCase(str: string): string {\n return str\n .replace(/([a-z0-9])([A-Z])/g, \"$1_$2\")\n .replace(/([A-Z])([A-Z][a-z])/g, \"$1_$2\")\n .toLowerCase();\n}\n\n/**\n * Transforms camel-cased keys into snake cased keys\n *\n * @param {*} obj The object to transform\n * @returns {*} The transformed object\n */\nfunction toSnakeCase(obj: any): any {\n if (typeof obj !== \"object\" || !obj) return obj;\n if (obj instanceof Date) return obj;\n if (isJSONEncodable(obj)) return toSnakeCase(obj.toJSON());\n if (Array.isArray(obj)) return obj.map(toSnakeCase);\n return Object.fromEntries(Object.entries(obj).map(([key, value]) => [snakeCase(key), toSnakeCase(value)]));\n}\n\n/**\n * Indicates if an object is encodable or not.\n *\n * @param maybeEncodable - The object to check against\n */\nfunction isJSONEncodable(maybeEncodable: unknown): maybeEncodable is JSONEncodable<unknown> {\n return (\n maybeEncodable !== null &&\n typeof maybeEncodable === \"object\" &&\n \"toJSON\" in maybeEncodable &&\n typeof maybeEncodable[\"toJSON\"] === \"function\"\n );\n}\n\nexport abstract class BaseInteraction<\n Type extends InteractionType,\n Context extends BaseInteractionContext = BaseInteractionContext,\n> {\n public readonly type: Type;\n /** The raw interaction data */\n protected readonly raw: Extract<ValidInteraction, { type: Type }>;\n public readonly rest: REST;\n protected _ephemeral: boolean | null = null;\n protected replied: boolean = false;\n protected deferred: boolean = false;\n public readonly context: Context;\n public readonly fetcher: Fetcher;\n\n constructor(\n protected api: API,\n data: Extract<ValidInteraction, { type: Type }>,\n context: Context\n ) {\n this.type = data.type as Type;\n this.raw = { ...data };\n this.rest = api.rest;\n this.context = context;\n this.fetcher = new Fetcher(api, () => this.context.get(\"cache\") as any);\n }\n\n get applicationId() {\n return this.raw.application_id;\n }\n\n get entitlements() {\n return this.raw.entitlements;\n }\n\n get channelId() {\n return this.raw.channel?.id;\n }\n\n get channel() {\n return this.raw.channel;\n }\n\n get guildId() {\n return this.raw.guild_id;\n }\n\n get guild() {\n return this.raw.guild;\n }\n\n get userId() {\n return this.raw.user?.id;\n }\n\n get user() {\n return (this.raw.member?.user || this.raw.user) as APIUser; // One is always given.\n }\n\n get member() {\n return this.raw.member;\n }\n\n get locale() {\n return this.raw.guild_locale;\n }\n\n get guildLocale() {\n return this.raw.guild_locale;\n }\n\n get token() {\n return this.raw.token;\n }\n\n get id() {\n return this.raw.id;\n }\n\n get appPermissions() {\n return this.raw.app_permissions;\n }\n\n get version() {\n return this.raw.version;\n }\n\n protected isJSONEncodable(obj: unknown): obj is JSONEncodable<unknown> {\n return isJSONEncodable(obj);\n }\n\n protected toSnakeCase<T = unknown>(obj: unknown): T {\n return toSnakeCase(obj) as T;\n }\n\n inGuild(): this is BaseInteraction<Type> & { guild_id: Snowflake; guild: APIPartialInteractionGuild; guild_locale: Locale } {\n return Boolean(this.raw.guild_id && this.raw.guild && this.raw.guild_locale);\n }\n\n inDM(): this is BaseInteraction<Type> & { guild_id: undefined; guild: undefined; guild_locale: undefined } {\n return !this.inGuild();\n }\n\n getAppEntitlements() {\n return this.entitlements.filter((entitlement) => entitlement.application_id === this.applicationId);\n }\n\n guildHavePremium(): boolean {\n return (\n this.getAppEntitlements().filter(\n (entitlement) =>\n entitlement.guild_id === this.guildId && (!entitlement.ends_at || new Date(entitlement.ends_at) > new Date())\n ).length > 0\n );\n }\n\n userHavePremium(): boolean {\n return (\n this.getAppEntitlements().filter(\n (entitlement) =>\n entitlement.user_id === this.userId && (!entitlement.ends_at || new Date(entitlement.ends_at) > new Date())\n ).length > 0\n );\n }\n\n protected prepareResponsePayload<T extends PreparedResponseOptions = PreparedResponseOptions>(\n options: InteractionResponseCallbackData\n ): T {\n const builders = (options.files ?? []).filter((f): f is AttachmentBuilder => f instanceof AttachmentBuilder);\n const rawFiles = (options.files ?? []).filter((f): f is RawFile => !(f instanceof AttachmentBuilder));\n\n const { files: resolvedFiles, attachments: resolvedMeta } = AttachmentBuilder.resolve(...builders);\n\n delete options.files;\n\n const components = options.components?.map((c) => (this.isJSONEncodable(c) ? c.toJSON() : c));\n const embeds = options.embeds?.map((e) => (this.isJSONEncodable(e) ? e.toJSON() : e));\n const attachments = [...resolvedMeta, ...(options.attachments ?? [])];\n const finalFiles = [...resolvedFiles, ...rawFiles];\n\n const body: any = {};\n if (options.content) body.content = options.content;\n if (options.tts) body.tts = options.tts;\n if (options.allowed_mentions) body.allowed_mentions = options.allowed_mentions;\n if (options.flags) body.flags = options.flags;\n if (options.applied_tags) body.applied_tags = options.applied_tags;\n if (options.poll) body.poll = options.poll;\n if (options.thread_name) body.thread_name = options.thread_name;\n if (components?.length) body.components = components;\n if (embeds?.length) body.embeds = embeds;\n if (attachments?.length) body.attachments = attachments;\n\n const finalBody = this.toSnakeCase<APIInteractionResponseCallbackData>(body);\n if (finalFiles.length) {\n return { ...finalBody, files: finalFiles } as T;\n }\n return { ...finalBody } as T;\n }\n\n async reply(options: InteractionResponseCallbackData | string, forceEphemeral = true) {\n const replyOptions = typeof options === \"string\" ? { content: options } : options;\n if (forceEphemeral) {\n replyOptions.flags = (replyOptions.flags ?? 0) | 64;\n }\n const response = await this.api.interactions.reply(\n this.id,\n this.token,\n { ...this.prepareResponsePayload(replyOptions), with_response: true },\n {\n signal: AbortSignal.timeout(5000),\n }\n );\n this.replied = true;\n return response;\n }\n\n async deferReply(forceEphemeral = true) {\n const response = await this.api.interactions.defer(this.id, this.token, {\n flags: forceEphemeral ? 64 : undefined,\n with_response: true,\n });\n this.deferred = true;\n return response;\n }\n\n /**\n * Defers the update of a component interaction.\n *\n * @returns A promise that resolves when the update is deferred\n *\n * Responding to a component interaction via the deferUpdate() method acknowledges the interaction and resets the message state.\n * This method can be used to suppress the need for further responses, however it's encouraged to provide meaningful feedback to users via an update() or ephemeral reply() at least.\\\n * Once deferUpdate() has been called, future messages can be sent by calling followUp() or edits can be made by calling editReply() on the component interaction.\n *\n * Example flow:\n * 1. User clicks a button.\n * 2. Bot calls `deferUpdate()` to acknowledge the interaction.\n * 3. Bot performs some processing.\n * 4. Bot calls `editReply()` to update the original message.\n *\n */\n deferUpdate() {\n return this.api.interactions.deferMessageUpdate(this.id, this.token, { with_response: true });\n }\n\n /**\n * Edits the original interaction response.\n *\n * @param options - The options to edit the message with\n * @param messageId - The message id to edit, defaults to `@original`\n * @returns The edited message\n *\n * This is used to edit the original interaction response message.\n *\n * Before using this method, the interaction needs to be replied to first before using this method - with `reply`, `deferReply` or `update`.\n */\n async editReply(options: InteractionResponseCallbackData | string, messageId: Snowflake | \"@original\" = \"@original\") {\n const replyOptions = typeof options === \"string\" ? { content: options } : options;\n const response = await this.api.interactions.editReply(\n this.applicationId,\n this.token,\n this.prepareResponsePayload(replyOptions),\n messageId,\n {\n signal: AbortSignal.timeout(5000),\n }\n );\n this.replied = true;\n return response;\n }\n\n /**\n * Deletes the original interaction response (or a follow-up message).\n *\n * @param messageId - The message id to delete, defaults to `@original`\n * @returns A promise that resolves when the message is deleted\n *\n * This is used to delete the original interaction response message or a follow-up message.\n */\n deleteReply(messageId?: Snowflake | \"@original\") {\n return this.api.interactions.deleteReply(this.applicationId, this.token, messageId);\n }\n\n /**\n * Updates the original interaction response.\n *\n * @param options - The options to update the message with\n * @returns The updated message\n *\n * This is mainly used for component interactions where you want to update the message the component is attached to OR for\n * moodal submit interactions to update the message that opened the modal.\n *\n * After calling this method, the interaction is considered replied and you need to use `editReply` to edit the original response.\n */\n async update(options: InteractionResponseCallbackData | string) {\n const updateOptions = typeof options === \"string\" ? { content: options } : options;\n const response = await this.api.interactions.updateMessage(\n this.id,\n this.token,\n { ...this.prepareResponsePayload(updateOptions), with_response: true },\n {\n signal: AbortSignal.timeout(5000),\n }\n );\n this.replied = true;\n return response;\n }\n\n /**\n * Sends a follow-up message to the interaction.\n *\n * @param options - The options to send the follow-up message with\n * @param forceEphemeral - Whether to force the message to be ephemeral\n * @returns The sent follow-up message\n *\n * This is used to send additional messages after the initial interaction response.\n */\n async followUp(options: InteractionResponseCallbackData | string, forceEphemeral = false) {\n const followUpOptions = typeof options === \"string\" ? { content: options } : options;\n if (forceEphemeral) {\n followUpOptions.flags = (followUpOptions.flags ?? 0) | 64;\n }\n const response = await this.api.interactions.followUp(\n this.applicationId,\n this.token,\n this.prepareResponsePayload(followUpOptions),\n {\n signal: AbortSignal.timeout(5000),\n }\n );\n return response;\n }\n\n // Typeguards\n isCommand(): this is CommandInteraction<ApplicationCommandType, Context> {\n return this.raw.type === InteractionType.ApplicationCommand;\n }\n\n isChatInputCommand(): this is ChatInputCommandInteraction<Context> {\n return (\n this.raw.type === InteractionType.ApplicationCommand &&\n (this.raw as APIApplicationCommandInteraction).data.type === ApplicationCommandType.ChatInput\n );\n }\n\n isUserContextCommand(): this is UserContextInteraction<Context> {\n return (\n this.raw.type === InteractionType.ApplicationCommand &&\n (this.raw as APIApplicationCommandInteraction).data.type === ApplicationCommandType.User\n );\n }\n\n isMessageContextCommand(): this is MessageContextInteraction<Context> {\n return (\n this.raw.type === InteractionType.ApplicationCommand &&\n (this.raw as APIApplicationCommandInteraction).data.type === ApplicationCommandType.Message\n );\n }\n\n isModal(): this is ModalInteraction {\n return this.raw.type === InteractionType.ModalSubmit;\n }\n\n isMessageModal(): this is ModalInteraction<Context & { message: APIMessage }> {\n return this.isModal() && !!this.message;\n }\n\n isMessageComponent(): this is MessageComponentInteraction<Context, MessageComponentType> {\n return this.raw.type === InteractionType.MessageComponent;\n }\n\n isButton(): this is ButtonInteraction<Context> {\n return this.isMessageComponent() && this.raw.data.component_type === ComponentType.Button;\n }\n\n isStringSelect(): this is StringSelectInteraction<Context> {\n return this.isMessageComponent() && this.raw.data.component_type === ComponentType.StringSelect;\n }\n\n isUserSelect(): this is UserSelectInteraction<Context> {\n return this.isMessageComponent() && this.raw.data.component_type === ComponentType.UserSelect;\n }\n\n isRoleSelect(): this is RoleSelectInteraction<Context> {\n return this.isMessageComponent() && this.raw.data.component_type === ComponentType.RoleSelect;\n }\n\n isMentionableSelect(): this is MentionableSelectInteraction<Context> {\n return this.isMessageComponent() && this.raw.data.component_type === ComponentType.MentionableSelect;\n }\n\n isChannelSelect(): this is ChannelSelectInteraction<Context> {\n return this.isMessageComponent() && this.raw.data.component_type === ComponentType.ChannelSelect;\n }\n\n isAutocomplete(): this is AutocompleteInteraction<Context> & { type: InteractionType.ApplicationCommandAutocomplete } {\n return this.raw.type === InteractionType.ApplicationCommandAutocomplete;\n }\n}\n","import { InteractionType } from \"discord-api-types/v10\";\nimport { ModalBuilder } from \"@discordjs/builders\";\nimport { BaseInteraction } from \"./BaseInteraction\";\nimport type { BaseInteractionContext, ModalInteractionResponseCallbackData } from \"../types\";\n\nclass ModalCapableInteraction<\n Type extends InteractionType,\n Context extends BaseInteractionContext = BaseInteractionContext,\n> extends BaseInteraction<Type, Context> {\n /**\n * Responds to the interaction with a modal.\n *\n * @param data - The modal data to send\n */\n showModal(data: ModalInteractionResponseCallbackData | ModalBuilder) {\n const responseData = {\n ...(data instanceof ModalBuilder ? data.toJSON() : data),\n components:\n data instanceof ModalBuilder\n ? data.components.map((row) => row.toJSON())\n : data.components.map((row) => (this.isJSONEncodable(row) ? row.toJSON() : row)),\n };\n return this.api.interactions.createModal(this.id, this.token, responseData);\n }\n}\n\nexport { ModalCapableInteraction };\n","import { APIApplicationCommandInteraction, ApplicationCommandType, InteractionType } from \"discord-api-types/v10\";\nimport { API } from \"@discordjs/core/http-only\";\nimport { BaseInteractionContext } from \"../types\";\nimport { ModalCapableInteraction } from \"./ModalCapableInteraction\";\n\nabstract class CommandInteraction<\n CType extends ApplicationCommandType = ApplicationCommandType,\n Context extends BaseInteractionContext = BaseInteractionContext,\n> extends ModalCapableInteraction<InteractionType.ApplicationCommand, Context> {\n public readonly commandType: CType;\n\n constructor(api: API, interaction: Extract<APIApplicationCommandInteraction, { data: { type: CType } }>, c: Context) {\n super(api, interaction, c);\n this.commandType = interaction.data.type;\n }\n\n get commandName() {\n return this.raw.data.name;\n }\n\n get commandId() {\n return this.raw.data.id;\n }\n\n isOfType<T extends ApplicationCommandType>(type: T): this is CommandInteraction<T, Context> {\n return (this.commandType as ApplicationCommandType) === type;\n }\n}\n\nexport { CommandInteraction };\n","import { ApplicationCommandType, type APIChatInputApplicationCommandInteraction } from \"discord-api-types/v10\";\nimport { CommandInteractionOptionResolver } from \"@resolvers/CommandOptionResolver\";\nimport { API } from \"@discordjs/core/http-only\";\nimport { BaseInteractionContext } from \"../types\";\nimport { CommandInteraction } from \"./CommandInteraction\";\n\nclass ChatInputCommandInteraction<Context extends BaseInteractionContext = BaseInteractionContext> extends CommandInteraction<\n ApplicationCommandType.ChatInput,\n Context\n> {\n public readonly options: CommandInteractionOptionResolver;\n constructor(api: API, interaction: APIChatInputApplicationCommandInteraction, c: Context) {\n super(api, interaction, c);\n this.options = new CommandInteractionOptionResolver(interaction.data.options, interaction.data.resolved);\n }\n}\n\nexport { ChatInputCommandInteraction };\n","import type { APIInteraction, APIWebhookEvent } from \"discord-api-types/v10\";\nimport { cloneRawRequest, type HonoRequest } from \"hono/request\";\nimport { BufferSource } from \"../types\";\n\nexport const subtleCrypto = crypto.subtle;\n\n/**\n * Converts different types to Uint8Array.\n *\n * @param value - Value to convert. Strings are parsed as hex.\n * @param format - Format of value. Valid options: 'hex'. Defaults to utf-8.\n * @returns Value in Uint8Array form.\n */\nfunction valueToUint8Array(value: Uint8Array | ArrayBuffer | Buffer | string, format?: string): Uint8Array {\n if (value == null) {\n return new Uint8Array();\n }\n if (typeof value === \"string\") {\n if (format === \"hex\") {\n const matches = value.match(/.{1,2}/g);\n if (matches == null) {\n throw new Error(\"Value is not a valid hex string\");\n }\n const hexVal = matches.map((byte: string) => Number.parseInt(byte, 16));\n return new Uint8Array(hexVal);\n }\n\n return new TextEncoder().encode(value);\n }\n try {\n if (Buffer.isBuffer(value)) {\n return new Uint8Array(value);\n }\n } catch (_ex) {\n // Runtime doesn't have Buffer\n }\n if (value instanceof ArrayBuffer) {\n return new Uint8Array(value);\n }\n if (value instanceof Uint8Array) {\n return value;\n }\n throw new Error(\"Unrecognized value type, must be one of: string, Buffer, ArrayBuffer, Uint8Array\");\n}\n\n/**\n * Merge two arrays.\n *\n * @param arr1 - First array\n * @param arr2 - Second array\n * @returns Concatenated arrays\n */\nfunction concatUint8Arrays(arr1: Uint8Array, arr2: Uint8Array): Uint8Array {\n const merged = new Uint8Array(arr1.length + arr2.length);\n merged.set(arr1);\n merged.set(arr2, arr1.length);\n return merged;\n}\n\n/**\n * Validates a payload from Discord against its signature and key.\n *\n * @param rawBody - The raw payload data\n * @param signature - The signature from the `X-Signature-Ed25519` header\n * @param timestamp - The timestamp from the `X-Signature-Timestamp` header\n * @param clientPublicKey - The public key from the Discord developer dashboard\n * @returns Whether or not validation was successful\n */\nexport async function verifyKey(\n rawBody: Uint8Array | ArrayBuffer | Buffer | string,\n signature: string | null,\n timestamp: string | null,\n clientPublicKey: string | CryptoKey\n): Promise<boolean> {\n if (!signature || !timestamp) return false;\n try {\n const timestampData = valueToUint8Array(timestamp);\n const bodyData = valueToUint8Array(rawBody);\n const message = concatUint8Arrays(timestampData, bodyData);\n const publicKey =\n typeof clientPublicKey === \"string\"\n ? await subtleCrypto.importKey(\n \"raw\",\n valueToUint8Array(clientPublicKey, \"hex\").buffer as BufferSource,\n {\n name: \"ed25519\",\n },\n false,\n [\"verify\"]\n )\n : clientPublicKey;\n const isValid = await subtleCrypto.verify(\n {\n name: \"ed25519\",\n },\n publicKey,\n valueToUint8Array(signature, \"hex\").buffer as ArrayBuffer,\n message.buffer as ArrayBuffer\n );\n return isValid;\n } catch (_ex) {\n return false;\n }\n}\n\nexport async function verifyDiscordRequest<T extends APIInteraction | APIWebhookEvent>(\n req: HonoRequest<any, any>,\n discordPublicKey: string | CryptoKey\n) {\n const signature = req.header(\"x-signature-ed25519\");\n const timestamp = req.header(\"x-signature-timestamp\");\n const body = await (await cloneRawRequest(req)).text();\n const isValidRequest = signature && timestamp && (await verifyKey(body, signature, timestamp, discordPublicKey));\n if (!isValidRequest) {\n return { isValid: false } as const;\n }\n\n return { data: JSON.parse(body) as T, isValid: true } as const;\n}\n","// From discord.js\ninterface Colors {\n /** 0x1ABC9C | rgb(26,188,156) */\n Aqua: number;\n /** 0x3498DB | rgb(52,152,219) */\n Blue: number;\n /** 0x5865F2 | rgb(88,101,242) */\n Blurple: number;\n /** 0x11806A | rgb(17,128,106) */\n DarkAqua: number;\n /** 0x206694 | rgb(32,102,148) */\n DarkBlue: number;\n /** 0x2C2F33 | rgb(44,47,51) */\n DarkButNotBlack: number;\n /** 0x7F8C8D | rgb(127,140,141) */\n DarkerGrey: number;\n /** 0xC27C0E | rgb(194,124,14) */\n DarkGold: number;\n /** 0x1F8B4C | rgb(31,139,76) */\n DarkGreen: number;\n /** 0x979C9F | rgb(151,156,159) */\n DarkGrey: number;\n /** 0x2C3E50 | rgb(44,62,80) */\n DarkNavy: number;\n /** 0xA84300 | rgb(168,67,0) */\n DarkOrange: number;\n /** 0x71368A | rgb(113,54,138) */\n DarkPurple: number;\n /** 0x992D22 | rgb(153,45,34) */\n DarkRed: number;\n /** 0xAD1457 | rgb(173,20,87) */\n DarkVividPink: number;\n /** 0x000000 | rgb(0,0,0) */\n Default: number;\n /** 0xEB459E | rgb(235,69,158) */\n Fuchsia: number;\n /** 0xF1C40F | rgb(241,196,15) */\n Gold: number;\n /** 0x57F287 | rgb(87,242,135) */\n Green: number;\n /** 0x95A5A6 | rgb(149,165,166) */\n Grey: number;\n /** 0x99AAb5 | rgb(153,170,181) */\n Greyple: number;\n /** 0xBCC0C0 | rgb(188,192,192) */\n LightGrey: number;\n /** 0xE91E63 | rgb(233,30,99) */\n LuminousVividPink: number;\n /** 0x34495E | rgb(52,73,94) */\n Navy: number;\n /** 0x23272A | rgb(35,39,42) */\n NotQuiteBlack: number;\n /** 0xE67E22 | rgb(230,126,34) */\n Orange: number;\n /** 0x9B59B6 | rgb(155,89,182) */\n Purple: number;\n /** 0xED4245 | rgb(237,66,69) */\n Red: number;\n /** 0xFFFFFF | rgb(255,255,255) */\n White: number;\n /** 0xFEE75C | rgb(254,231,92) */\n Yellow: number;\n}\n\nexport const Colors: Colors = {\n Aqua: 0x1abc9c,\n Blue: 0x3498db,\n Blurple: 0x5865f2,\n DarkAqua: 0x11806a,\n DarkBlue: 0x206694,\n DarkButNotBlack: 0x2c2f33,\n DarkerGrey: 0x7f8c8d,\n DarkGold: 0xc27c0e,\n DarkGreen: 0x1f8b4c,\n DarkGrey: 0x979c9f,\n DarkNavy: 0x2c3e50,\n DarkOrange: 0xa84300,\n DarkPurple: 0x71368a,\n DarkRed: 0x992d22,\n DarkVividPink: 0xad1457,\n Default: 0x000000,\n Fuchsia: 0xeb459e,\n Gold: 0xf1c40f,\n Green: 0x57f287,\n Grey: 0x95a5a6,\n Greyple: 0x99aab5,\n LightGrey: 0xbcc0c0,\n LuminousVividPink: 0xe91e63,\n Navy: 0x34495e,\n NotQuiteBlack: 0x23272a,\n Orange: 0xe67e22,\n Purple: 0x9b59b6,\n Red: 0xed4245,\n White: 0xffffff,\n Yellow: 0xfee75c,\n};\n","import { AnyHandler } from \"@handlers/index\";\nimport { API } from \"@discordjs/core/http-only\";\nimport { REST } from \"@discordjs/rest\";\nimport { FlatOrNestedArray } from \"../types\";\nimport type { RESTPostAPIApplicationCommandsJSONBody, RESTPostAPIApplicationGuildCommandsJSONBody } from \"discord-api-types/v10\";\n\n/**\n * Registers application commands (Slash and Context Menus) with Discord's API.\n *\n * This function flattens the provided handlers, separates global from guild-specific\n * commands, and performs a bulk overwrite for both.\n *\n * @param token - The Discord Bot token.\n * @param applicationId - The Discord Application ID.\n * @param handlers - A rest parameter of handlers or arrays of handlers to register.\n *\n * @throws {Error} If the API request to Discord fails.\n */\nexport async function registerCommands(\n token: string | undefined,\n applicationId: string | undefined,\n ...handlers: FlatOrNestedArray<AnyHandler>\n) {\n const flatCommands = handlers.flat(Infinity) as AnyHandler[];\n const { globalCommands, guildCommands } = flatCommands\n .map((handler) => {\n if (handler.handlerType === \"slash\" || handler.handlerType === \"context\") {\n return handler;\n }\n return undefined;\n })\n .filter((cmd) => cmd !== undefined)\n .reduce(\n (acc, cmd) => {\n if (cmd.isGuildCommand()) {\n for (const guildId of cmd.guildIds.values()) {\n if (!acc.guildCommands[guildId]) {\n acc.guildCommands[guildId] = [];\n }\n acc.guildCommands[guildId].push(cmd.toJSON());\n }\n } else {\n acc.globalCommands.push(cmd.toJSON());\n }\n return acc;\n },\n {\n globalCommands: [] as RESTPostAPIApplicationCommandsJSONBody[],\n guildCommands: {} as Record<string, RESTPostAPIApplicationGuildCommandsJSONBody[]>,\n }\n );\n\n if (!token || !applicationId) {\n console.warn(\"Token or Application ID not provided, skipping command registration.\");\n return;\n }\n\n const api = new API(new REST({ version: \"10\" }).setToken(token));\n try {\n await api.applicationCommands.bulkOverwriteGlobalCommands(applicationId, globalCommands);\n console.log(`---- ✅ Successfully registered ${globalCommands.length} global commands ----`);\n } catch (error) {\n console.error(\"---- ❌ Error registering global commands ----\");\n throw error;\n }\n\n if (Object.keys(guildCommands).length === 0) {\n return;\n }\n\n const guildCommandsArray = Object.entries(guildCommands).map(([guildId, commands]) => ({ guildId, commands }));\n\n for (const { guildId, commands } of guildCommandsArray) {\n try {\n await api.applicationCommands.bulkOverwriteGuildCommands(applicationId, guildId, commands);\n console.log(`---- ✅ Successfully registered ${commands.length} guild commands for guild ${guildId} ----`);\n } catch (error) {\n console.error(`---- ❌ Error registering guild commands for guild ${guildId} ----`);\n throw error;\n }\n }\n}\n","export * from \"@utils/Colors\";\nexport * from \"@utils/registerCommands\";\n\n/**\n * Parse a custom ID string into its parts.\n *\n * Supports two modes:\n * - onlyPrefix = true: returns the prefix string before the first '/' or '?'.\n * - onlyPrefix = false (default): returns an object with parsed pieces.\n *\n * Expected customId shapes:\n * - \"prefix/component/other/path?param1/param2\"\n * - \"prefix?param1/param2\"\n *\n * @param customId - The custom ID to parse.\n * @param onlyPrefix - If true, only return the prefix string (default: false).\n * @returns If onlyPrefix is true: string (the prefix). Otherwise an object with:\n * - compPath: string[] (full path split by '/'),\n * - prefix: string (first item of compPath),\n * - lastPathItem: string (last item of compPath),\n * - component: string | null (second item of compPath or null),\n * - params: string[] (params split by '/'; empty array when none),\n * - firstParam: string | null,\n * - lastParam: string | null\n *\n * @example\n * parseCustomId(\"modal/user/profile?123/abc\")\n * // => { compPath: [\"modal\",\"user\",\"profile\"], prefix: \"modal\", ... params: [\"123\",\"abc\"], ... }\n *\n * parseCustomId(\"button/click\", true)\n * // => \"button\"\n */\nexport function parseCustomId(customId: string, onlyPrefix: true): string;\nexport function parseCustomId(\n customId: string,\n onlyPrefix?: false\n): {\n compPath: string[];\n prefix: string;\n lastPathItem: string;\n component: string | null;\n params: string[];\n firstParam: string | null;\n lastParam: string | null;\n};\nexport function parseCustomId(customId: string, onlyPrefix: boolean = false) {\n if (onlyPrefix) {\n const match = customId.match(/^(.+?)(\\/|\\?)/i);\n return match ? match[1] : customId;\n }\n const [path, params] = customId.split(\"?\") as [string, string | undefined];\n const pathS = path.split(\"/\");\n const parms = params?.split(\"/\") || [];\n return {\n compPath: pathS,\n prefix: pathS[0],\n lastPathItem: pathS[pathS.length - 1],\n component: pathS[1] || null,\n params: parms || [],\n firstParam: parms[0] || null,\n lastParam: parms[parms.length - 1] || null,\n };\n}\n","import { APIUserApplicationCommandInteraction, APIUser, ApplicationCommandType } from \"discord-api-types/v10\";\nimport { API } from \"@discordjs/core/http-only\";\nimport { BaseInteractionContext } from \"../types\";\nimport { CommandInteraction } from \"./CommandInteraction\";\n\nclass UserContextInteraction<Context extends BaseInteractionContext = BaseInteractionContext> extends CommandInteraction<\n ApplicationCommandType.User,\n Context\n> {\n public readonly targetUser: APIUser;\n\n constructor(api: API, interaction: APIUserApplicationCommandInteraction, c: Context) {\n super(api, interaction, c);\n this.targetUser = interaction.data.resolved.users[interaction.data.target_id];\n }\n}\n\nexport { UserContextInteraction };\n","import { APIMessage, APIMessageApplicationCommandInteraction, ApplicationCommandType } from \"discord-api-types/v10\";\nimport { API } from \"@discordjs/core/http-only\";\nimport { BaseInteractionContext } from \"../types\";\nimport { CommandInteraction } from \"./CommandInteraction\";\n\nclass MessageContextInteraction<Context extends BaseInteractionContext = BaseInteractionContext> extends CommandInteraction<\n ApplicationCommandType.Message,\n Context\n> {\n public readonly targetMessage: APIMessage;\n\n constructor(api: API, interaction: APIMessageApplicationCommandInteraction, c: Context) {\n super(api, interaction, c);\n this.targetMessage = interaction.data.resolved.messages[interaction.data.target_id];\n }\n}\n\nexport { MessageContextInteraction };\n","import {\n APIAttachment,\n APIInteractionDataResolved,\n APIInteractionDataResolvedChannel,\n APIInteractionDataResolvedGuildMember,\n APIModalSubmitCheckboxComponent,\n APIModalSubmitCheckboxGroupComponent,\n APIModalSubmitFileUploadComponent,\n APIModalSubmitRadioGroupComponent,\n APIRole,\n APIUser,\n ComponentType,\n ModalSubmitLabelComponent,\n ModalSubmitTextDisplayComponent,\n Snowflake,\n} from \"discord-api-types/v10\";\nimport { APIInteractionDataResolvedCollections, ResolvedSelectedGuildMember } from \"../types\";\nimport { Collection, ReadonlyCollection } from \"@discordjs/collection\";\n\nexport interface BaseModalData<Type extends ComponentType> {\n id?: number;\n type: Type;\n}\n\nexport interface TextInputModalData extends BaseModalData<ComponentType.TextInput> {\n custom_id: string;\n value: string;\n}\n\nexport interface SelectMenuModalData extends BaseModalData<\n | ComponentType.ChannelSelect\n | ComponentType.MentionableSelect\n | ComponentType.RoleSelect\n | ComponentType.StringSelect\n | ComponentType.UserSelect\n> {\n custom_id: string;\n channels?: ReadonlyCollection<Snowflake, APIInteractionDataResolvedChannel>;\n members?: ReadonlyCollection<Snowflake, APIInteractionDataResolvedGuildMember>;\n roles?: ReadonlyCollection<Snowflake, APIRole>;\n users?: ReadonlyCollection<Snowflake, APIUser>;\n /**\n * The raw values selected by the user.\n */\n values: readonly string[];\n}\n\n// Technically, we had to add file uploads too, but we ain't using them anyway\ntype APIModalData =\n | TextInputModalData\n | SelectMenuModalData\n | APIModalSubmitCheckboxComponent\n | APIModalSubmitCheckboxGroupComponent\n | APIModalSubmitRadioGroupComponent\n | APIModalSubmitFileUploadComponent;\n\nexport class ModalComponentResolver {\n private _resolved: APIInteractionDataResolvedCollections;\n private hoistedComponents: Collection<string, APIModalData>;\n\n constructor(\n private components: (ModalSubmitLabelComponent | ModalSubmitTextDisplayComponent)[],\n resolved?: APIInteractionDataResolved\n ) {\n this._resolved = Object.keys(resolved ?? {}).reduce((acc, key) => {\n const resolvedData = resolved?.[key as keyof APIInteractionDataResolved];\n if (key === \"members\") {\n // get users and combine them with members for easy access; a user is expected to ALWAYS be present if a member is\n const users = resolved?.users ? new Collection(Object.entries(resolved.users)) : new Collection();\n const members = resolvedData ? new Collection(Object.entries(resolvedData)) : new Collection();\n const combined = new Collection([...members.entries()].map(([id, member]) => [id, { ...member, user: users.get(id)! }]));\n acc[key] = combined;\n return acc;\n }\n const collection = new Collection(resolvedData ? Object.entries(resolvedData) : []);\n acc[key] = collection;\n return acc;\n }, {} as any);\n\n this.hoistedComponents = this.components.reduce(\n (accumulator, next) => {\n // For label components\n if (next.type === ComponentType.Label) {\n accumulator.set(next.component.custom_id, next.component);\n }\n\n return accumulator;\n },\n new Collection() as Collection<string, APIModalData>\n );\n }\n\n public get data() {\n return this.hoistedComponents.map((component) => component);\n }\n\n /**\n * Checks if a component with the given custom ID exists in the modal.\n * @param custom_id The custom ID of the component to check for.\n * @returns True if a component with the given custom ID exists, false otherwise.\n */\n fieldExists(custom_id: string): boolean {\n return this.hoistedComponents.has(custom_id);\n }\n\n getComponent(custom_id: string): APIModalData {\n const component = this.hoistedComponents.get(custom_id);\n\n if (!component) throw new TypeError(\"No component found with the provided custom_id.\");\n\n return component;\n }\n\n /**\n * Gets the value of a text input component.\n *\n * @param custom_id The custom ID of the component.\n * @param required Whether to throw an error if the component is not found or not a text input.\n * @returns The value of the text input, or null if not set and not required.\n */\n getString(custom_id: string, required?: boolean): string | null;\n getString(custom_id: string, required: true): string;\n getString(custom_id: string, required: boolean = false): string | null {\n const component = this.getComponent(custom_id);\n if (component.type !== ComponentType.TextInput) {\n throw new TypeError(\"Component is not a text input\", { cause: { custom_id, type: component.type } });\n }\n return component.value;\n }\n\n /**\n * Gets the selected values of a select menu component.\n *\n * @param custom_id The custom ID of the component.\n * @param required Whether to throw an error if the component is not found or not a select menu.\n * @returns The selected values, or null if not set and not required.\n */\n getSelectedValues(custom_id: string, required?: boolean): readonly string[] | null;\n getSelectedValues(custom_id: string, required: true): readonly string[];\n getSelectedValues(custom_id: string, required: boolean = false): readonly string[] | null {\n const component = this.getComponent(custom_id);\n if (!(\"values\" in component)) {\n throw new TypeError(\"Component is not a select menu\", { cause: { custom_id, type: component.type } });\n }\n return component.values;\n }\n\n /**\n * Gets the selected channels from a channel select menu.\n *\n * @param custom_id The custom ID of the component.\n * @param required Whether to throw an error if the component is not found or not a channel select.\n * @returns The selected channels, or null if not set and not required.\n */\n getSelectedChannels(custom_id: string, required?: boolean): Collection<string, APIInteractionDataResolvedChannel> | null;\n getSelectedChannels(custom_id: string, required: true): Collection<string, APIInteractionDataResolvedChannel>;\n getSelectedChannels(\n custom_id: string,\n required: boolean = false\n ): Collection<string, APIInteractionDataResolvedChannel> | null {\n const component = this.getComponent(custom_id);\n if (component.type !== ComponentType.ChannelSelect) {\n throw new TypeError(\"Component is not a channel select\", { cause: { custom_id, type: component.type } });\n }\n const values = component.values;\n const channels = values.map((id) => this._resolved.channels?.get(id)).filter(Boolean) as APIInteractionDataResolvedChannel[];\n return channels.length > 0\n ? new Collection(channels.map((channel) => [channel.id, channel]))\n : required\n ? new Collection()\n : null;\n }\n\n /**\n * Gets the selected users from a user select menu.\n *\n * @param custom_id The custom ID of the component.\n * @param required Whether to throw an error if the component is not found or not a user select.\n * @returns The selected users, or null if not set and not required.\n */\n getSelectedUsers(custom_id: string, required?: boolean): Collection<string, APIUser> | null;\n getSelectedUsers(custom_id: string, required: true): Collection<string, APIUser>;\n getSelectedUsers(custom_id: string, required: boolean = false): Collection<string, APIUser> | null {\n const component = this.getComponent(custom_id);\n if (component.type !== ComponentType.UserSelect) {\n throw new TypeError(\"Component is not a user select\", { cause: { custom_id, type: component.type } });\n }\n const values = component.values;\n const users = values.map((id) => this._resolved.users?.get(id)).filter(Boolean) as APIUser[];\n return users.length > 0 ? new Collection(users.map((user) => [user.id, user])) : required ? new Collection() : null;\n }\n\n /**\n * Gets the selected members from a user select menu (if in guild).\n *\n * @param custom_id The custom ID of the component.\n * @param required Whether to throw an error if the component is not found or not a user select.\n * @returns The selected members, or null if not set and not required.\n */\n getSelectedMembers(custom_id: string, required?: boolean): Collection<string, ResolvedSelectedGuildMember> | null;\n getSelectedMembers(custom_id: string, required: true): Collection<string, ResolvedSelectedGuildMember>;\n getSelectedMembers(custom_id: string, required: boolean = false): Collection<string, ResolvedSelectedGuildMember> | null {\n const component = this.getComponent(custom_id);\n if (component.type !== ComponentType.UserSelect) {\n throw new TypeError(\"Component is not a user select\", { cause: { custom_id, type: component.type } });\n }\n const values = component.values;\n const members = values.map((id) => this._resolved.members?.get(id)).filter(Boolean) as ResolvedSelectedGuildMember[];\n return members.length > 0\n ? new Collection(members.map((member) => [member.user.id, member]))\n : required\n ? new Collection()\n : null;\n }\n\n /**\n * Gets the selected roles from a role select menu.\n *\n * @param custom_id The custom ID of the component.\n * @param required Whether to throw an error if the component is not found or not a role select.\n * @returns The selected roles, or null if not set and not required.\n */\n getSelectedRoles(custom_id: string, required?: boolean): Collection<string, APIRole> | null;\n getSelectedRoles(custom_id: string, required: true): Collection<string, APIRole>;\n getSelectedRoles(custom_id: string, required: boolean = false): Collection<string, APIRole> | null {\n const component = this.getComponent(custom_id);\n if (component.type !== ComponentType.RoleSelect) {\n throw new TypeError(\"Component is not a role select\", { cause: { custom_id, type: component.type } });\n }\n const values = component.values;\n const roles = values.map((id) => this._resolved.roles?.get(id)).filter(Boolean) as APIRole[];\n return roles.length > 0 ? new Collection(roles.map((role) => [role.id, role])) : required ? new Collection() : null;\n }\n\n /**\n * Gets the selected mentionables from a mentionable select menu.\n *\n * @param custom_id The custom ID of the component.\n * @param required Whether to throw an error if the component is not found or not a mentionable select.\n * @returns The selected mentionables (users, members, or roles), or null if not set and not required.\n */\n getSelectedMentionables(custom_id: string, required?: boolean): (ResolvedSelectedGuildMember | APIUser | APIRole)[] | null;\n getSelectedMentionables(custom_id: string, required: true): (ResolvedSelectedGuildMember | APIUser | APIRole)[];\n getSelectedMentionables(\n custom_id: string,\n required: boolean = false\n ): (ResolvedSelectedGuildMember | APIUser | APIRole)[] | null {\n const component = this.getComponent(custom_id);\n if (component.type !== ComponentType.MentionableSelect) {\n throw new TypeError(\"Component is not a mentionable select\", { cause: { custom_id, type: component.type } });\n }\n const values = component.values;\n const mentionables: (ResolvedSelectedGuildMember | APIUser | APIRole)[] = [];\n for (const id of values) {\n const member = this._resolved.members?.get(id);\n if (member) mentionables.push(member);\n else {\n const user = this._resolved.users?.get(id);\n if (user) mentionables.push(user);\n else {\n const role = this._resolved.roles?.get(id);\n if (role) mentionables.push(role);\n }\n }\n }\n return mentionables.length > 0 ? mentionables : required ? [] : null;\n }\n\n getFiles(custom_id: string, required?: boolean): Collection<string, APIAttachment> | null;\n getFiles(custom_id: string, required: true): Collection<string, APIAttachment>;\n getFiles(custom_id: string, required?: boolean): Collection<string, APIAttachment> | null {\n const component = this.getComponent(custom_id);\n if (component.type !== ComponentType.FileUpload) {\n throw new TypeError(\"Component is not a file upload\", { cause: { custom_id, type: component.type } });\n }\n const values = component.values;\n const attachments = values.map((id) => this._resolved.attachments?.get(id)).filter(Boolean) as APIAttachment[];\n if (attachments.length === 0) {\n return required ? new Collection() : null;\n }\n return new Collection(attachments.map((attachment) => [attachment.id, attachment]));\n }\n\n getRadioGroupValue(custom_id: string, required?: boolean): string | null;\n getRadioGroupValue(custom_id: string, required: true): string;\n getRadioGroupValue(custom_id: string, required?: boolean): string | null {\n const component = this.getComponent(custom_id);\n if (component.type !== ComponentType.RadioGroup) {\n throw new TypeError(\"Component is not a radio group\", { cause: { custom_id, type: component.type } });\n }\n return component.value ?? (required ? \"\" : null);\n }\n\n getCheckboxGroupValues(custom_id: string, required?: boolean): string[] | null;\n getCheckboxGroupValues(custom_id: string, required: true): string[];\n getCheckboxGroupValues(custom_id: string, required?: boolean): string[] | null {\n const component = this.getComponent(custom_id);\n if (component.type !== ComponentType.CheckboxGroup) {\n throw new TypeError(\"Component is not a checkbox group\", { cause: { custom_id, type: component.type } });\n }\n return component.values.length > 0 ? component.values : required ? [] : null;\n }\n\n getCheckboxValue(custom_id: string, required?: boolean): boolean | null;\n getCheckboxValue(custom_id: string, required: true): boolean;\n getCheckboxValue(custom_id: string, required?: boolean): boolean | null {\n const component = this.getComponent(custom_id);\n if (component.type !== ComponentType.Checkbox) {\n throw new TypeError(\"Component is not a checkbox\", { cause: { custom_id, type: component.type } });\n }\n return component.value ?? (required ? false : null);\n }\n\n getAllComponents(): APIModalData[] {\n return this.hoistedComponents.map((component) => component);\n }\n}\n","import {\n APIMessage,\n APIModalSubmitInteraction,\n InteractionType,\n ModalSubmitLabelComponent,\n ModalSubmitTextDisplayComponent,\n} from \"discord-api-types/v10\";\nimport { API } from \"@discordjs/core/http-only\";\nimport { ModalComponentResolver } from \"@resolvers/ModalComponentResolver\";\nimport { BaseInteraction } from \"./BaseInteraction\";\nimport { BaseInteractionContext } from \"../types\";\n\nclass ModalInteraction<Context extends BaseInteractionContext = BaseInteractionContext> extends BaseInteraction<\n InteractionType.ModalSubmit,\n Context\n> {\n public readonly fields: ModalComponentResolver;\n public readonly message?: APIMessage;\n public readonly customId: string;\n\n constructor(api: API, interaction: APIModalSubmitInteraction, c: Context) {\n super(api, interaction, c);\n this.customId = interaction.data.custom_id;\n this.fields = new ModalComponentResolver(\n interaction.data.components as (ModalSubmitLabelComponent | ModalSubmitTextDisplayComponent)[],\n interaction.data.resolved\n );\n if (\"message\" in interaction && interaction.message) {\n this.message = interaction.message;\n }\n }\n}\n\nexport { ModalInteraction };\n","import {\n APIApplicationCommandAutocompleteInteraction,\n APIApplicationCommandOptionChoice,\n InteractionType,\n type APIChatInputApplicationCommandInteraction,\n} from \"discord-api-types/v10\";\nimport { CommandInteractionOptionResolver } from \"@resolvers/CommandOptionResolver\";\nimport { API } from \"@discordjs/core/http-only\";\nimport { BaseInteraction } from \"./BaseInteraction\";\nimport { BaseInteractionContext } from \"../types\";\n\nclass AutocompleteInteraction<Context extends BaseInteractionContext = BaseInteractionContext> extends BaseInteraction<\n InteractionType.ApplicationCommandAutocomplete,\n Context\n> {\n public readonly options: CommandInteractionOptionResolver;\n public responded = false;\n\n constructor(api: API, interaction: APIApplicationCommandAutocompleteInteraction, c: Context) {\n super(api, interaction, c);\n this.options = new CommandInteractionOptionResolver(interaction.data.options, interaction.data.resolved);\n }\n\n get commandName() {\n return this.raw.data.name;\n }\n\n get commandId() {\n return this.raw.data.id;\n }\n\n async respond(choices: APIApplicationCommandOptionChoice[]) {\n await this.api.interactions.createAutocompleteResponse(this.id, this.token, { choices });\n this.responded = true;\n }\n}\n\nexport { AutocompleteInteraction };\n","import type { ChatInputCommandInteraction } from \"@ctx/ChatInputInteraction\";\nimport type { AutocompleteInteraction } from \"@ctx/AutocompleteInteraction\";\nimport { SlashCommandBuilder } from \"@discordjs/builders\";\nimport type {\n SlashCommandBooleanOption,\n SlashCommandUserOption,\n SlashCommandChannelOption,\n SlashCommandRoleOption,\n SlashCommandAttachmentOption,\n SlashCommandMentionableOption,\n SlashCommandStringOption,\n SlashCommandIntegerOption,\n SlashCommandNumberOption,\n SlashCommandSubcommandBuilder,\n SlashCommandSubcommandGroupBuilder,\n} from \"@discordjs/builders\";\nimport type { BaseInteractionContext } from \"../types\";\n\n/**\n * Handler for chat input commands with optional autocomplete support\n */\nexport class SlashCommandHandler<Context extends BaseInteractionContext = BaseInteractionContext> extends SlashCommandBuilder {\n readonly handlerType = \"slash\";\n private handlerFn?: (interaction: ChatInputCommandInteraction<Context>) => Promise<any> | any;\n private autocompleteFn?: (interaction: AutocompleteInteraction<Context>) => Promise<any> | any;\n /**\n * Set of guild IDs where this command is registered (empty for global commands)\n */\n readonly guildIds = new Set<string>();\n\n isGuildCommand(): boolean {\n return this.guildIds.size > 0;\n }\n\n setGuildIds(guildIds: string[]): this {\n this.guildIds.clear();\n for (const guildId of guildIds) {\n this.guildIds.add(guildId);\n }\n return this;\n }\n\n addGuildIds(...guildIds: string[]): this {\n for (const guildId of guildIds) {\n this.guildIds.add(guildId);\n }\n return this;\n }\n\n removeGuildIds(...guildIds: string[]): this {\n for (const guildId of guildIds) {\n this.guildIds.delete(guildId);\n }\n return this;\n }\n\n /**\n * Adds the command handler function.\n *\n * @param handler The function to handle the command interaction\n * @returns The current SlashCommandHandler instance\n */\n public addHandler(\n handler: (interaction: ChatInputCommandInteraction<Context>) => Promise<any> | any\n ): SlashCommandHandler<Context> {\n this.handlerFn = handler;\n return this;\n }\n\n /**\n * Adds the autocomplete handler function.\n *\n * @param handler The function to handle the autocomplete interaction\n * @returns The current SlashCommandHandler instance\n */\n public addAutocompleteHandler(\n handler: (interaction: AutocompleteInteraction<Context>) => Promise<any> | any\n ): SlashCommandHandler<Context> {\n this.autocompleteFn = handler;\n return this;\n }\n\n /**\n * Executes the command handler\n */\n async execute(interaction: ChatInputCommandInteraction<Context>): Promise<void> {\n if (!this.handlerFn) {\n throw new Error(`Command \"${this.name}\" does not have a handler`);\n }\n await this.handlerFn(interaction);\n }\n\n /**\n * Executes the autocomplete handler if it exists\n */\n async executeAutocomplete(interaction: AutocompleteInteraction<Context>): Promise<void> {\n if (this.autocompleteFn == undefined) {\n throw new Error(`Command \"${this.name}\" does not have an autocomplete handler`);\n }\n await this.autocompleteFn(interaction);\n }\n\n /**\n * Override option/subcommand adders so they return `this` (the handler),\n * preserving chaining when options/subcommands are added.\n */\n addBooleanOption(input: SlashCommandBooleanOption | ((builder: SlashCommandBooleanOption) => SlashCommandBooleanOption)): this {\n super.addBooleanOption(input);\n return this;\n }\n\n addUserOption(input: SlashCommandUserOption | ((builder: SlashCommandUserOption) => SlashCommandUserOption)): this {\n super.addUserOption(input);\n return this;\n }\n\n addChannelOption(input: SlashCommandChannelOption | ((builder: SlashCommandChannelOption) => SlashCommandChannelOption)): this {\n super.addChannelOption(input);\n return this;\n }\n\n addRoleOption(input: SlashCommandRoleOption | ((builder: SlashCommandRoleOption) => SlashCommandRoleOption)): this {\n super.addRoleOption(input);\n return this;\n }\n\n addAttachmentOption(\n input: SlashCommandAttachmentOption | ((builder: SlashCommandAttachmentOption) => SlashCommandAttachmentOption)\n ): this {\n super.addAttachmentOption(input);\n return this;\n }\n\n addMentionableOption(\n input: SlashCommandMentionableOption | ((builder: SlashCommandMentionableOption) => SlashCommandMentionableOption)\n ): this {\n super.addMentionableOption(input);\n return this;\n }\n\n addStringOption(input: SlashCommandStringOption | ((builder: SlashCommandStringOption) => SlashCommandStringOption)): this {\n super.addStringOption(input);\n return this;\n }\n\n addIntegerOption(input: SlashCommandIntegerOption | ((builder: SlashCommandIntegerOption) => SlashCommandIntegerOption)): this {\n super.addIntegerOption(input);\n return this;\n }\n\n addNumberOption(input: SlashCommandNumberOption | ((builder: SlashCommandNumberOption) => SlashCommandNumberOption)): this {\n super.addNumberOption(input);\n return this;\n }\n\n addSubcommand(\n input: SlashCommandSubcommandBuilder | ((sub: SlashCommandSubcommandBuilder) => SlashCommandSubcommandBuilder)\n ): this {\n super.addSubcommand(input);\n return this;\n }\n\n addSubcommandGroup(\n input:\n | SlashCommandSubcommandGroupBuilder\n | ((group: SlashCommandSubcommandGroupBuilder) => SlashCommandSubcommandGroupBuilder)\n ): this {\n super.addSubcommandGroup(input);\n return this;\n }\n}\n","import { ContextMenuCommandBuilder } from \"@discordjs/builders\";\nimport { MessageContextInteraction } from \"@ctx/MessageContextCommandInteraction\";\nimport { UserContextInteraction } from \"@ctx/UserContextCommandInteraction\";\nimport { BaseInteractionContext, ContextCommandType } from \"../types\";\n\nexport class ContextCommandHandler<\n Context extends BaseInteractionContext = BaseInteractionContext,\n T extends ContextCommandType = ContextCommandType,\n InteractionData = T extends ContextCommandType.User ? UserContextInteraction<Context> : MessageContextInteraction<Context>,\n> extends ContextMenuCommandBuilder {\n constructor(public readonly commandType: T) {\n super();\n this.setType(commandType as any); // ContextMenuCommandType is a type, not an enum so the values of the enum ContextCommandType isn't assignable to it directly\n }\n\n readonly handlerType = \"context\";\n private handlerFn?: (interaction: InteractionData) => Promise<any> | any;\n /**\n * Set of guild IDs where this command is registered (empty for global commands)\n */\n readonly guildIds = new Set<string>();\n\n isGuildCommand(): boolean {\n return this.guildIds.size > 0;\n }\n\n setGuildIds(guildIds: string[]): this {\n this.guildIds.clear();\n for (const guildId of guildIds) {\n this.guildIds.add(guildId);\n }\n return this;\n }\n\n addGuildIds(...guildIds: string[]): this {\n for (const guildId of guildIds) {\n this.guildIds.add(guildId);\n }\n return this;\n }\n\n removeGuildIds(...guildIds: string[]): this {\n for (const guildId of guildIds) {\n this.guildIds.delete(guildId);\n }\n return this;\n }\n\n public addHandler(\n handler: (interaction: InteractionData) => Promise<any> | any\n ): ContextCommandHandler<Context, T, InteractionData> {\n this.handlerFn = handler;\n return this;\n }\n\n /**\n * Executes the command handler\n */\n async execute(interaction: InteractionData): Promise<void> {\n if (!this.handlerFn) {\n throw new Error(`Command \"${this.name}\" does not have a handler`);\n }\n await this.handlerFn(interaction);\n }\n}\n","import { parseCustomId } from \"@utils/index\";\nimport { BaseInteractionContext, MessageComponentInteractionObj, MessageComponentType } from \"../types\";\n\n/**\n * Handler for message components (buttons, select menus) based on custom ID prefix\n */\nexport class ComponentHandler<\n Context extends BaseInteractionContext = BaseInteractionContext,\n CType extends MessageComponentType = MessageComponentType,\n> {\n readonly handlerType = \"component\";\n public readonly prefix: string;\n public readonly componentType: CType;\n private handlerFn?: (interaction: MessageComponentInteractionObj<Context, CType>) => Promise<any> | any;\n\n constructor(\n prefix: string,\n componentType: CType,\n handler?: (interaction: MessageComponentInteractionObj<Context, CType>) => Promise<any> | any\n ) {\n this.componentType = componentType;\n if (!prefix || typeof prefix !== \"string\") {\n throw new TypeError(\"Component handler prefix must be a non-empty string\");\n }\n\n this.prefix = prefix;\n if (handler) this.handlerFn = handler;\n }\n\n addHandler(\n handler: (interaction: MessageComponentInteractionObj<Context, CType>) => Promise<any> | any\n ): ComponentHandler<Context, CType> {\n this.handlerFn = handler;\n return this;\n }\n\n /**\n * Executes the component handler\n */\n async execute(interaction: MessageComponentInteractionObj<Context, CType>): Promise<void> {\n if (!this.handlerFn) {\n throw new Error(`Component handler with prefix \"${this.prefix}\" does not have a handler`);\n }\n await this.handlerFn(interaction);\n }\n\n /**\n * Checks if this handler matches the given custom ID\n */\n matches(customId: string): boolean {\n const prefix = parseCustomId(customId, true);\n return prefix === this.prefix;\n }\n}\n","import type { ModalInteraction } from \"@ctx/ModalInteraction\";\nimport { parseCustomId } from \"@utils/index\";\nimport type { BaseInteractionContext } from \"../types\";\n\n/**\n * Handler for modal submits based on custom ID prefix\n */\nexport class ModalHandler<Context extends BaseInteractionContext = BaseInteractionContext> {\n readonly handlerType = \"modal\";\n public readonly prefix: string;\n private handlerFn?: (interaction: ModalInteraction<Context>) => Promise<any> | any;\n\n constructor(prefix: string, handler?: (interaction: ModalInteraction<Context>) => Promise<any> | any) {\n if (!prefix || typeof prefix !== \"string\") {\n throw new TypeError(\"Modal handler prefix must be a non-empty string\");\n }\n\n this.prefix = prefix;\n if (handler) this.handlerFn = handler;\n }\n\n addHandler(handler: (interaction: ModalInteraction<Context>) => Promise<any> | any): ModalHandler<Context> {\n this.handlerFn = handler;\n return this;\n }\n\n /**\n * Executes the modal handler\n */\n async execute(interaction: ModalInteraction<Context>): Promise<void> {\n if (!this.handlerFn) {\n throw new Error(`Modal handler with prefix \"${this.prefix}\" does not have a handler`);\n }\n await this.handlerFn(interaction);\n }\n\n /**\n * Checks if this handler matches the given custom ID\n */\n matches(customId: string): boolean {\n const prefix = parseCustomId(customId, true);\n return prefix === this.prefix;\n }\n}\n","import { Hono, type Context } from \"hono\";\nimport { APIWebhookEvent, ApplicationWebhookEventType, ApplicationWebhookType } from \"discord-api-types/v10\";\nimport type { APIWebhookEventPayload, WebhookEventHandlerFnForWorkers, WebhookEventHandlerFnWithRequest } from \"$types/webhook\";\nimport { verifyDiscordRequest } from \"@utils/discordVerify\";\n\ntype BlankVariables = Record<string, any>;\n\n/**\n * Represents a webhook event handler to be used by an Honocord instance or standalone fetch handler or Hono app.\n *\n * @template T - Discord webhook event type\n * @template Env - Environment bindings type\n * @template Variables - Additional context variables\n * @template ForWorker - Set to `true` for Cloudflare Workers mode (no return type required), `false` for standard mode (must return Response)\n * @template Data - Typed webhook event data\n */\nexport class WebhookEventHandler<\n T extends ApplicationWebhookEventType,\n Env extends { DISCORD_PUBLIC_KEY?: string } = {},\n Variables extends BlankVariables = BlankVariables,\n ForWorker extends boolean = false,\n Data extends APIWebhookEventPayload<T> = APIWebhookEventPayload<T>,\n> {\n readonly handlerType = \"webhook\";\n public readonly eventType: T;\n private handlerFn?: ForWorker extends true\n ? WebhookEventHandlerFnForWorkers<Data, Env, BlankVariables & { data: Data }>\n : WebhookEventHandlerFnWithRequest<Data, Env, BlankVariables & { data: Data }>;\n private app = new Hono<{ Bindings: Env; Variables: Omit<Variables, \"data\"> & { data: Data } }>();\n private isForWorker: boolean;\n\n constructor(eventType: T, forWorker?: ForWorker) {\n this.eventType = eventType;\n this.isForWorker = forWorker ?? false;\n }\n\n /**\n * Internal wrapper that handles Discord request verification and delegates to the user-defined handler.\n * This is used by the standalone `fetch` and `getApp()` methods.\n *\n * @private\n * @internal\n */\n private handlerWrapper = async (c: Context<{ Bindings: Env; Variables: BlankVariables & { data: Data } }>) => {\n if (!this.handlerFn) {\n console.error(\"No handler function defined for webhook event handler.\");\n return c.body(null, 500);\n } else if (!c.env.DISCORD_PUBLIC_KEY) {\n console.error(\"No Discord public key provided in environment variables.\");\n return c.body(null, 500);\n }\n\n // validate request body and type\n const { isValid, data } = await verifyDiscordRequest<APIWebhookEvent>(c.req, c.env.DISCORD_PUBLIC_KEY);\n if (!isValid || !data) {\n console.error(\"Invalid request signature or body.\");\n return c.body(null, 401);\n }\n\n if (data.type === ApplicationWebhookType.Ping) {\n return c.json({ type: ApplicationWebhookType.Ping }, 200);\n } else if (data.event.type !== this.eventType) {\n console.error(\n `Received event type ${data.event.type} does not match handler event type ${this.eventType}. How did this happen?`\n );\n return c.body(null, 400);\n }\n\n c.set(\"data\", data.event as Data);\n\n try {\n return await this.handlerFn(c);\n } catch (error) {\n console.error(\"Error executing webhook event handler:\", error);\n return c.body(null, 500);\n }\n };\n\n /**\n * Registers the handler function for this webhook event.\n *\n * @param handlerFn - The function to execute when this webhook event is received\n *\n * @example\n * Standard mode (must return Response):\n * ```typescript\n * const handler = new WebhookEventHandler(ApplicationWebhookEventType.MessageCreate);\n *\n * handler.addHandler(async (c) => {\n * const message = c.var.data;\n * console.log(\"Received message:\", message.content);\n * return c.json({ success: true }); // Must return Response\n * });\n * ```\n *\n * @example\n * Worker mode (no return required):\n * ```typescript\n * const handler = new WebhookEventHandler(ApplicationWebhookEventType.MessageCreate, true);\n *\n * handler.addHandler(async (c) => {\n * const message = c.var.data;\n * console.log(\"Received message:\", message.content);\n * // No return required in worker mode\n * });\n * ```\n */\n addHandler(\n handlerFn: ForWorker extends true\n ? WebhookEventHandlerFnForWorkers<Data, Env, BlankVariables & { data: Data }>\n : WebhookEventHandlerFnWithRequest<Data, Env, BlankVariables & { data: Data }>\n ) {\n this.handlerFn = handlerFn as any;\n if (!this.isForWorker) {\n this.app.post(\"/\", this.handlerWrapper);\n }\n return this;\n }\n\n /**\n * Execute the handler with pre-verified event data.\n *\n * **When to use:** This method is automatically called when the handler is registered with Honocord via `loadHandlers()`.\n * The Honocord instance handles request verification and ping events once, then delegates to this method.\n *\n * **You typically don't call this directly** - it's used internally by Honocord's `webhookHandler`.\n *\n * @param eventData - The pre-verified webhook event data\n * @param c - The Hono context\n * @returns The response from the handler function\n *\n * @example\n * ```typescript\n * // This is handled automatically when using Honocord:\n * const bot = new Honocord();\n * const handler = new WebhookEventHandler(ApplicationWebhookEventType.MessageCreate);\n * handler.addHandler(async (c) => c.json({ ok: true }));\n *\n * bot.loadHandlers(handler); // execute() is called internally\n * export default bot.getApp(); // POST /webhook\n * ```\n */\n async execute(eventData: Data, c: Context<{ Bindings: Env; Variables: BlankVariables & { data: Data } }>) {\n if (!this.handlerFn) {\n console.error(\"No handler function defined for webhook event handler.\");\n return c.body(null, 500);\n }\n\n c.set(\"data\", eventData);\n\n try {\n return await this.handlerFn(c);\n } catch (error) {\n console.error(\"Error executing webhook event handler:\", error);\n return c.body(null, 500);\n }\n }\n\n /**\n * Returns the fetch handler for standalone usage.\n *\n * **Note:** This method is only available in standard mode (`ForWorker = false`).\n * When using worker mode, this method returns `never` and will throw a runtime error.\n *\n * **When to use:** Use this when you want a self-contained webhook endpoint that handles its own\n * Discord request verification and ping events, independent of a Honocord instance.\n *\n * This is ideal for:\n * - Microservices architecture where webhooks are separate from interaction handlers\n * - Multiple bots with different webhook endpoints\n * - Testing individual webhook handlers in isolation\n * - Deploying webhooks on different paths or domains\n *\n * @returns A fetch-compatible handler function\n *\n * @example\n * ```typescript\n * import { Hono } from \"hono\";\n * import { WebhookEventHandler } from \"honocord/handlers\";\n * import { ApplicationWebhookEventType } from \"discord-api-types/v10\";\n *\n * const app = new Hono();\n *\n * // Standalone webhook handler with built-in verification\n * const messageHandler = new WebhookEventHandler(\n * ApplicationWebhookEventType.MessageCreate\n * );\n *\n * messageHandler.addHandler(async (c) => {\n * const message = c.var.data;\n * return c.json({ received: true });\n * });\n *\n * // Use as a standalone endpoint\n * app.post(\"/discord-webhook\", messageHandler.fetch);\n *\n * export default app;\n * ```\n */\n get fetch(): ForWorker extends true ? never : typeof this.app.fetch {\n if (this.isForWorker) {\n throw new Error(\n \"fetch() is not available when handler is configured for Cloudflare Workers mode. Use it with Honocord's webhookHandler instead.\"\n );\n }\n return this.app.fetch as any;\n }\n\n /**\n * Returns the internal Hono app for standalone usage.\n *\n * **Note:** This method is only available in standard mode (`ForWorker = false`).\n * When using worker mode, this method returns `never` and will throw a runtime error.\n *\n * **When to use:** Similar to `fetch`, but allows you to mount the handler on a route prefix.\n * This provides the same self-contained verification as `fetch`.\n *\n * @returns A Hono app instance\n *\n * @example\n * ```typescript\n * import { Hono } from \"hono\";\n * import { WebhookEventHandler } from \"honocord/handlers\";\n * import { ApplicationWebhookEventType } from \"discord-api-types/v10\";\n *\n * const app = new Hono();\n *\n * const messageHandler = new WebhookEventHandler(\n * ApplicationWebhookEventType.MessageCreate\n * );\n *\n * messageHandler.addHandler(async (c) => {\n * return c.json({ ok: true });\n * });\n *\n * // Mount on a prefix\n * app.route(\"/discord\", messageHandler.getApp());\n * // Available at POST /discord\n *\n * export default app;\n * ```\n */\n getApp(): ForWorker extends true ? never : typeof this.app {\n if (this.isForWorker) {\n throw new Error(\n \"getApp() is not available when handler is configured for Cloudflare Workers mode. Use it with Honocord's webhookHandler instead.\"\n );\n }\n return this.app as any;\n }\n}\n","import { APIMessage, InteractionType } from \"discord-api-types/v10\";\nimport { API } from \"@discordjs/core/http-only\";\nimport type { BaseInteractionContext, MessageComponentInteractionPayload, MessageComponentType } from \"../types\";\nimport { ModalCapableInteraction } from \"./ModalCapableInteraction\";\n\nabstract class MessageComponentInteraction<\n Context extends BaseInteractionContext = BaseInteractionContext,\n T extends MessageComponentType = MessageComponentType,\n> extends ModalCapableInteraction<InteractionType.MessageComponent, Context> {\n public readonly message: APIMessage;\n public readonly customId: string;\n public readonly componentType: T;\n\n constructor(api: API, interaction: MessageComponentInteractionPayload<T>, c: Context) {\n super(api, interaction, c);\n this.customId = interaction.data.custom_id;\n this.message = interaction.message;\n this.componentType = interaction.data.component_type as T;\n }\n}\n\nexport { MessageComponentInteraction };\n","import { ComponentType } from \"discord-api-types/v10\";\nimport { API } from \"@discordjs/core/http-only\";\nimport type { BaseInteractionContext, MessageComponentInteractionPayload } from \"../types\";\nimport { MessageComponentInteraction } from \"./MessageComponentInteraction\";\n\nclass ButtonInteraction<Context extends BaseInteractionContext = BaseInteractionContext> extends MessageComponentInteraction<\n Context,\n ComponentType.Button\n> {\n constructor(api: API, interaction: MessageComponentInteractionPayload<ComponentType.Button>, c: Context) {\n super(api, interaction, c);\n }\n}\n\nexport { ButtonInteraction };\n","import { ComponentType } from \"discord-api-types/v10\";\nimport { API } from \"@discordjs/core/http-only\";\nimport type { BaseInteractionContext, MessageComponentInteractionPayload } from \"../types\";\nimport { MessageComponentInteraction } from \"./MessageComponentInteraction\";\n\nclass StringSelectInteraction<\n Context extends BaseInteractionContext = BaseInteractionContext,\n> extends MessageComponentInteraction<Context, ComponentType.StringSelect> {\n public readonly values: string[];\n constructor(api: API, interaction: MessageComponentInteractionPayload<ComponentType.StringSelect>, c: Context) {\n super(api, interaction, c);\n this.values = interaction.data.values;\n }\n}\n\nexport { StringSelectInteraction };\n","import { APIUser, ComponentType } from \"discord-api-types/v10\";\nimport { API } from \"@discordjs/core/http-only\";\nimport type { BaseInteractionContext, MessageComponentInteractionPayload, ResolvedSelectedGuildMember } from \"../types\";\nimport { MessageComponentInteraction } from \"./MessageComponentInteraction\";\nimport { Collection } from \"@discordjs/collection\";\n\nclass UserSelectInteraction<Context extends BaseInteractionContext = BaseInteractionContext> extends MessageComponentInteraction<\n Context,\n ComponentType.UserSelect\n> {\n public readonly values: string[];\n public readonly users: Collection<string, APIUser>;\n public readonly members: Collection<string, ResolvedSelectedGuildMember> = new Collection();\n constructor(api: API, interaction: MessageComponentInteractionPayload<ComponentType.UserSelect>, c: Context) {\n super(api, interaction, c);\n this.values = interaction.data.values;\n this.users = new Collection(interaction.data.resolved.users ? Object.entries(interaction.data.resolved.users) : []);\n if (this.inGuild()) {\n this.members = new Collection(\n this.values\n .map((id) => {\n // We can technically assume that the member and user will always be present if the ID is in the values array, but we should still check just in case\n const member = interaction.data.resolved.members?.[id];\n if (member) {\n const user = this.users.get(id);\n if (user) {\n return [id, { ...member, user } as ResolvedSelectedGuildMember] as const;\n }\n }\n return null;\n })\n .filter((entry) => entry !== null)\n );\n }\n }\n}\n\nexport { UserSelectInteraction };\n","import { APIRole, ComponentType } from \"discord-api-types/v10\";\nimport { API } from \"@discordjs/core/http-only\";\nimport type { BaseInteractionContext, MessageComponentInteractionPayload } from \"../types\";\nimport { MessageComponentInteraction } from \"./MessageComponentInteraction\";\nimport { Collection } from \"@discordjs/collection\";\n\nclass RoleSelectInteraction<Context extends BaseInteractionContext = BaseInteractionContext> extends MessageComponentInteraction<\n Context,\n ComponentType.RoleSelect\n> {\n public readonly values: string[];\n public readonly roles: Collection<string, APIRole>;\n constructor(api: API, interaction: MessageComponentInteractionPayload<ComponentType.RoleSelect>, c: Context) {\n super(api, interaction, c);\n this.values = interaction.data.values;\n this.roles = new Collection(interaction.data.resolved.roles ? Object.entries(interaction.data.resolved.roles) : []);\n }\n}\n\nexport { RoleSelectInteraction };\n","import { APIRole, APIUser, ComponentType } from \"discord-api-types/v10\";\nimport { API } from \"@discordjs/core/http-only\";\nimport type { BaseInteractionContext, MessageComponentInteractionPayload } from \"../types\";\nimport { MessageComponentInteraction } from \"./MessageComponentInteraction\";\nimport { Collection } from \"@discordjs/collection\";\n\nclass MentionableSelectInteraction<\n Context extends BaseInteractionContext = BaseInteractionContext,\n> extends MessageComponentInteraction<Context, ComponentType.MentionableSelect> {\n public readonly values: string[];\n public readonly roles: Collection<string, APIRole>;\n public readonly users: Collection<string, APIUser>;\n constructor(api: API, interaction: MessageComponentInteractionPayload<ComponentType.MentionableSelect>, c: Context) {\n super(api, interaction, c);\n this.values = interaction.data.values;\n this.roles = new Collection(interaction.data.resolved.roles ? Object.entries(interaction.data.resolved.roles) : []);\n this.users = new Collection(interaction.data.resolved.users ? Object.entries(interaction.data.resolved.users) : []);\n }\n}\n\nexport { MentionableSelectInteraction };\n","import { APIInteractionDataResolvedChannel, ComponentType } from \"discord-api-types/v10\";\nimport { API } from \"@discordjs/core/http-only\";\nimport type { BaseInteractionContext, MessageComponentInteractionPayload } from \"../types\";\nimport { MessageComponentInteraction } from \"./MessageComponentInteraction\";\nimport { Collection } from \"@discordjs/collection\";\n\nclass ChannelSelectInteraction<\n Context extends BaseInteractionContext = BaseInteractionContext,\n> extends MessageComponentInteraction<Context, ComponentType.ChannelSelect> {\n public readonly values: string[];\n public readonly channels: Collection<string, APIInteractionDataResolvedChannel>;\n constructor(api: API, interaction: MessageComponentInteractionPayload<ComponentType.ChannelSelect>, c: Context) {\n super(api, interaction, c);\n this.values = interaction.data.values;\n this.channels = new Collection(interaction.data.resolved.channels ? Object.entries(interaction.data.resolved.channels) : []);\n }\n}\n\nexport { ChannelSelectInteraction };\n","import {\n APIInteractionDataResolved,\n APIMessageApplicationCommandInteractionDataResolved,\n APIUserInteractionDataResolved,\n ApplicationCommandType,\n ChannelType,\n ComponentType,\n InteractionType,\n type APIGuild,\n type APIRole,\n type APIUser,\n} from \"discord-api-types/v10\";\nimport type { BaseCacheAdapter } from \"@honocord/cache-base\";\nimport { ValidInteraction } from \"$types/interactions\";\nimport { CachedChannel, CachedGuildMember, CacheNamespace, MemberNamespaceAccessor, NamespaceAccessor } from \"$types/caching\";\n\nfunction key(ns: CacheNamespace, ...parts: string[]): string {\n return `${ns}:${parts.join(\":\")}`;\n}\n\nexport class CacheManager {\n readonly channels: NamespaceAccessor<CachedChannel>;\n readonly roles: NamespaceAccessor<APIRole>;\n readonly users: NamespaceAccessor<APIUser>;\n readonly guilds: NamespaceAccessor<APIGuild>;\n readonly members: MemberNamespaceAccessor;\n\n constructor(\n private adapter: BaseCacheAdapter,\n private defaultTtlMs: number = 5 * 60 * 1000 /* 5 minutes */\n ) {\n this.channels = {\n get: (id) => this.adapter.get<CachedChannel>(key(\"channel\", id)),\n set: (channel, ttlMs) => this.adapter.set(key(\"channel\", channel.id), channel, ttlMs ?? this.defaultTtlMs),\n delete: (id) => this.adapter.delete(key(\"channel\", id)),\n has: (id) => this.adapter.has(key(\"channel\", id)),\n mset: (entries) => this.adapter.mset(entries.map((e) => ({ ...e, key: key(\"channel\", e.value.id) }))),\n };\n\n this.roles = {\n get: (id) => this.adapter.get<APIRole>(key(\"role\", id)),\n set: (role, ttlMs) => this.adapter.set(key(\"role\", role.id), role, ttlMs ?? this.defaultTtlMs),\n delete: (id) => this.adapter.delete(key(\"role\", id)),\n has: (id) => this.adapter.has(key(\"role\", id)),\n mset: (entries) => this.adapter.mset(entries.map((e) => ({ ...e, key: key(\"role\", e.value.id) }))),\n };\n\n this.users = {\n get: (id) => this.adapter.get<APIUser>(key(\"user\", id)),\n set: (user, ttlMs) => this.adapter.set(key(\"user\", user.id), user, ttlMs ?? this.defaultTtlMs),\n delete: (id) => this.adapter.delete(key(\"user\", id)),\n has: (id) => this.adapter.has(key(\"user\", id)),\n mset: (entries) => this.adapter.mset(entries.map((e) => ({ ...e, key: key(\"user\", e.value.id) }))),\n };\n\n this.guilds = {\n get: (id) => this.adapter.get<APIGuild>(key(\"guild\", id)),\n set: (guild, ttlMs) => this.adapter.set(key(\"guild\", guild.id), guild, ttlMs ?? this.defaultTtlMs),\n delete: (id) => this.adapter.delete(key(\"guild\", id)),\n has: (id) => this.adapter.has(key(\"guild\", id)),\n mset: (entries) => this.adapter.mset(entries.map((e) => ({ ...e, key: key(\"guild\", e.value.id) }))),\n };\n\n // Members are guild-scoped: key = \"member:{guildId}:{userId}\"\n this.members = {\n get: (guildId, userId) => this.adapter.get<CachedGuildMember>(key(\"member\", guildId, userId)),\n set: (guildId, member, ttlMs) =>\n this.adapter.set(key(\"member\", guildId, member.user!.id), member, ttlMs ?? this.defaultTtlMs),\n delete: (guildId, userId) => this.adapter.delete(key(\"member\", guildId, userId)),\n has: (guildId, userId) => this.adapter.has(key(\"member\", guildId, userId)),\n mset: (guildId, entries) => this.adapter.mset(entries.map((e) => ({ ...e, key: key(\"member\", guildId, e.value.user.id) }))),\n };\n }\n\n async getGuildRoles(guildId: string): Promise<APIRole[]> {\n const roleIds = await this.adapter.get<string[]>(key(\"guild-roles\", guildId));\n if (!roleIds) return [];\n const roles = await Promise.all(roleIds.map((roleId) => this.roles.get(roleId)));\n return roles.filter(Boolean) as APIRole[];\n }\n\n async getDMChannel(\n userId: string\n ): Promise<Extract<CachedChannel, { type: ChannelType.DM | ChannelType.GroupDM }> | undefined> {\n const channelId = await this.adapter.get<string>(key(\"dm-channel\", userId));\n const cachedChannel = channelId ? await this.channels.get(channelId) : undefined;\n if (cachedChannel && (cachedChannel.type === ChannelType.DM || cachedChannel.type === ChannelType.GroupDM)) {\n return cachedChannel;\n }\n return undefined; // We should never get here, but just in case\n }\n\n async setDMChannel(userId: string, channel: CachedChannel, ttlMs?: number): Promise<void> {\n await this.channels.set(channel, ttlMs);\n await this.adapter.set(key(\"dm-channel\", userId), channel.id, ttlMs ?? this.defaultTtlMs);\n }\n\n private async addRolesToGuild(guildId: string, roleIds: string[]): Promise<void> {\n if (!roleIds.length) return;\n const existing = (await this.adapter.get<string[]>(key(\"guild-roles\", guildId))) ?? [];\n const toAdd = roleIds.filter((id) => !existing.includes(id));\n if (toAdd.length) {\n await this.adapter.set(key(\"guild-roles\", guildId), [...existing, ...toAdd], this.defaultTtlMs);\n }\n }\n\n populate(i: ValidInteraction) {\n switch (i.type) {\n case InteractionType.ApplicationCommand: // Chat Input Command\n return this.populateCommand(i);\n case InteractionType.MessageComponent: // Message Component\n return this.populateMessageComponent(i);\n case InteractionType.ModalSubmit: // Modal Submit\n if (i.data.resolved) {\n return this.populateResolved(i.data.resolved, i.guild_id);\n }\n break;\n default:\n break;\n }\n return Promise.resolve();\n }\n\n private async populateResolved(\n resolved: APIInteractionDataResolved | APIUserInteractionDataResolved | APIMessageApplicationCommandInteractionDataResolved,\n guildId?: string\n ) {\n if (resolved) {\n // channels can't be used as the partial objects are only ID and type\n if (\"users\" in resolved && resolved.users) {\n await this.users.mset(Object.values(resolved.users).map((user) => ({ value: user })));\n }\n if (\"roles\" in resolved && resolved.roles) {\n const roles = Object.values(resolved.roles);\n await this.roles.mset(roles.map((role) => ({ value: role })));\n if (guildId) {\n await this.addRolesToGuild(\n guildId,\n roles.map((r) => r.id)\n );\n }\n }\n if (\"members\" in resolved && resolved.members && guildId) {\n // We need the guildId to cache members, but it's not included in the resolved data. We can only cache the member if we also have the user object, which includes the ID.\n const entries = Object.entries(resolved.members).flatMap(([userId, member]) => {\n const user = resolved.users?.[userId];\n return user ? [{ value: { ...member, user } }] : [];\n });\n if (entries.length) {\n await this.members.mset(guildId, entries);\n }\n }\n }\n }\n\n private async populateCommand(i: Extract<ValidInteraction, { type: InteractionType.ApplicationCommand }>) {\n if (i.data.type === ApplicationCommandType.PrimaryEntryPoint) return; // Doesnt have any data\n\n // i.guild is somehow only the APIPartialInteractionGuild which only carries id, features and preferred_locale/locale (buggy)\n\n if (i.data.resolved) {\n await this.populateResolved(i.data.resolved, i.guild_id);\n }\n\n if (i.user) {\n await this.users.set(i.user);\n }\n if (i.member && i.guild_id) {\n await this.users.set(i.member.user);\n await this.members.set(i.guild_id, i.member);\n }\n if (i.channel) {\n await this.channels.set(i.channel as CachedChannel);\n }\n }\n\n private async populateMessageComponent(i: Extract<ValidInteraction, { type: InteractionType.MessageComponent }>) {\n if (i.channel) {\n await this.channels.set(i.channel as CachedChannel);\n }\n\n if (i.user) {\n await this.users.set(i.user);\n }\n if (i.member && i.guild_id) {\n await this.users.set(i.member.user);\n await this.members.set(i.guild_id, i.member);\n }\n\n if (\n i.data.component_type !== ComponentType.Button &&\n i.data.component_type !== ComponentType.StringSelect &&\n \"resolved\" in i.data &&\n i.data.resolved\n ) {\n const resolved = i.data.resolved;\n if (\"users\" in resolved && resolved.users) {\n await this.users.mset(Object.values(resolved.users).map((user) => ({ value: user })));\n }\n if (\"roles\" in resolved && resolved.roles) {\n await this.roles.mset(Object.values(resolved.roles).map((role) => ({ value: role })));\n }\n if (\"members\" in resolved && resolved.members && i.guild_id) {\n const resolvedUsers = \"users\" in resolved ? resolved.users : undefined;\n const entries = Object.entries(resolved.members).flatMap(([userId, member]) => {\n const user = resolvedUsers?.[userId];\n return user ? [{ value: { ...member, user } }] : [];\n });\n if (entries.length) {\n await this.members.mset(i.guild_id, entries);\n }\n }\n }\n }\n}\n","import {\n APIApplicationCommandAutocompleteInteraction,\n APIApplicationCommandInteraction,\n APIInteraction,\n APIWebhookEvent,\n ApplicationCommandType,\n ApplicationWebhookType,\n ComponentType,\n InteractionResponseType,\n InteractionType,\n} from \"discord-api-types/v10\";\nimport { ChatInputCommandInteraction } from \"@ctx/ChatInputInteraction\";\nimport { API } from \"@discordjs/core/http-only\";\nimport { REST } from \"@discordjs/rest\";\nimport { Context, Hono } from \"hono\";\nimport { verifyDiscordRequest } from \"@utils/discordVerify\";\nimport { parseCustomId } from \"@utils/index\";\nimport type {\n BaseVariables,\n BaseInteractionContext,\n ValidInteraction,\n MessageComponentInteractionPayload,\n MessageComponentType,\n FlatOrNestedArray,\n MiddlewareFunction,\n ApplicationWebhookEventType,\n} from \"$types/index\";\nimport { UserContextInteraction } from \"@ctx/UserContextCommandInteraction\";\nimport { MessageContextInteraction } from \"@ctx/MessageContextCommandInteraction\";\nimport { ModalInteraction } from \"@ctx/ModalInteraction\";\nimport { AutocompleteInteraction } from \"@ctx/AutocompleteInteraction\";\nimport {\n SlashCommandHandler,\n ContextCommandHandler,\n ComponentHandler,\n ModalHandler,\n type Handler,\n type AnyHandler,\n WebhookEventHandler,\n} from \"@handlers/index\";\nimport { ButtonInteraction } from \"@ctx/ButtonInteraction\";\nimport { StringSelectInteraction } from \"@ctx/StringSelectInteraction\";\nimport { UserSelectInteraction } from \"@ctx/UserSelectInteraction\";\nimport { RoleSelectInteraction } from \"@ctx/RoleSelectInteraction\";\nimport { MentionableSelectInteraction } from \"@ctx/MentionableSelectInteraction\";\nimport { ChannelSelectInteraction } from \"@ctx/ChannelSelectInteraction\";\nimport { BaseCacheAdapter, NullCacheAdapter } from \"@honocord/cache-base\";\nimport { CacheManager } from \"@utils/CacheManager\";\n\ninterface HonocordOptions {\n /**\n * Indicates whether the Honocord instance is running on Cloudflare Workers.\n *\n * This affects how interactions are processed, allowing for asynchronous handling using the Workers' execution context.\n *\n * @default c.env.IS_CF_WORKER === \"true\" # later determined from environment variable\n */\n isCFWorker?: boolean;\n /**\n * Whether to turn on debug logging for REST API requests.\n *\n * @default false\n */\n debugRest?: boolean;\n /**\n * Default TTL (in MILLISECONDS) for cached entities when a cache adapter is registered via `withCache`.\n *\n * Set `0` to disable expiration.\n */\n cacheTtlMs?: number;\n}\n\ninterface HonocordAppOptions {\n interactionsPath?: `/${string}`;\n webhookPath?: `/${string}`;\n}\n\nexport class Honocord {\n /**\n * Map of commandName to CommandHandler instances for global commands.\n */\n private globalCommandHandlers = new Map<string, SlashCommandHandler | ContextCommandHandler>();\n /**\n * Map of `guildId:commandName` to CommandHandler instances for guild-specific commands.\n */\n private guildCommandHandlers = new Map<string, SlashCommandHandler | ContextCommandHandler>();\n private componentHandlers = new Map<string, ComponentHandler>();\n private modalHandlers = new Map<string, ModalHandler>();\n private middleware = new Array<MiddlewareFunction<any>>();\n private webhookHandlers = new Map<ApplicationWebhookEventType, WebhookEventHandler<any>>();\n private isCFWorker: boolean;\n private debugRest: boolean;\n private _cacheAdapterFactory: (env: any) => BaseCacheAdapter = () => new NullCacheAdapter();\n private _cacheManager: CacheManager | null = null;\n private _defaultCacheTtlMs: number | undefined = undefined; // ← add this\n\n /**\n * Executes all registered middleware in sequence.\n *\n * @param ctx - The interaction context\n * @param finalHandler - The final handler to execute after all middleware\n */\n private async runMiddleware(ctx: BaseInteractionContext, finalHandler: () => Promise<void>): Promise<void> {\n if (this.middleware.length === 0) {\n return await finalHandler();\n }\n\n /**\n * Executes the next middleware in the chain.\n */\n const dispatch = async (i: number = 0): Promise<void> => {\n if (i >= this.middleware.length) {\n return await finalHandler();\n }\n\n await this.middleware[i](ctx, () => dispatch(i + 1));\n };\n\n await dispatch();\n }\n\n constructor({ isCFWorker, debugRest }: HonocordOptions = {}) {\n this.isCFWorker = isCFWorker ?? false;\n this.debugRest = debugRest ?? false;\n }\n\n /**\n * Registers handlers for interactions.\n *\n * @param handlers - Array of CommandHandler, ComponentHandler, or ModalHandler instances\n *\n * For an example of usage, see the [Example Repository](https://github.com/The-LukeZ/honocord-examples).\n */\n loadHandlers(...handlers: FlatOrNestedArray<AnyHandler>): void {\n const flattenedHandlers = handlers.flat(Infinity) as Handler[];\n\n for (const handler of flattenedHandlers) {\n if (handler instanceof SlashCommandHandler || handler instanceof ContextCommandHandler) {\n if (handler.isGuildCommand()) {\n for (const guildId of handler.guildIds.values()) {\n const key = `${guildId}:${handler.name}`;\n if (this.guildCommandHandlers.has(key)) {\n console.warn(`Guild command handler for \"${handler.name}\" in guild \"${guildId}\" already exists. Overwriting.`);\n }\n this.guildCommandHandlers.set(key, handler as SlashCommandHandler | ContextCommandHandler);\n }\n continue;\n }\n\n if (this.globalCommandHandlers.has(handler.name)) {\n console.warn(`Command handler for \"${handler.name}\" already exists. Overwriting.`);\n }\n this.globalCommandHandlers.set(handler.name, handler as SlashCommandHandler | ContextCommandHandler);\n } else if (handler instanceof ComponentHandler) {\n const prefix = handler.prefix;\n if (this.componentHandlers.has(prefix)) {\n console.warn(`Component handler with prefix \"${prefix}\" already exists. Overwriting.`);\n }\n this.componentHandlers.set(prefix, handler as ComponentHandler<any>);\n } else if (handler instanceof ModalHandler) {\n const prefix = handler.prefix;\n if (this.modalHandlers.has(prefix)) {\n console.warn(`Modal handler with prefix \"${prefix}\" already exists. Overwriting.`);\n }\n this.modalHandlers.set(prefix, handler);\n } else if (handler instanceof WebhookEventHandler) {\n if (this.webhookHandlers.has(handler.eventType)) {\n console.warn(`Webhook handler for event type \"${handler.eventType}\" already exists. Overwriting.`);\n }\n this.webhookHandlers.set(handler.eventType, handler);\n }\n }\n }\n\n private createCommandInteraction(ctx: BaseInteractionContext, interaction: APIApplicationCommandInteraction, api: API) {\n switch (interaction.data.type) {\n case ApplicationCommandType.ChatInput:\n return new ChatInputCommandInteraction(api, interaction as any, ctx);\n case ApplicationCommandType.User:\n return new UserContextInteraction(api, interaction as any, ctx);\n case ApplicationCommandType.Message:\n return new MessageContextInteraction(api, interaction as any, ctx);\n default:\n throw new Error(\n `Unsupported application command type: ${interaction.data.type} (${ApplicationCommandType[interaction.data.type]})`\n );\n }\n }\n\n private executeCommandHandler(\n handler: SlashCommandHandler | ContextCommandHandler,\n interactionObj: ReturnType<typeof this.createCommandInteraction>,\n commandType: ApplicationCommandType\n ) {\n if (handler instanceof SlashCommandHandler && commandType === ApplicationCommandType.ChatInput) {\n return handler.execute(interactionObj as ChatInputCommandInteraction);\n } else if (handler instanceof ContextCommandHandler) {\n if (commandType === ApplicationCommandType.User) {\n return handler.execute(interactionObj as UserContextInteraction);\n } else if (commandType === ApplicationCommandType.Message) {\n return handler.execute(interactionObj as MessageContextInteraction);\n }\n }\n }\n\n private async handleCommandInteraction(ctx: BaseInteractionContext, interaction: APIApplicationCommandInteraction, api: API) {\n const interactionObj = this.createCommandInteraction(ctx, interaction, api);\n const commandName = interaction.data.name;\n const handler = this.globalCommandHandlers.get(commandName);\n\n // Store interaction in context for middleware access\n ctx.set(\"command\", interactionObj as any);\n\n await this.runMiddleware(ctx, async () => {\n if (handler) {\n try {\n await this.executeCommandHandler(handler, interactionObj, interaction.data.type);\n } catch (error) {\n console.error(`Error executing command handler for \"${commandName}\"`, error);\n throw error;\n }\n }\n\n // Could be a guild command\n const guildId = interaction.guild_id;\n if (guildId) {\n const key = `${guildId}:${commandName}`;\n const guildHandler = this.guildCommandHandlers.get(key);\n if (guildHandler) {\n try {\n await this.executeCommandHandler(guildHandler, interactionObj, interaction.data.type);\n } catch (error) {\n console.error(`Error executing guild command handler for \"${commandName}\" in guild \"${guildId}\"`, error);\n throw error;\n }\n }\n }\n });\n\n return interactionObj;\n }\n\n private async handleAutocompleteInteraction(\n ctx: BaseInteractionContext,\n interaction: APIApplicationCommandAutocompleteInteraction,\n api: API\n ) {\n const interactionObj = new AutocompleteInteraction(api, interaction, ctx);\n const commandName = interaction.data.name;\n const handler = this.globalCommandHandlers.get(commandName);\n\n // Store interaction in context for middleware access\n ctx.set(\"autocomplete\", interactionObj as any);\n\n await this.runMiddleware(ctx, async () => {\n if (handler && handler instanceof SlashCommandHandler) {\n try {\n await handler.executeAutocomplete(interactionObj);\n } catch (error) {\n console.error(`Error executing autocomplete handler for \"${commandName}\"`, error);\n throw error;\n }\n }\n\n // Could be a guild command\n const guildId = interaction.guild_id;\n if (guildId) {\n const key = `${guildId}:${commandName}`;\n const guildHandler = this.guildCommandHandlers.get(key);\n if (guildHandler && guildHandler instanceof SlashCommandHandler) {\n try {\n await guildHandler.executeAutocomplete(interactionObj);\n } catch (error) {\n console.error(`Error executing guild autocomplete handler for \"${commandName}\" in guild \"${guildId}\"`, error);\n throw error;\n }\n }\n }\n });\n }\n\n private createMessageComponentInteraction<T extends MessageComponentType>(\n ctx: BaseInteractionContext,\n interactionObj: MessageComponentInteractionPayload<T>,\n api: API\n ) {\n switch (interactionObj.data.component_type) {\n case ComponentType.Button:\n return new ButtonInteraction(api, interactionObj as any, ctx);\n case ComponentType.StringSelect:\n return new StringSelectInteraction(api, interactionObj as any, ctx);\n case ComponentType.UserSelect:\n return new UserSelectInteraction(api, interactionObj as any, ctx);\n case ComponentType.RoleSelect:\n return new RoleSelectInteraction(api, interactionObj as any, ctx);\n case ComponentType.MentionableSelect:\n return new MentionableSelectInteraction(api, interactionObj as any, ctx);\n case ComponentType.ChannelSelect:\n return new ChannelSelectInteraction(api, interactionObj as any, ctx);\n default:\n throw new Error(`Unsupported message component type: ${(interactionObj.data as any).component_type}`);\n }\n }\n\n private async handleComponentInteraction<T extends MessageComponentType>(\n ctx: BaseInteractionContext,\n interaction: MessageComponentInteractionPayload<T>,\n api: API\n ) {\n const interactionObj = this.createMessageComponentInteraction(ctx, interaction, api);\n const prefix = parseCustomId(interaction.data.custom_id, true);\n\n // Store interaction in context for middleware access\n ctx.set(\"component\", interactionObj as any);\n\n await this.runMiddleware(ctx, async () => {\n // Lookup handler by prefix\n const handler = this.componentHandlers.get(prefix);\n if (handler?.componentType === interaction.data.component_type) {\n try {\n await handler.execute(interactionObj);\n } catch (error) {\n console.error(`Error executing component handler for prefix \"${prefix}\"`, error);\n throw error;\n }\n } else {\n throw new Error(\n `No component handler found for prefix \"${prefix}\" and component type \"${interaction.data.component_type}\"`\n );\n }\n });\n\n return interactionObj;\n }\n\n private async handleModalInteraction(\n ctx: BaseInteractionContext,\n interaction: Extract<ValidInteraction, { type: InteractionType.ModalSubmit }>,\n api: API\n ) {\n const interactionObj = new ModalInteraction(api, interaction, ctx);\n const customId = interaction.data.custom_id;\n const prefix = parseCustomId(customId, true);\n\n // Store interaction in context for middleware access\n ctx.set(\"modal\", interactionObj);\n\n await this.runMiddleware(ctx, async () => {\n // Lookup handler by prefix\n const handler = this.modalHandlers.get(prefix);\n\n if (handler) {\n try {\n await handler.execute(interactionObj);\n } catch (error) {\n console.error(`Error executing modal handler for prefix \"${prefix}\"`, error);\n throw error;\n }\n }\n });\n\n return interactionObj;\n }\n\n private async createInteraction(ctx: BaseInteractionContext, interaction: ValidInteraction) {\n const cache = this._getCacheManager(ctx.env);\n if (this._cacheManager) {\n // TODO: Find out what performance impact this has\n await cache.populate(interaction as ValidInteraction);\n }\n ctx.set(\"cache\", cache);\n\n const rest = new REST({ authPrefix: \"Bot\" }).setToken(ctx.env.DISCORD_TOKEN as string);\n if (this.debugRest) {\n rest\n .addListener(\"response\", (request, response) => {\n console.debug(\n `[REST] ${request.method} ${request.path} -> ${response.status} ${response.statusText} (${request.route})`\n );\n })\n .addListener(\"restDebug\", (info) => {\n console.debug(`[REST DEBUG] ${info}`);\n });\n }\n const api = new API(rest);\n\n switch (interaction.type) {\n case InteractionType.ApplicationCommand:\n return await this.handleCommandInteraction(ctx, interaction, api);\n case InteractionType.MessageComponent:\n return await this.handleComponentInteraction(ctx, interaction, api);\n case InteractionType.ModalSubmit:\n return await this.handleModalInteraction(ctx, interaction, api);\n case InteractionType.ApplicationCommandAutocomplete:\n return await this.handleAutocompleteInteraction(ctx, interaction, api);\n default:\n throw new Error(`Unknown interaction type: ${(interaction as any).type} (${InteractionType[(interaction as any).type]})`);\n }\n }\n\n /**\n * Returns a Hono handler for POST Requests handling Discord interactions.\n *\n * @example\n * ```typescript\n * import { Hono } from \"hono\";\n * import { Honocord } from \"honocord\";\n *\n * const app = new Hono();\n * const bot = new Honocord();\n *\n * app.get(\"/\", (c) => c.text(\"🔥 Honocord is running!\"));\n * app.post(\"/interactions\", bot.interactionsHandler);\n *\n * export default app;\n * ```\n */\n interactionsHandler = async (c: BaseInteractionContext) => {\n // Check if running on CF Workers\n const isCFWorker = this.isCFWorker || c.env.IS_CF_WORKER === \"true\";\n\n // Verify the request\n const { isValid, data: interaction } = await verifyDiscordRequest<APIInteraction>(c.req, c.env.DISCORD_PUBLIC_KEY as string);\n if (!isValid) {\n return c.text(\"Bad request signature.\", 401);\n } else if (!interaction) {\n console.log(\"No interaction found in request\");\n return c.text(\"No interaction found.\", 400);\n }\n\n if (interaction.type === InteractionType.Ping) {\n console.log(\"Received Discord Ping\");\n return c.json({ type: InteractionResponseType.Pong });\n }\n\n // Handle CF Workers execution context\n if (isCFWorker && c.executionCtx?.waitUntil) {\n // Process interaction asynchronously\n c.executionCtx.waitUntil(\n new Promise(async (resolve) => {\n try {\n await this.createInteraction(c, interaction);\n } catch (error) {\n console.error(\"Error handling interaction:\", error);\n }\n resolve(undefined);\n })\n );\n return c.json({}, 202); // Accepted for processing\n }\n\n // Standard non-CF Workers execution\n try {\n await this.createInteraction(c, interaction);\n } catch (error) {\n console.error(\"Error handling interaction:\", error);\n return c.text(\"Internal server error.\", 500);\n }\n };\n\n /**\n * Returns a Hono App instance with the interaction handler mounted at the root path and a GET Handler for all paths, which returns a simple Health response.\n *\n * @example\n * ```typescript\n * import { Honocord } from \"honocord\";\n *\n * const honoCord = new Honocord();\n *\n * export default honoCord.getApp();\n * // Supports both \"/\" and \"/interactions\" for the interactions handler, if any are loaded\n * // And `/webhook` for the webhook handler if any are loaded\n * ```\n */\n getApp(options: HonocordAppOptions = {}) {\n options = {\n interactionsPath: \"/interactions\",\n webhookPath: \"/webhook\",\n ...options,\n };\n const app = new Hono<{ Variables: BaseVariables }>();\n app.get(\"*\", (c) => c.text(\"🔥 Honocord is running!\"));\n if (this.globalCommandHandlers.size > 0 || this.guildCommandHandlers.size > 0) {\n app.post(\"/\", this.interactionsHandler);\n app.post(options.interactionsPath || \"/interactions\", this.interactionsHandler);\n }\n if (this.webhookHandlers.size > 0) app.post(options.webhookPath || \"/webhook\", this.webhookHandler);\n return app;\n }\n\n /**\n * Registers a middleware function to process interaction contexts.\n *\n * Middleware receives the Hono context and a `next` callback:\n * - Access/modify context variables via `c.get()` and `c.set()`\n * - Access the interaction object via `c.var.command`, `c.var.component`, `c.var.modal`, or `c.var.autocomplete`\n * - Access environment bindings via `c.env`\n * - Call `await next()` to continue to the next middleware or handler\n *\n * The context is passed by reference, so all modifications persist through the middleware chain and into handlers.\n *\n * @example\n * ```typescript\n * bot.use(async (c, next) => {\n * // Set custom data in context\n * c.set('startTime', Date.now());\n *\n * // Continue to next middleware/handler\n * // you can also return next() directly if no post-processing is needed\n * await next();\n *\n * // Code here runs after the handler completes\n * console.log('Duration:', Date.now() - c.get('startTime'));\n * });\n * ```\n *\n * @param middleware - The middleware function(s) to register.\n * @returns The Honocord instance for chaining.\n */\n use<Context extends BaseInteractionContext = BaseInteractionContext>(...middleware: MiddlewareFunction<Context>[]): this {\n this.middleware.push(...middleware);\n return this;\n }\n\n /**\n * Returns a Hono handler for POST requests handling Discord webhook events.\n *\n * On Cloudflare Workers, webhook events are processed asynchronously using `waitUntil`,\n * allowing immediate response to Discord while extending the worker's lifetime to complete processing.\n *\n * @example\n * ```typescript\n * import { Hono } from \"hono\";\n * import { Honocord } from \"honocord\";\n *\n * const app = new Hono();\n * const bot = new Honocord();\n *\n * app.post(\"/webhook\", bot.webhookHandler);\n *\n * export default app;\n * ```\n */\n webhookHandler = async (c: Context) => {\n const isCFWorker = this.isCFWorker || c.env.IS_CF_WORKER === \"true\";\n\n if (typeof c.env.DISCORD_PUBLIC_KEY !== \"string\") {\n console.error(\"No Discord public key provided in environment variables.\");\n return c.body(null, 500);\n }\n const { isValid, data } = await verifyDiscordRequest<APIWebhookEvent>(c.req, c.env.DISCORD_PUBLIC_KEY);\n\n if (!isValid || !data) {\n return c.text(\"Bad request signature.\", 401);\n }\n\n if (data.type === ApplicationWebhookType.Ping) {\n return c.json({ type: ApplicationWebhookType.Ping }, 200);\n }\n\n const handler = this.webhookHandlers.get(data.event.type);\n if (!handler) {\n return c.text(\"No handler found for this event type.\", 404);\n }\n\n // CF Workers async processing\n if (isCFWorker && c.executionCtx?.waitUntil) {\n c.executionCtx.waitUntil(\n new Promise(async (resolve) => {\n try {\n await handler.execute(data.event, c);\n } catch (error) {\n console.error(`Error handling webhook event ${data.event.type}:`, error);\n }\n resolve(undefined);\n })\n );\n return c.json({ ok: true }, 200);\n }\n\n // Standard execution for other platforms\n return handler.execute(data.event, c);\n };\n\n /**\n * Registers a cache adapter factory for use throughout the bot.\n * The factory receives the request environment and returns a `BaseCacheAdapter` instance.\n *\n * On Cloudflare Workers, use `DurableObjectCacheAdapter`.\n * On self-hosted environments, use `MemoryCacheAdapter`, `MongoCacheAdapter`, or `RedisAdapter`.\n *\n * @example\n * ```typescript\n * // Cloudflare Workers\n * bot.withCache((env) => new DurableObjectCacheAdapter(env.MY_CACHE));\n *\n * // Self-hosted (pre-initialized)\n * const cache = new MongoCacheAdapter(process.env.MONGO_URI!);\n * await cache.connect();\n * bot.withCache(() => cache);\n * ```\n *\n * @param factory - A function that receives the environment and returns a cache adapter.\n * @returns The Honocord instance for chaining.\n */\n withCache<TheEnv = any>(factory: (env: TheEnv) => BaseCacheAdapter): this {\n this._cacheAdapterFactory = factory;\n this._cacheManager = null; // Reset cache manager to ensure new factory is used\n return this;\n }\n\n /**\n * Returns the cache manager for the given environment.\n * If no cache manager exists for the environment, a new one is created.\n * @param env - The environment to get the cache manager for.\n * @returns The cache manager for the given environment.\n */\n private _getCacheManager(env: unknown): CacheManager {\n if (!this._cacheManager) {\n this._cacheManager = new CacheManager(this._cacheAdapterFactory(env), this._defaultCacheTtlMs);\n }\n return this._cacheManager;\n }\n\n /**\n * Clears all registered middleware functions.\n * @returns The Honocord instance for chaining.\n */\n clearMiddleware(): this {\n this.middleware = [];\n return this;\n }\n}\n","import { ApplicationCommandType } from \"discord-api-types/v10\";\n\nexport enum ContextCommandType {\n User = ApplicationCommandType.User,\n Message = ApplicationCommandType.Message,\n}\n"],"mappings":";;;;;;;;;;;;;;AAoCA,IAAM,mCAAN,MAAuC;;;;CAIrC,AAAQ,SAAwB;;;;CAIhC,AAAQ,cAA6B;;;;;CAKrC,AAAQ;CAIR,AAAQ;CAER,YACE,SAKA,UACA;AACA,OAAK,kBAAkB,WAAW,EAAE;AACpC,OAAK,YAAY,OAAO,KAAK,YAAY,EAAE,CAAC,CAAC,QAAQ,KAAK,UAAQ;GAChE,MAAM,eAAe,WAAWA;AAChC,OAAIA,UAAQ,WAAW;IAErB,MAAM,QAAQ,UAAU,QAAQ,IAAIC,iCAAW,OAAO,QAAQ,SAAS,MAAM,CAAC,GAA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