lunibee 0.1.0 → 0.1.2
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.
- package/README.md +229 -0
- package/dist/builders/attachment.d.ts +20 -0
- package/dist/builders/commands.d.ts +118 -0
- package/dist/builders/components.d.ts +151 -0
- package/dist/builders/embed.d.ts +59 -0
- package/dist/builders/index.d.ts +5 -0
- package/dist/builders/index.js +828 -0
- package/dist/builders/index.js.map +13 -0
- package/dist/collection/cache.d.ts +37 -0
- package/dist/collection/index.d.ts +47 -0
- package/dist/collection/index.js +214 -0
- package/dist/collection/index.js.map +11 -0
- package/dist/core/client-state.d.ts +10 -0
- package/dist/core/collector.d.ts +27 -0
- package/dist/core/events.d.ts +5 -0
- package/dist/core/index.d.ts +111 -0
- package/dist/core/index.js +3188 -0
- package/dist/core/index.js.map +29 -0
- package/dist/core/permissions.d.ts +293 -0
- package/dist/formatters/index.d.ts +10 -0
- package/dist/formatters/index.js +43 -0
- package/dist/formatters/index.js.map +10 -0
- package/dist/handlers/index.d.ts +16 -0
- package/dist/handlers/index.js +37 -0
- package/dist/handlers/index.js.map +10 -0
- package/{src/index.ts → dist/index.d.ts} +2 -29
- package/dist/index.js +4182 -0
- package/dist/index.js.map +41 -0
- package/dist/managers/application.d.ts +28 -0
- package/dist/managers/base.d.ts +28 -0
- package/dist/managers/index.d.ts +96 -0
- package/dist/managers/index.js +947 -0
- package/dist/managers/index.js.map +22 -0
- package/dist/managers/member.d.ts +35 -0
- package/dist/managers/message.d.ts +25 -0
- package/dist/managers/role.d.ts +34 -0
- package/dist/managers/thread.d.ts +14 -0
- package/dist/rest/index.d.ts +49 -0
- package/dist/rest/index.js +344 -0
- package/dist/rest/index.js.map +12 -0
- package/dist/rest/routes.d.ts +44 -0
- package/dist/rest/types.d.ts +26 -0
- package/dist/rest/webhook.d.ts +40 -0
- package/dist/sharding/bus.d.ts +22 -0
- package/dist/sharding/index.d.ts +34 -0
- package/dist/sharding/index.js +732 -0
- package/dist/sharding/index.js.map +13 -0
- package/dist/structures/base.d.ts +75 -0
- package/dist/structures/index.d.ts +39 -0
- package/dist/structures/index.js +571 -0
- package/dist/structures/index.js.map +14 -0
- package/dist/structures/interactions.d.ts +136 -0
- package/dist/structures/permissions.d.ts +73 -0
- package/dist/structures/resources.d.ts +64 -0
- package/dist/types/index.d.ts +535 -0
- package/dist/types/index.js +132 -0
- package/dist/types/index.js.map +10 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.js +18 -0
- package/dist/utils/index.js.map +10 -0
- package/dist/voice/index.d.ts +97 -0
- package/dist/voice/index.js +161 -0
- package/dist/voice/index.js.map +10 -0
- package/dist/ws/index.d.ts +76 -0
- package/dist/ws/index.js +582 -0
- package/dist/ws/index.js.map +11 -0
- package/package.json +113 -28
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../packages/types/src/index.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/** Discord API snowflake identifier. */\r\nexport type Snowflake = string;\r\n\r\n/** Gateway intent bit flags supported by Discord (PascalCase). */\r\nexport const GatewayIntentBits = {\r\n Guilds: 1 << 0,\r\n GuildMembers: 1 << 1,\r\n GuildModeration: 1 << 2,\r\n GuildExpressions: 1 << 3,\r\n GuildIntegrations: 1 << 4,\r\n GuildWebhooks: 1 << 5,\r\n GuildInvites: 1 << 6,\r\n GuildVoiceStates: 1 << 7,\r\n GuildPresences: 1 << 8,\r\n GuildMessages: 1 << 9,\r\n GuildMessageReactions: 1 << 10,\r\n GuildMessageTyping: 1 << 11,\r\n DirectMessages: 1 << 12,\r\n DirectMessageReactions: 1 << 13,\r\n DirectMessageTyping: 1 << 14,\r\n MessageContent: 1 << 15,\r\n GuildScheduledEvents: 1 << 16,\r\n AutoModerationConfiguration: 1 << 20,\r\n AutoModerationExecution: 1 << 21,\r\n GuildMessagePolls: 1 << 24,\r\n DirectMessagePolls: 1 << 25,\r\n} as const;\r\n\r\n/** Idiomatic camelCase Gateway intent bit flags supported by Discord. */\r\nexport const IntentBits = {\r\n guild: 1 << 0,\r\n guilds: 1 << 0,\r\n guildMembers: 1 << 1,\r\n guildModeration: 1 << 2,\r\n guildBans: 1 << 2,\r\n guildExpressions: 1 << 3,\r\n guildEmojis: 1 << 3,\r\n guildEmojisAndStickers: 1 << 3,\r\n guildIntegrations: 1 << 4,\r\n guildWebhooks: 1 << 5,\r\n guildInvites: 1 << 6,\r\n guildVoiceStates: 1 << 7,\r\n guildPresences: 1 << 8,\r\n guildMessages: 1 << 9,\r\n guildMessage: 1 << 9,\r\n guildMessageReactions: 1 << 10,\r\n guildMessageTyping: 1 << 11,\r\n directMessages: 1 << 12,\r\n directMessageReactions: 1 << 13,\r\n directMessageTyping: 1 << 14,\r\n messageContent: 1 << 15,\r\n guildScheduledEvents: 1 << 16,\r\n autoModerationConfiguration: 1 << 20,\r\n autoModerationExecution: 1 << 21,\r\n guildMessagePolls: 1 << 24,\r\n directMessagePolls: 1 << 25,\r\n} as const;\r\n\r\n/** Alias for IntentBits. */\r\nexport const Intents = IntentBits;\r\n\r\n/** Gateway intent resolvable value (single bitfield, enum key, or array of bitfields/strings). */\r\nexport type GatewayIntentResolvable =\r\n | number\r\n | keyof typeof GatewayIntentBits\r\n | keyof typeof IntentBits\r\n | (\r\n number | keyof typeof GatewayIntentBits | keyof typeof IntentBits | string\r\n )[];\r\n\r\n/** Resolves any GatewayIntentResolvable into a raw bitfield integer. */\r\nexport function resolveGatewayIntents(\r\n intents: GatewayIntentResolvable,\r\n): number {\r\n if (typeof intents === \"number\") return intents;\r\n if (Array.isArray(intents)) {\r\n return intents.reduce<number>((acc, intent) => {\r\n return acc | resolveGatewayIntents(intent as any);\r\n }, 0);\r\n }\r\n if (typeof intents === \"string\") {\r\n if (intents in GatewayIntentBits)\r\n return (GatewayIntentBits as Record<string, number>)[intents]!;\r\n if (intents in IntentBits)\r\n return (IntentBits as Record<string, number>)[intents]!;\r\n const lower = intents.charAt(0).toLowerCase() + intents.slice(1);\r\n if (lower in IntentBits)\r\n return (IntentBits as Record<string, number>)[lower]!;\r\n const num = Number(intents);\r\n if (!Number.isNaN(num)) return num;\r\n }\r\n return 0;\r\n}\r\n\r\n/** Gateway connection properties (OS, browser, device). */\r\nexport interface GatewayProperties {\r\n os?: string;\r\n browser?: string;\r\n device?: string;\r\n [key: string]: unknown;\r\n}\r\n/** Gateway presence activity. */\r\nexport interface GatewayPresenceActivity {\r\n name: string;\r\n type?: number;\r\n url?: string;\r\n state?: string;\r\n}\r\n/** Gateway presence data. */\r\nexport interface GatewayPresence {\r\n status?: \"online\" | \"dnd\" | \"idle\" | \"invisible\" | \"offline\";\r\n activities?: GatewayPresenceActivity[];\r\n afk?: boolean;\r\n since?: number | null;\r\n}\r\n/** Client configuration. */\r\nexport interface ClientOptions {\r\n token: string;\r\n intents: GatewayIntentResolvable;\r\n gateway?: GatewayOptions;\r\n rest?: RESTOptions;\r\n}\r\n/** Gateway connection configuration. */\r\nexport interface GatewayOptions {\r\n intents?: GatewayIntentResolvable;\r\n reconnect?: boolean;\r\n maxReconnectAttempts?: number;\r\n reconnectBaseDelay?: number;\r\n reconnectMaxDelay?: number;\r\n shardId?: number;\r\n shardCount?: number;\r\n properties?: GatewayProperties;\r\n presence?: GatewayPresence;\r\n}\r\n\r\n/** REST request configuration. */\r\nexport interface RESTOptions {\r\n timeout?: number;\r\n retries?: number;\r\n baseURL?: string;\r\n}\r\n/** Discord user object. */\r\nexport interface UserData {\r\n id: Snowflake;\r\n username: string;\r\n discriminator?: string;\r\n global_name?: string | null;\r\n avatar?: string | null;\r\n bot?: boolean;\r\n system?: boolean;\r\n public_flags?: number;\r\n}\r\n/** Current authenticated bot user. */\r\nexport type ClientUser = UserData;\r\n/** Discord Gateway payload envelope. */\r\nexport interface GatewayPayload<T = unknown> {\r\n op: number;\r\n d: T | null;\r\n s: number | null;\r\n t: string | null;\r\n}\r\n/** Generic Discord API error payload. */\r\nexport interface APIError {\r\n code?: number;\r\n message?: string;\r\n errors?: Record<string, unknown>;\r\n}\r\n/** Discord message flags. */\r\nexport const MessageFlags = {\r\n Crossposted: 1,\r\n IsCrosspost: 2,\r\n SuppressEmbeds: 4,\r\n SourceMessageDeleted: 8,\r\n Urgent: 16,\r\n HasThread: 32,\r\n Ephemeral: 64,\r\n Loading: 128,\r\n IsComponentsV2: 32768,\r\n} as const;\r\n/** Discord channel types. */\r\nexport const ChannelType = {\r\n GuildText: 0,\r\n DM: 1,\r\n GuildVoice: 2,\r\n GroupDM: 3,\r\n GuildCategory: 4,\r\n GuildAnnouncement: 5,\r\n AnnouncementThread: 10,\r\n PublicThread: 11,\r\n PrivateThread: 12,\r\n GuildStageVoice: 13,\r\n GuildDirectory: 14,\r\n GuildForum: 15,\r\n GuildMedia: 16,\r\n} as const;\r\n\r\n/** Raw Discord embed object. */\r\nexport interface APIEmbed {\r\n title?: string;\r\n type?: string;\r\n description?: string;\r\n url?: string;\r\n timestamp?: string;\r\n color?: number;\r\n footer?: Record<string, unknown>;\r\n image?: Record<string, unknown>;\r\n thumbnail?: Record<string, unknown>;\r\n video?: Record<string, unknown>;\r\n provider?: Record<string, unknown>;\r\n author?: Record<string, unknown>;\r\n fields?: Array<Record<string, unknown>>;\r\n}\r\n/** Raw Discord attachment object. */\r\nexport interface APIAttachment {\r\n id: Snowflake;\r\n filename: string;\r\n description?: string | null;\r\n content_type?: string;\r\n size: number;\r\n url: string;\r\n proxy_url: string;\r\n height?: number | null;\r\n width?: number | null;\r\n ephemeral?: boolean;\r\n duration_secs?: number;\r\n waveform?: string;\r\n flags?: number;\r\n}\r\n/** Raw Discord message component object. */\r\nexport interface APIMessageComponent {\r\n type: number;\r\n id?: number;\r\n custom_id?: string;\r\n style?: number;\r\n label?: string;\r\n disabled?: boolean;\r\n emoji?: Record<string, unknown>;\r\n url?: string;\r\n options?: Array<Record<string, unknown>>;\r\n components?: APIMessageComponent[];\r\n}\r\n/** Raw Discord message reference. */\r\nexport interface APIMessageReference {\r\n type?: number;\r\n message_id?: Snowflake;\r\n channel_id?: Snowflake;\r\n guild_id?: Snowflake;\r\n fail_if_not_exists?: boolean;\r\n}\r\n/** Raw Discord message reaction. */\r\nexport interface APIMessageReaction {\r\n count: number;\r\n count_details?: Record<string, number>;\r\n me?: boolean;\r\n me_burst?: boolean;\r\n emoji: Record<string, unknown>;\r\n burst_colors?: string[];\r\n}\r\n/** Raw Discord message object. */\r\nexport interface APIMessage {\r\n id: Snowflake;\r\n channel_id: Snowflake;\r\n author: UserData;\r\n content: string;\r\n timestamp?: string;\r\n edited_timestamp?: string | null;\r\n tts?: boolean;\r\n mention_everyone?: boolean;\r\n mentions?: UserData[];\r\n mention_roles?: Snowflake[];\r\n mention_channels?: Array<Record<string, unknown>>;\r\n attachments?: APIAttachment[];\r\n embeds?: APIEmbed[];\r\n reactions?: APIMessageReaction[];\r\n nonce?: string | number | null;\r\n pinned?: boolean;\r\n webhook_id?: Snowflake;\r\n type?: number;\r\n activity?: Record<string, unknown>;\r\n application?: Record<string, unknown>;\r\n application_id?: Snowflake;\r\n message_reference?: APIMessageReference;\r\n flags?: number;\r\n referenced_message?: APIMessage | null;\r\n interaction_metadata?: Record<string, unknown>;\r\n thread?: Record<string, unknown>;\r\n components?: APIMessageComponent[];\r\n position?: number;\r\n role_subscription_data?: Record<string, unknown>;\r\n purchase_notification?: Record<string, unknown>;\r\n poll?: Record<string, unknown>;\r\n guild_id?: Snowflake;\r\n}\r\n/** Raw Discord channel object. */\r\nexport interface APIChannel {\r\n id: Snowflake;\r\n type: number;\r\n guild_id?: Snowflake;\r\n position?: number;\r\n permission_overwrites?: Array<Record<string, unknown>>;\r\n name?: string | null;\r\n topic?: string | null;\r\n nsfw?: boolean;\r\n last_message_id?: Snowflake | null;\r\n bitrate?: number;\r\n user_limit?: number;\r\n rate_limit_per_user?: number;\r\n recipients?: UserData[];\r\n icon?: string | null;\r\n owner_id?: Snowflake;\r\n application_id?: Snowflake;\r\n parent_id?: Snowflake | null;\r\n last_pin_timestamp?: string | null;\r\n rtc_region?: string | null;\r\n video_quality_mode?: number;\r\n message_count?: number;\r\n member_count?: number;\r\n thread_metadata?: Record<string, unknown>;\r\n default_auto_archive_duration?: number;\r\n flags?: number;\r\n total_message_sent?: number;\r\n available_tags?: Array<Record<string, unknown>>;\r\n default_reaction_emoji?: Record<string, unknown> | null;\r\n default_thread_rate_limit_per_user?: number;\r\n default_sort_order?: number | null;\r\n default_forum_layout?: number;\r\n}\r\n/** Raw Discord guild object. */\r\nexport interface APIGuild {\r\n id: Snowflake;\r\n name: string;\r\n icon?: string | null;\r\n icon_hash?: string | null;\r\n splash?: string | null;\r\n discovery_splash?: string | null;\r\n owner_id?: Snowflake;\r\n afk_channel_id?: Snowflake | null;\r\n afk_timeout?: number;\r\n widget_enabled?: boolean;\r\n widget_channel_id?: Snowflake | null;\r\n verification_level?: number;\r\n default_message_notifications?: number;\r\n explicit_content_filter?: number;\r\n roles?: Array<Record<string, unknown>>;\r\n emojis?: Array<Record<string, unknown>>;\r\n features?: string[];\r\n mfa_level?: number;\r\n application_id?: Snowflake | null;\r\n system_channel_id?: Snowflake | null;\r\n system_channel_flags?: number;\r\n rules_channel_id?: Snowflake | null;\r\n max_presences?: number | null;\r\n max_members?: number;\r\n vanity_url_code?: string | null;\r\n description?: string | null;\r\n banner?: string | null;\r\n premium_tier?: number;\r\n preferred_locale?: string;\r\n public_updates_channel_id?: Snowflake | null;\r\n max_video_channel_users?: number;\r\n approximate_member_count?: number;\r\n approximate_presence_count?: number;\r\n nsfw_level?: number;\r\n safety_alerts_channel_id?: Snowflake | null;\r\n}\r\n/** Raw Discord guild member object. */\r\nexport interface APIGuildMember {\r\n user: UserData;\r\n nick?: string | null;\r\n avatar?: string | null;\r\n roles: Snowflake[];\r\n joined_at: string;\r\n premium_since?: string | null;\r\n deaf?: boolean;\r\n mute?: boolean;\r\n flags?: number;\r\n pending?: boolean;\r\n permissions?: string;\r\n communication_disabled_until?: string | null;\r\n guild_id?: Snowflake;\r\n}\r\n/** Raw Discord reaction event payload. */\r\nexport interface APIMessageReactionEvent {\r\n user_id: Snowflake;\r\n channel_id: Snowflake;\r\n message_id: Snowflake;\r\n guild_id?: Snowflake;\r\n member?: APIGuildMember;\r\n emoji: Record<string, unknown>;\r\n message_author_id?: Snowflake;\r\n burst?: boolean;\r\n type?: number;\r\n}\r\n/** Raw Discord message deletion event payload. */\r\nexport interface APIMessageDeleteEvent {\r\n id: Snowflake;\r\n channel_id: Snowflake;\r\n guild_id?: Snowflake;\r\n}\r\n/** Raw Discord bulk message deletion event payload. */\r\nexport interface APIMessageDeleteBulkEvent {\r\n ids: Snowflake[];\r\n channel_id: Snowflake;\r\n guild_id?: Snowflake;\r\n}\r\n/** Raw Discord channel deletion event payload. */\r\nexport interface APIChannelDeleteEvent extends APIChannel {}\r\n/** Raw Discord guild deletion event payload. */\r\nexport interface APIGuildDeleteEvent {\r\n id: Snowflake;\r\n unavailable?: boolean;\r\n}\r\n/** Raw Discord thread lifecycle payload. */\r\nexport interface APIThreadEvent extends APIChannel {\r\n guild_id: Snowflake;\r\n member?: Record<string, unknown>;\r\n}\r\n/** Raw Discord READY event payload. */\r\nexport interface APIReadyEvent {\r\n v: number;\r\n user: UserData;\r\n guilds: Array<{ id: Snowflake; unavailable?: boolean }>;\r\n session_id: string;\r\n resume_gateway_url: string;\r\n shard?: [number, number];\r\n application?: { id: Snowflake; flags: number; [key: string]: unknown };\r\n}\r\n\r\n/** Discord application command option types. */\r\nexport const ApplicationCommandOptionType = {\r\n SubCommand: 1,\r\n SubCommandGroup: 2,\r\n String: 3,\r\n Integer: 4,\r\n Boolean: 5,\r\n User: 6,\r\n Channel: 7,\r\n Role: 8,\r\n Mentionable: 9,\r\n Number: 10,\r\n Attachment: 11,\r\n} as const;\r\n\r\n/** Discord application command types. */\r\nexport const ApplicationCommandType = {\r\n ChatInput: 1,\r\n User: 2,\r\n Message: 3,\r\n} as const;\r\n\r\n/** Raw Discord application command option. */\r\nexport interface APIApplicationCommandOption {\r\n type: number;\r\n name: string;\r\n description: string;\r\n required?: boolean;\r\n choices?: Array<{ name: string; value: string | number }>;\r\n options?: APIApplicationCommandOption[];\r\n min_value?: number;\r\n max_value?: number;\r\n min_length?: number;\r\n max_length?: number;\r\n autocomplete?: boolean;\r\n channel_types?: number[];\r\n}\r\n\r\n/** Raw Discord application command object (from API). */\r\nexport interface APIApplicationCommand {\r\n id: Snowflake;\r\n type?: number;\r\n application_id: Snowflake;\r\n guild_id?: Snowflake;\r\n name: string;\r\n description: string;\r\n options?: APIApplicationCommandOption[];\r\n default_member_permissions?: string | null;\r\n dm_permission?: boolean;\r\n nsfw?: boolean;\r\n version: Snowflake;\r\n}\r\n\r\n/** Data for creating/overwriting an application command. */\r\nexport interface ApplicationCommandData {\r\n name: string;\r\n description: string;\r\n type?: number;\r\n options?: APIApplicationCommandOption[];\r\n default_member_permissions?: string | null;\r\n dm_permission?: boolean;\r\n nsfw?: boolean;\r\n}\r\n\r\n/** Raw Discord role object. */\r\nexport interface APIRole {\r\n id: Snowflake;\r\n name: string;\r\n color: number;\r\n hoist: boolean;\r\n icon?: string | null;\r\n unicode_emoji?: string | null;\r\n position: number;\r\n permissions: string;\r\n managed: boolean;\r\n mentionable: boolean;\r\n tags?: Record<string, unknown>;\r\n flags?: number;\r\n}\r\n\r\n/** Raw Discord guild role event payload. */\r\nexport interface APIGuildRoleEvent {\r\n guild_id: Snowflake;\r\n role: APIRole;\r\n}\r\n\r\n/** Raw Discord guild role delete event payload. */\r\nexport interface APIGuildRoleDeleteEvent {\r\n guild_id: Snowflake;\r\n role_id: Snowflake;\r\n}\r\n\r\n/** Raw Discord guild ban event payload. */\r\nexport interface APIGuildBanEvent {\r\n guild_id: Snowflake;\r\n user: UserData;\r\n}\r\n\r\n/** Raw Discord emoji object. */\r\nexport interface APIEmoji {\r\n id: Snowflake | null;\r\n name: string | null;\r\n roles?: Snowflake[];\r\n user?: UserData;\r\n require_colons?: boolean;\r\n managed?: boolean;\r\n animated?: boolean;\r\n available?: boolean;\r\n}\r\n\r\n/** Raw Discord guild emojis update event payload. */\r\nexport interface APIGuildEmojisUpdateEvent {\r\n guild_id: Snowflake;\r\n emojis: APIEmoji[];\r\n}\r\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;AAIO,IAAM,oBAAoB;AAAA,EAC/B,QAAQ,KAAK;AAAA,EACb,cAAc,KAAK;AAAA,EACnB,iBAAiB,KAAK;AAAA,EACtB,kBAAkB,KAAK;AAAA,EACvB,mBAAmB,KAAK;AAAA,EACxB,eAAe,KAAK;AAAA,EACpB,cAAc,KAAK;AAAA,EACnB,kBAAkB,KAAK;AAAA,EACvB,gBAAgB,KAAK;AAAA,EACrB,eAAe,KAAK;AAAA,EACpB,uBAAuB,KAAK;AAAA,EAC5B,oBAAoB,KAAK;AAAA,EACzB,gBAAgB,KAAK;AAAA,EACrB,wBAAwB,KAAK;AAAA,EAC7B,qBAAqB,KAAK;AAAA,EAC1B,gBAAgB,KAAK;AAAA,EACrB,sBAAsB,KAAK;AAAA,EAC3B,6BAA6B,KAAK;AAAA,EAClC,yBAAyB,KAAK;AAAA,EAC9B,mBAAmB,KAAK;AAAA,EACxB,oBAAoB,KAAK;AAC3B;AAGO,IAAM,aAAa;AAAA,EACxB,OAAO,KAAK;AAAA,EACZ,QAAQ,KAAK;AAAA,EACb,cAAc,KAAK;AAAA,EACnB,iBAAiB,KAAK;AAAA,EACtB,WAAW,KAAK;AAAA,EAChB,kBAAkB,KAAK;AAAA,EACvB,aAAa,KAAK;AAAA,EAClB,wBAAwB,KAAK;AAAA,EAC7B,mBAAmB,KAAK;AAAA,EACxB,eAAe,KAAK;AAAA,EACpB,cAAc,KAAK;AAAA,EACnB,kBAAkB,KAAK;AAAA,EACvB,gBAAgB,KAAK;AAAA,EACrB,eAAe,KAAK;AAAA,EACpB,cAAc,KAAK;AAAA,EACnB,uBAAuB,KAAK;AAAA,EAC5B,oBAAoB,KAAK;AAAA,EACz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BAAoB;AAAA,EACpB,cAAc;AAAA,EACd,eAAe;AAAA,EACf,iBAAiB;AAAA,EACjB,gBAAgB;AAAA,EAChB,YAAY;AAAA,EACZ,YAAY;AACd;AA2OO,IAAM,+BAA+B;AAAA,EAC1C,YAAY;AAAA,EACZ,iBAAiB;AAAA,EACjB,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,SAAS;AAAA,EACT,MAAM;AAAA,EACN,SAAS;AAAA,EACT,MAAM;AAAA,EACN,aAAa;AAAA,EACb,QAAQ;AAAA,EACR,YAAY;AACd;AAGO,IAAM,yBAAyB;AAAA,EACpC,WAAW;AAAA,EACX,MAAM;AAAA,EACN,SAAS;AACX;",
|
|
8
|
+
"debugId": "FE618CA7F2A5EFE164756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Returns a promise that resolves after the specified duration. */
|
|
2
|
+
export declare function sleep(ms: number): Promise<void>;
|
|
3
|
+
/** Returns an integer between the supplied inclusive bounds. */
|
|
4
|
+
export declare function randomInt(min: number, max: number): number;
|
|
5
|
+
/** Tests whether a value is a Discord snowflake-like ID. */
|
|
6
|
+
export declare function isSnowflake(value: string): boolean;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/utils/src/index.ts
|
|
3
|
+
function sleep(ms) {
|
|
4
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
5
|
+
}
|
|
6
|
+
function randomInt(min, max) {
|
|
7
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
8
|
+
}
|
|
9
|
+
function isSnowflake(value) {
|
|
10
|
+
return /^\d{16,22}$/.test(value);
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
isSnowflake,
|
|
14
|
+
randomInt,
|
|
15
|
+
sleep
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
//# debugId=4F20A8D367F5985F64756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../packages/utils/src/index.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/** Returns a promise that resolves after the specified duration. */\nexport function sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\n/** Returns an integer between the supplied inclusive bounds. */\nexport function randomInt(min: number, max: number): number {\n return Math.floor(Math.random() * (max - min + 1)) + min;\n}\n\n/** Tests whether a value is a Discord snowflake-like ID. */\nexport function isSnowflake(value: string): boolean {\n return /^\\d{16,22}$/.test(value);\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;AACO,SAAS,KAAK,CAAC,IAA2B;AAAA,EAC/C,OAAO,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,EAAE,CAAC;AAAA;AAIlD,SAAS,SAAS,CAAC,KAAa,KAAqB;AAAA,EAC1D,OAAO,KAAK,MAAM,KAAK,OAAO,KAAK,MAAM,MAAM,EAAE,IAAI;AAAA;AAIhD,SAAS,WAAW,CAAC,OAAwB;AAAA,EAClD,OAAO,cAAc,KAAK,KAAK;AAAA;",
|
|
8
|
+
"debugId": "4F20A8D367F5985F64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/** Voice session lifecycle states. */
|
|
2
|
+
export declare enum VoiceConnectionState {
|
|
3
|
+
Disconnected = "disconnected",
|
|
4
|
+
Connecting = "connecting",
|
|
5
|
+
Connected = "connected",
|
|
6
|
+
Destroyed = "destroyed"
|
|
7
|
+
}
|
|
8
|
+
/** Voice protocol transport errors. */
|
|
9
|
+
export declare class VoiceError extends Error {
|
|
10
|
+
/** Creates a voice error. @param message Error message. @param options Optional native error options. */
|
|
11
|
+
constructor(message: string, options?: ErrorOptions);
|
|
12
|
+
}
|
|
13
|
+
/** Options used to establish a voice session. */
|
|
14
|
+
export interface VoiceConnectionOptions {
|
|
15
|
+
/** Guild containing the voice channel. */
|
|
16
|
+
guildId: string;
|
|
17
|
+
/** Voice channel to join. */
|
|
18
|
+
channelId?: string;
|
|
19
|
+
/** Whether the self user should be muted. */
|
|
20
|
+
selfMute?: boolean;
|
|
21
|
+
/** Whether the self user should be deafened. */
|
|
22
|
+
selfDeaf?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/** UDP transport supplied by the runtime-specific voice implementation. */
|
|
25
|
+
export interface VoiceUdpTransport {
|
|
26
|
+
/** Sends an RTP/RTCP packet. @param packet Packet bytes. @param host Destination host. @param port Destination port. @returns Optional completion promise. */
|
|
27
|
+
send(packet: Uint8Array, host: string, port: number): Promise<void> | void;
|
|
28
|
+
/** Closes the UDP socket. @returns Nothing. */
|
|
29
|
+
close(): void;
|
|
30
|
+
}
|
|
31
|
+
/** Voice Gateway transport abstraction. */
|
|
32
|
+
export interface VoiceGatewayTransport {
|
|
33
|
+
/** Opens the voice gateway. @param endpoint Voice gateway endpoint. @param sessionId Voice session identifier. @returns Promise fulfilled when connected. */
|
|
34
|
+
connect(endpoint: string, sessionId: string): Promise<void>;
|
|
35
|
+
/** Sends a voice gateway payload. @param payload Gateway payload. @returns Nothing. */
|
|
36
|
+
send(payload: unknown): void;
|
|
37
|
+
/** Closes the voice gateway. @param code Optional close code. @param reason Optional close reason. @returns Nothing. */
|
|
38
|
+
close(code?: number, reason?: string): void;
|
|
39
|
+
}
|
|
40
|
+
/** Speaking flags used by the voice gateway. */
|
|
41
|
+
export declare const SpeakingFlags: {
|
|
42
|
+
readonly Microphone: 1;
|
|
43
|
+
readonly Soundshare: 2;
|
|
44
|
+
readonly Priority: 4;
|
|
45
|
+
};
|
|
46
|
+
/** Voice session event payloads. */
|
|
47
|
+
export interface VoiceEvents {
|
|
48
|
+
/** State transition event. */
|
|
49
|
+
stateChange: [VoiceConnectionState, VoiceConnectionState];
|
|
50
|
+
/** Speaking flag event. */
|
|
51
|
+
speaking: [number, number];
|
|
52
|
+
/** Voice transport error event. */
|
|
53
|
+
error: [VoiceError];
|
|
54
|
+
}
|
|
55
|
+
/** Tracks a Discord voice session and exposes transport-independent lifecycle controls. */
|
|
56
|
+
export declare class VoiceConnection {
|
|
57
|
+
#private;
|
|
58
|
+
/** Current voice connection state. */
|
|
59
|
+
state: VoiceConnectionState;
|
|
60
|
+
/** Guild associated with this voice session. */
|
|
61
|
+
readonly guildId: string;
|
|
62
|
+
/** Voice channel associated with this session. */
|
|
63
|
+
channelId?: string;
|
|
64
|
+
/** Whether the client is self-muted. */
|
|
65
|
+
selfMute: boolean;
|
|
66
|
+
/** Whether the client is self-deafened. */
|
|
67
|
+
selfDeaf: boolean;
|
|
68
|
+
/** Active voice gateway transport, when attached. */
|
|
69
|
+
gateway?: VoiceGatewayTransport;
|
|
70
|
+
/** Active UDP transport, when attached. */
|
|
71
|
+
udp?: VoiceUdpTransport;
|
|
72
|
+
/** Creates a voice connection state manager. @param options Guild ID or connection options. @throws {TypeError} If the guild ID is empty. */
|
|
73
|
+
constructor(options: string | VoiceConnectionOptions);
|
|
74
|
+
/** Registers a voice lifecycle listener. @param event Event name. @param listener Listener callback. @returns This connection. @throws {TypeError} If listener is not callable. */
|
|
75
|
+
on<K extends keyof VoiceEvents>(event: K, listener: (...args: VoiceEvents[K]) => unknown): this;
|
|
76
|
+
/** Removes a voice lifecycle listener. @param event Event name. @param listener Listener callback. @returns This connection. */
|
|
77
|
+
off<K extends keyof VoiceEvents>(event: K, listener: (...args: VoiceEvents[K]) => unknown): this;
|
|
78
|
+
/** Attaches protocol transports, replacing and cleaning up the old pair when present. @param gateway Voice gateway transport. @param udp UDP transport. @returns This connection. @throws {VoiceError} If the connection is destroyed. @throws {TypeError} If a transport is missing. */
|
|
79
|
+
attachTransports(gateway: VoiceGatewayTransport, udp: VoiceUdpTransport): this;
|
|
80
|
+
/** Begins the connection lifecycle. @returns Nothing. @throws {VoiceError} If the connection is destroyed. */
|
|
81
|
+
connect(): void;
|
|
82
|
+
/** Disconnects the current voice session. @returns Nothing. */
|
|
83
|
+
disconnect(): void;
|
|
84
|
+
/** Permanently destroys this voice connection. @returns Nothing. */
|
|
85
|
+
destroy(): void;
|
|
86
|
+
/** Updates the voice channel and connection state. @param channelId Voice channel identifier. @returns Nothing. @throws {VoiceError} If the connection is destroyed. @throws {TypeError} If channelId is empty. */
|
|
87
|
+
setChannel(channelId: string): void;
|
|
88
|
+
/** Updates self mute/deaf state. @param options Suppression flags. @returns Nothing. @throws {VoiceError} If the connection is destroyed. */
|
|
89
|
+
setSuppression(options: {
|
|
90
|
+
selfMute?: boolean;
|
|
91
|
+
selfDeaf?: boolean;
|
|
92
|
+
}): void;
|
|
93
|
+
/** Publishes a speaking state through the attached voice gateway. @param flags Speaking flags. @returns Nothing. @throws {VoiceError} If the connection is destroyed or has no gateway transport. */
|
|
94
|
+
setSpeaking(flags?: number): void;
|
|
95
|
+
/** Ensures the connection is still usable. @returns Nothing. @throws {VoiceError} If destroyed. */
|
|
96
|
+
private assertUsable;
|
|
97
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/voice/src/index.ts
|
|
3
|
+
var VoiceConnectionState;
|
|
4
|
+
((VoiceConnectionState2) => {
|
|
5
|
+
VoiceConnectionState2["Disconnected"] = "disconnected";
|
|
6
|
+
VoiceConnectionState2["Connecting"] = "connecting";
|
|
7
|
+
VoiceConnectionState2["Connected"] = "connected";
|
|
8
|
+
VoiceConnectionState2["Destroyed"] = "destroyed";
|
|
9
|
+
})(VoiceConnectionState ||= {});
|
|
10
|
+
|
|
11
|
+
class VoiceError extends Error {
|
|
12
|
+
constructor(message, options) {
|
|
13
|
+
super(message, options);
|
|
14
|
+
this.name = "VoiceError";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
var SpeakingFlags = {
|
|
18
|
+
Microphone: 1,
|
|
19
|
+
Soundshare: 2,
|
|
20
|
+
Priority: 4
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
class VoiceConnection {
|
|
24
|
+
state = "disconnected" /* Disconnected */;
|
|
25
|
+
guildId;
|
|
26
|
+
channelId;
|
|
27
|
+
selfMute;
|
|
28
|
+
selfDeaf;
|
|
29
|
+
gateway;
|
|
30
|
+
udp;
|
|
31
|
+
#listeners = new Map;
|
|
32
|
+
constructor(options) {
|
|
33
|
+
const resolved = typeof options === "string" ? { guildId: options } : options;
|
|
34
|
+
if (!resolved.guildId?.trim()) {
|
|
35
|
+
throw new TypeError("A guild ID is required for a voice connection.");
|
|
36
|
+
}
|
|
37
|
+
this.guildId = resolved.guildId;
|
|
38
|
+
this.channelId = resolved.channelId;
|
|
39
|
+
this.selfMute = resolved.selfMute ?? false;
|
|
40
|
+
this.selfDeaf = resolved.selfDeaf ?? false;
|
|
41
|
+
}
|
|
42
|
+
on(event, listener) {
|
|
43
|
+
if (typeof listener !== "function")
|
|
44
|
+
throw new TypeError("Voice listener must be a function.");
|
|
45
|
+
let listeners = this.#listeners.get(event);
|
|
46
|
+
if (!listeners)
|
|
47
|
+
this.#listeners.set(event, listeners = new Set);
|
|
48
|
+
listeners.add(listener);
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
off(event, listener) {
|
|
52
|
+
this.#listeners.get(event)?.delete(listener);
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
attachTransports(gateway, udp) {
|
|
56
|
+
this.assertUsable();
|
|
57
|
+
if (!gateway || !udp)
|
|
58
|
+
throw new TypeError("Both voice gateway and UDP transports are required.");
|
|
59
|
+
if (this.gateway || this.udp)
|
|
60
|
+
this.#closeTransports();
|
|
61
|
+
this.gateway = gateway;
|
|
62
|
+
this.udp = udp;
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
connect() {
|
|
66
|
+
this.assertUsable();
|
|
67
|
+
if (this.state === "connected" /* Connected */)
|
|
68
|
+
return;
|
|
69
|
+
this.#transition("connecting" /* Connecting */);
|
|
70
|
+
if (this.state !== "connecting" /* Connecting */)
|
|
71
|
+
return;
|
|
72
|
+
this.#transition("connected" /* Connected */);
|
|
73
|
+
}
|
|
74
|
+
disconnect() {
|
|
75
|
+
if (this.state === "destroyed" /* Destroyed */)
|
|
76
|
+
return;
|
|
77
|
+
this.#closeTransports();
|
|
78
|
+
this.#transition("disconnected" /* Disconnected */);
|
|
79
|
+
}
|
|
80
|
+
destroy() {
|
|
81
|
+
if (this.state === "destroyed" /* Destroyed */)
|
|
82
|
+
return;
|
|
83
|
+
this.#closeTransports();
|
|
84
|
+
this.channelId = undefined;
|
|
85
|
+
this.#transition("destroyed" /* Destroyed */);
|
|
86
|
+
this.#listeners.clear();
|
|
87
|
+
}
|
|
88
|
+
setChannel(channelId) {
|
|
89
|
+
this.assertUsable();
|
|
90
|
+
if (!channelId?.trim())
|
|
91
|
+
throw new TypeError("A voice channel ID is required.");
|
|
92
|
+
this.channelId = channelId;
|
|
93
|
+
}
|
|
94
|
+
setSuppression(options) {
|
|
95
|
+
this.assertUsable();
|
|
96
|
+
if (options.selfMute !== undefined)
|
|
97
|
+
this.selfMute = options.selfMute;
|
|
98
|
+
if (options.selfDeaf !== undefined)
|
|
99
|
+
this.selfDeaf = options.selfDeaf;
|
|
100
|
+
}
|
|
101
|
+
setSpeaking(flags = SpeakingFlags.Microphone) {
|
|
102
|
+
this.assertUsable();
|
|
103
|
+
if (!this.gateway) {
|
|
104
|
+
throw new VoiceError("A voice gateway transport is required to change speaking state.");
|
|
105
|
+
}
|
|
106
|
+
this.gateway.send({ op: 5, d: { speaking: flags, delay: 0, ssrc: 0 } });
|
|
107
|
+
this.#emit("speaking", flags, 0);
|
|
108
|
+
}
|
|
109
|
+
#assertUsable() {
|
|
110
|
+
if (this.state === "destroyed" /* Destroyed */) {
|
|
111
|
+
throw new VoiceError("Voice connection has been destroyed.");
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
#closeTransports() {
|
|
115
|
+
try {
|
|
116
|
+
this.gateway?.close(1000, "Voice connection replaced or closed");
|
|
117
|
+
} catch (error) {
|
|
118
|
+
this.#emit("error", error instanceof VoiceError ? error : new VoiceError("Voice gateway cleanup failed.", { cause: error }));
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
this.udp?.close();
|
|
122
|
+
} catch (error) {
|
|
123
|
+
this.#emit("error", error instanceof VoiceError ? error : new VoiceError("Voice UDP cleanup failed.", { cause: error }));
|
|
124
|
+
}
|
|
125
|
+
this.gateway = undefined;
|
|
126
|
+
this.udp = undefined;
|
|
127
|
+
}
|
|
128
|
+
#transition(next) {
|
|
129
|
+
const previous = this.state;
|
|
130
|
+
this.state = next;
|
|
131
|
+
if (previous === next)
|
|
132
|
+
return;
|
|
133
|
+
for (const listener of this.#listeners.get("stateChange") ?? []) {
|
|
134
|
+
try {
|
|
135
|
+
listener(next, previous);
|
|
136
|
+
} catch (error) {
|
|
137
|
+
this.#emit("error", error instanceof VoiceError ? error : new VoiceError("Voice event listener failed.", { cause: error }));
|
|
138
|
+
}
|
|
139
|
+
if (this.state !== next && next !== "destroyed" /* Destroyed */)
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
#emit(event, ...args) {
|
|
144
|
+
for (const listener of this.#listeners.get(event) ?? []) {
|
|
145
|
+
try {
|
|
146
|
+
listener(...args);
|
|
147
|
+
} catch {}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
assertUsable() {
|
|
151
|
+
this.#assertUsable();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
export {
|
|
155
|
+
SpeakingFlags,
|
|
156
|
+
VoiceConnection,
|
|
157
|
+
VoiceConnectionState,
|
|
158
|
+
VoiceError
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
//# debugId=B72F5E80ABB620A864756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../packages/voice/src/index.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/** Voice session lifecycle states. */\r\nexport enum VoiceConnectionState {\r\n Disconnected = \"disconnected\",\r\n Connecting = \"connecting\",\r\n Connected = \"connected\",\r\n Destroyed = \"destroyed\",\r\n}\r\n\r\n/** Voice protocol transport errors. */\r\nexport class VoiceError extends Error {\r\n /** Creates a voice error. @param message Error message. @param options Optional native error options. */\r\n public constructor(message: string, options?: ErrorOptions) {\r\n super(message, options);\r\n this.name = \"VoiceError\";\r\n }\r\n}\r\n\r\n/** Options used to establish a voice session. */\r\nexport interface VoiceConnectionOptions {\r\n /** Guild containing the voice channel. */\r\n guildId: string;\r\n /** Voice channel to join. */\r\n channelId?: string;\r\n /** Whether the self user should be muted. */\r\n selfMute?: boolean;\r\n /** Whether the self user should be deafened. */\r\n selfDeaf?: boolean;\r\n}\r\n\r\n/** UDP transport supplied by the runtime-specific voice implementation. */\r\nexport interface VoiceUdpTransport {\r\n /** Sends an RTP/RTCP packet. @param packet Packet bytes. @param host Destination host. @param port Destination port. @returns Optional completion promise. */\r\n send(packet: Uint8Array, host: string, port: number): Promise<void> | void;\r\n /** Closes the UDP socket. @returns Nothing. */\r\n close(): void;\r\n}\r\n\r\n/** Voice Gateway transport abstraction. */\r\nexport interface VoiceGatewayTransport {\r\n /** Opens the voice gateway. @param endpoint Voice gateway endpoint. @param sessionId Voice session identifier. @returns Promise fulfilled when connected. */\r\n connect(endpoint: string, sessionId: string): Promise<void>;\r\n /** Sends a voice gateway payload. @param payload Gateway payload. @returns Nothing. */\r\n send(payload: unknown): void;\r\n /** Closes the voice gateway. @param code Optional close code. @param reason Optional close reason. @returns Nothing. */\r\n close(code?: number, reason?: string): void;\r\n}\r\n\r\n/** Speaking flags used by the voice gateway. */\r\nexport const SpeakingFlags = {\r\n Microphone: 1,\r\n Soundshare: 2,\r\n Priority: 4,\r\n} as const;\r\n\r\n/** Voice session event payloads. */\r\nexport interface VoiceEvents {\r\n /** State transition event. */\r\n stateChange: [VoiceConnectionState, VoiceConnectionState];\r\n /** Speaking flag event. */\r\n speaking: [number, number];\r\n /** Voice transport error event. */\r\n error: [VoiceError];\r\n}\r\n\r\ntype VoiceListener = (...args: any[]) => unknown;\r\n\r\n/** Tracks a Discord voice session and exposes transport-independent lifecycle controls. */\r\nexport class VoiceConnection {\r\n /** Current voice connection state. */\r\n public state: VoiceConnectionState = VoiceConnectionState.Disconnected;\r\n /** Guild associated with this voice session. */\r\n public readonly guildId: string;\r\n /** Voice channel associated with this session. */\r\n public channelId?: string;\r\n /** Whether the client is self-muted. */\r\n public selfMute: boolean;\r\n /** Whether the client is self-deafened. */\r\n public selfDeaf: boolean;\r\n /** Active voice gateway transport, when attached. */\r\n public gateway?: VoiceGatewayTransport;\r\n /** Active UDP transport, when attached. */\r\n public udp?: VoiceUdpTransport;\r\n /** Registered lifecycle listeners. */\r\n readonly #listeners = new Map<keyof VoiceEvents, Set<VoiceListener>>();\r\n\r\n /** Creates a voice connection state manager. @param options Guild ID or connection options. @throws {TypeError} If the guild ID is empty. */\r\n public constructor(options: string | VoiceConnectionOptions) {\r\n const resolved =\r\n typeof options === \"string\" ? { guildId: options } : options;\r\n if (!resolved.guildId?.trim()) {\r\n throw new TypeError(\"A guild ID is required for a voice connection.\");\r\n }\r\n this.guildId = resolved.guildId;\r\n this.channelId = resolved.channelId;\r\n this.selfMute = resolved.selfMute ?? false;\r\n this.selfDeaf = resolved.selfDeaf ?? false;\r\n }\r\n\r\n /** Registers a voice lifecycle listener. @param event Event name. @param listener Listener callback. @returns This connection. @throws {TypeError} If listener is not callable. */\r\n public on<K extends keyof VoiceEvents>(\r\n event: K,\r\n listener: (...args: VoiceEvents[K]) => unknown,\r\n ): this {\r\n if (typeof listener !== \"function\")\r\n throw new TypeError(\"Voice listener must be a function.\");\r\n let listeners = this.#listeners.get(event);\r\n if (!listeners) this.#listeners.set(event, (listeners = new Set()));\r\n listeners.add(listener);\r\n return this;\r\n }\r\n\r\n /** Removes a voice lifecycle listener. @param event Event name. @param listener Listener callback. @returns This connection. */\r\n public off<K extends keyof VoiceEvents>(\r\n event: K,\r\n listener: (...args: VoiceEvents[K]) => unknown,\r\n ): this {\r\n this.#listeners.get(event)?.delete(listener);\r\n return this;\r\n }\r\n\r\n /** Attaches protocol transports, replacing and cleaning up the old pair when present. @param gateway Voice gateway transport. @param udp UDP transport. @returns This connection. @throws {VoiceError} If the connection is destroyed. @throws {TypeError} If a transport is missing. */\r\n public attachTransports(\r\n gateway: VoiceGatewayTransport,\r\n udp: VoiceUdpTransport,\r\n ): this {\r\n this.assertUsable();\r\n if (!gateway || !udp)\r\n throw new TypeError(\r\n \"Both voice gateway and UDP transports are required.\",\r\n );\r\n if (this.gateway || this.udp) this.#closeTransports();\r\n this.gateway = gateway;\r\n this.udp = udp;\r\n return this;\r\n }\r\n\r\n /** Begins the connection lifecycle. @returns Nothing. @throws {VoiceError} If the connection is destroyed. */\r\n public connect(): void {\r\n this.assertUsable();\r\n if (this.state === VoiceConnectionState.Connected) return;\r\n this.#transition(VoiceConnectionState.Connecting);\r\n if (this.state !== VoiceConnectionState.Connecting) return;\r\n this.#transition(VoiceConnectionState.Connected);\r\n }\r\n\r\n /** Disconnects the current voice session. @returns Nothing. */\r\n public disconnect(): void {\r\n if (this.state === VoiceConnectionState.Destroyed) return;\r\n this.#closeTransports();\r\n this.#transition(VoiceConnectionState.Disconnected);\r\n }\r\n\r\n /** Permanently destroys this voice connection. @returns Nothing. */\r\n public destroy(): void {\r\n if (this.state === VoiceConnectionState.Destroyed) return;\r\n this.#closeTransports();\r\n this.channelId = undefined;\r\n this.#transition(VoiceConnectionState.Destroyed);\r\n this.#listeners.clear();\r\n }\r\n\r\n /** Updates the voice channel and connection state. @param channelId Voice channel identifier. @returns Nothing. @throws {VoiceError} If the connection is destroyed. @throws {TypeError} If channelId is empty. */\r\n public setChannel(channelId: string): void {\r\n this.assertUsable();\r\n if (!channelId?.trim())\r\n throw new TypeError(\"A voice channel ID is required.\");\r\n this.channelId = channelId;\r\n }\r\n\r\n /** Updates self mute/deaf state. @param options Suppression flags. @returns Nothing. @throws {VoiceError} If the connection is destroyed. */\r\n public setSuppression(options: {\r\n selfMute?: boolean;\r\n selfDeaf?: boolean;\r\n }): void {\r\n this.assertUsable();\r\n if (options.selfMute !== undefined) this.selfMute = options.selfMute;\r\n if (options.selfDeaf !== undefined) this.selfDeaf = options.selfDeaf;\r\n }\r\n\r\n /** Publishes a speaking state through the attached voice gateway. @param flags Speaking flags. @returns Nothing. @throws {VoiceError} If the connection is destroyed or has no gateway transport. */\r\n public setSpeaking(flags: number = SpeakingFlags.Microphone): void {\r\n this.assertUsable();\r\n if (!this.gateway) {\r\n throw new VoiceError(\r\n \"A voice gateway transport is required to change speaking state.\",\r\n );\r\n }\r\n this.gateway.send({ op: 5, d: { speaking: flags, delay: 0, ssrc: 0 } });\r\n this.#emit(\"speaking\", flags, 0);\r\n }\r\n\r\n /** Ensures the connection is still usable. @returns Nothing. @throws {VoiceError} If destroyed. */\r\n #assertUsable(): void {\r\n if (this.state === VoiceConnectionState.Destroyed) {\r\n throw new VoiceError(\"Voice connection has been destroyed.\");\r\n }\r\n }\r\n\r\n /** Closes both active transports while isolating cleanup failures. @returns Nothing. */\r\n #closeTransports(): void {\r\n try {\r\n this.gateway?.close(1000, \"Voice connection replaced or closed\");\r\n } catch (error) {\r\n this.#emit(\r\n \"error\",\r\n error instanceof VoiceError\r\n ? error\r\n : new VoiceError(\"Voice gateway cleanup failed.\", { cause: error }),\r\n );\r\n }\r\n try {\r\n this.udp?.close();\r\n } catch (error) {\r\n this.#emit(\r\n \"error\",\r\n error instanceof VoiceError\r\n ? error\r\n : new VoiceError(\"Voice UDP cleanup failed.\", { cause: error }),\r\n );\r\n }\r\n this.gateway = undefined;\r\n this.udp = undefined;\r\n }\r\n\r\n /** Transitions to a new lifecycle state and emits the transition event. @param next Next state. @returns Nothing. */\r\n #transition(next: VoiceConnectionState): void {\r\n const previous = this.state;\r\n this.state = next;\r\n if (previous === next) return;\r\n for (const listener of this.#listeners.get(\"stateChange\") ?? []) {\r\n try {\r\n void listener(next, previous);\r\n } catch (error) {\r\n this.#emit(\r\n \"error\",\r\n error instanceof VoiceError\r\n ? error\r\n : new VoiceError(\"Voice event listener failed.\", { cause: error }),\r\n );\r\n }\r\n if (this.state !== next && next !== VoiceConnectionState.Destroyed)\r\n return;\r\n }\r\n }\r\n\r\n /** Emits a voice event while isolating consumer failures. @param event Event name. @param args Event arguments. @returns Nothing. */\r\n #emit<K extends keyof VoiceEvents>(event: K, ...args: VoiceEvents[K]): void {\r\n for (const listener of this.#listeners.get(event) ?? []) {\r\n try {\r\n void listener(...args);\r\n } catch {\r\n /* Consumer failures are isolated. */\r\n }\r\n }\r\n }\r\n\r\n /** Ensures the connection is still usable. @returns Nothing. @throws {VoiceError} If destroyed. */\r\n private assertUsable(): void {\r\n this.#assertUsable();\r\n }\r\n}\r\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;AACO,IAAK;AAAA,CAAL,CAAK,0BAAL;AAAA,EACL,wCAAe;AAAA,EACf,sCAAa;AAAA,EACb,qCAAY;AAAA,EACZ,qCAAY;AAAA,GAJF;AAAA;AAQL,MAAM,mBAAmB,MAAM;AAAA,EAE7B,WAAW,CAAC,SAAiB,SAAwB;AAAA,IAC1D,MAAM,SAAS,OAAO;AAAA,IACtB,KAAK,OAAO;AAAA;AAEhB;AAiCO,IAAM,gBAAgB;AAAA,EAC3B,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,UAAU;AACZ;AAAA;AAeO,MAAM,gBAAgB;AAAA,EAEpB,QAA8B;AAAA,EAErB;AAAA,EAET;AAAA,EAEA;AAAA,EAEA;AAAA,EAEA;AAAA,EAEA;AAAA,EAEE,aAAa,IAAI;AAAA,EAGnB,WAAW,CAAC,SAA0C;AAAA,IAC3D,MAAM,WACJ,OAAO,YAAY,WAAW,EAAE,SAAS,QAAQ,IAAI;AAAA,IACvD,IAAI,CAAC,SAAS,SAAS,KAAK,GAAG;AAAA,MAC7B,MAAM,IAAI,UAAU,gDAAgD;AAAA,IAC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,OAAO,MAAM,CAAC,CAClE;AAAA;AAAA,IAEF,KAAK,UAAU;AAAA,IACf,KAAK,MAAM;AAAA;AAAA,EAIb,WAAW,CAAC,MAAkC;AAAA,IAC5C,MAAM,WAAW,KAAK;AAAA,IACtB,KAAK,QAAQ;AAAA,IACb,IAAI,aAAa;AAAA,MAAM;AAAA,IACvB,WAAW,YAAY,KAAK,WAAW,IAAI,aAAa,KAAK,CAAC,GAAG;AAAA,MAC/D,IAAI;AAAA,QACG,SAAS,MAAM,QAAQ;AAAA,QAC5B,OAAO,OAAO;AAAA,QACd,KAAK,MACH,SACA,iBAAiB,aACb,QACA,IAAI,WAAW,gCAAgC,EAAE,OAAO,MAAM,CAAC,CACrE;AAAA;AAAA,MAEF,IAAI,KAAK,UAAU,QAAQ,SAAS;AAAA,QAClC;AAAA,IACJ;AAAA;AAAA,EAIF,KAAkC,CAAC,UAAa,MAA4B;AAAA,IAC1E,WAAW,YAAY,KAAK,WAAW,IAAI,KAAK,KAAK,CAAC,GAAG;AAAA,MACvD,IAAI;AAAA,QACG,SAAS,GAAG,IAAI;AAAA,QACrB,MAAM;AAAA,IAGV;AAAA;AAAA,EAIM,YAAY,GAAS;AAAA,IAC3B,KAAK,cAAc;AAAA;AAEvB;",
|
|
8
|
+
"debugId": "B72F5E80ABB620A864756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { type GatewayPayload, type GatewayProperties, type GatewayPresence, type GatewayIntentResolvable } from "@lunibee/types";
|
|
2
|
+
/** Discord Gateway opcodes. */
|
|
3
|
+
export declare const GatewayOpcodes: {
|
|
4
|
+
readonly Dispatch: 0;
|
|
5
|
+
readonly Heartbeat: 1;
|
|
6
|
+
readonly Identify: 2;
|
|
7
|
+
readonly PresenceUpdate: 3;
|
|
8
|
+
readonly VoiceStateUpdate: 4;
|
|
9
|
+
readonly Resume: 6;
|
|
10
|
+
readonly Reconnect: 7;
|
|
11
|
+
readonly RequestGuildMembers: 8;
|
|
12
|
+
readonly InvalidSession: 9;
|
|
13
|
+
readonly Hello: 10;
|
|
14
|
+
readonly HeartbeatAck: 11;
|
|
15
|
+
};
|
|
16
|
+
/** Gateway connection lifecycle states. */
|
|
17
|
+
export declare enum GatewayState {
|
|
18
|
+
/** Initial connection state. */ Connect = "CONNECT",
|
|
19
|
+
/** Gateway HELLO received state. */ Hello = "HELLO",
|
|
20
|
+
/** IDENTIFY operation in progress. */ Identify = "IDENTIFY",
|
|
21
|
+
/** RESUME operation in progress. */ Resume = "RESUME",
|
|
22
|
+
/** Gateway READY state. */ Ready = "READY",
|
|
23
|
+
/** Gateway dispatch processing state. */ Dispatch = "DISPATCH",
|
|
24
|
+
/** Heartbeat processing state. */ Heartbeat = "HEARTBEAT",
|
|
25
|
+
/** Reconnect in progress. */ Reconnect = "RECONNECT",
|
|
26
|
+
/** Gateway is permanently closed. */ Closed = "CLOSED"
|
|
27
|
+
}
|
|
28
|
+
/** Gateway protocol error. */
|
|
29
|
+
export declare class GatewayError extends Error {
|
|
30
|
+
/** Gateway close/error code. */ readonly code?: number;
|
|
31
|
+
/** Creates a Gateway error. @param message Error message. @param code Optional Gateway code. @param options Optional error metadata. */ constructor(message: string, code?: number, options?: ErrorOptions);
|
|
32
|
+
}
|
|
33
|
+
/** Gateway connection configuration. */
|
|
34
|
+
export interface GatewayOptions {
|
|
35
|
+
/** Authentication token. */ token: string;
|
|
36
|
+
/** Gateway intent bitfield or resolvable. */ intents: GatewayIntentResolvable;
|
|
37
|
+
/** Shard identifier. */ shardId?: number;
|
|
38
|
+
/** Total shard count. */ shardCount?: number;
|
|
39
|
+
/** Whether automatic reconnect is enabled. */ reconnect?: boolean;
|
|
40
|
+
/** Maximum reconnect attempts. */ maxReconnectAttempts?: number;
|
|
41
|
+
/** Initial reconnect delay. */ reconnectBaseDelay?: number;
|
|
42
|
+
/** Maximum reconnect delay. */ reconnectMaxDelay?: number;
|
|
43
|
+
/** Heartbeat acknowledgement timeout. */ heartbeatAckTimeout?: number;
|
|
44
|
+
/** Zombie connection timeout. */ zombieTimeout?: number;
|
|
45
|
+
/** Identification properties. */ properties?: GatewayProperties;
|
|
46
|
+
/** Presence data. */ presence?: GatewayPresence;
|
|
47
|
+
}
|
|
48
|
+
/** Gateway event listener. */
|
|
49
|
+
type GatewayListener = (data: unknown) => unknown;
|
|
50
|
+
/** Manages a Discord Gateway connection. */
|
|
51
|
+
export declare class Gateway {
|
|
52
|
+
#private;
|
|
53
|
+
/** Current Gateway lifecycle state. */
|
|
54
|
+
state: GatewayState;
|
|
55
|
+
/** Creates a Gateway connection manager. @param options Gateway configuration. @throws {TypeError|RangeError} If configuration is invalid. */
|
|
56
|
+
constructor(options: GatewayOptions);
|
|
57
|
+
/** Opens the Gateway connection. @param url Gateway WebSocket URL. @returns Promise fulfilled when the socket opens. @throws {GatewayError} If permanently closed or unable to connect. */
|
|
58
|
+
connect(url?: string): Promise<void>;
|
|
59
|
+
/** Permanently closes the Gateway connection. */
|
|
60
|
+
close(): void;
|
|
61
|
+
/** Registers a Gateway event listener. @param event Event name. @param listener Event callback. @returns This Gateway. */
|
|
62
|
+
/** Emits an event to all registered listeners. @param event Event name. @param data Event payload. */
|
|
63
|
+
emit(event: string, data?: unknown): void;
|
|
64
|
+
on(event: string, listener: GatewayListener): this;
|
|
65
|
+
/** Removes a Gateway event listener. @param event Event name. @param listener Event callback. @returns This Gateway. */
|
|
66
|
+
off(event: string, listener: GatewayListener): this;
|
|
67
|
+
/** Sends a Gateway payload. @param payload Gateway payload. @returns Whether it was sent. */
|
|
68
|
+
send(payload: GatewayPayload): boolean;
|
|
69
|
+
/** Sends a presence update. @param data Presence payload. @returns Whether it was sent. */
|
|
70
|
+
setPresence(data: GatewayPresence): boolean;
|
|
71
|
+
/** Sends a voice state update. @param data Voice state payload. @returns Whether it was sent. */
|
|
72
|
+
setVoiceState(data: Record<string, unknown>): boolean;
|
|
73
|
+
/** Requests guild members. @param data Guild member request payload. @returns Whether it was sent. */
|
|
74
|
+
requestGuildMembers(data: Record<string, unknown>): boolean;
|
|
75
|
+
}
|
|
76
|
+
export {};
|