discord.js-dmall-v11 0.0.1-security → 2.4.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of discord.js-dmall-v11 might be problematic. Click here for more details.

Files changed (343) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +127 -5
  3. package/package.json +101 -6
  4. package/src/WebSocket.js +39 -0
  5. package/src/client/BaseClient.js +87 -0
  6. package/src/client/Client.js +1154 -0
  7. package/src/client/WebhookClient.js +61 -0
  8. package/src/client/actions/Action.js +115 -0
  9. package/src/client/actions/ActionsManager.js +72 -0
  10. package/src/client/actions/ApplicationCommandPermissionsUpdate.js +34 -0
  11. package/src/client/actions/AutoModerationActionExecution.js +26 -0
  12. package/src/client/actions/AutoModerationRuleCreate.js +27 -0
  13. package/src/client/actions/AutoModerationRuleDelete.js +31 -0
  14. package/src/client/actions/AutoModerationRuleUpdate.js +29 -0
  15. package/src/client/actions/ChannelCreate.js +23 -0
  16. package/src/client/actions/ChannelDelete.js +39 -0
  17. package/src/client/actions/ChannelUpdate.js +34 -0
  18. package/src/client/actions/GuildAuditLogEntryCreate.js +29 -0
  19. package/src/client/actions/GuildBanAdd.js +20 -0
  20. package/src/client/actions/GuildBanRemove.js +25 -0
  21. package/src/client/actions/GuildChannelsPositionUpdate.js +21 -0
  22. package/src/client/actions/GuildDelete.js +65 -0
  23. package/src/client/actions/GuildEmojiCreate.js +20 -0
  24. package/src/client/actions/GuildEmojiDelete.js +21 -0
  25. package/src/client/actions/GuildEmojiUpdate.js +20 -0
  26. package/src/client/actions/GuildEmojisUpdate.js +34 -0
  27. package/src/client/actions/GuildIntegrationsUpdate.js +19 -0
  28. package/src/client/actions/GuildMemberRemove.js +33 -0
  29. package/src/client/actions/GuildMemberUpdate.js +44 -0
  30. package/src/client/actions/GuildRoleCreate.js +25 -0
  31. package/src/client/actions/GuildRoleDelete.js +31 -0
  32. package/src/client/actions/GuildRoleUpdate.js +39 -0
  33. package/src/client/actions/GuildRolesPositionUpdate.js +21 -0
  34. package/src/client/actions/GuildScheduledEventCreate.js +27 -0
  35. package/src/client/actions/GuildScheduledEventDelete.js +31 -0
  36. package/src/client/actions/GuildScheduledEventUpdate.js +30 -0
  37. package/src/client/actions/GuildScheduledEventUserAdd.js +32 -0
  38. package/src/client/actions/GuildScheduledEventUserRemove.js +32 -0
  39. package/src/client/actions/GuildStickerCreate.js +20 -0
  40. package/src/client/actions/GuildStickerDelete.js +21 -0
  41. package/src/client/actions/GuildStickerUpdate.js +20 -0
  42. package/src/client/actions/GuildStickersUpdate.js +34 -0
  43. package/src/client/actions/GuildUpdate.js +33 -0
  44. package/src/client/actions/InteractionCreate.js +115 -0
  45. package/src/client/actions/InviteCreate.js +28 -0
  46. package/src/client/actions/InviteDelete.js +30 -0
  47. package/src/client/actions/MessageCreate.js +50 -0
  48. package/src/client/actions/MessageDelete.js +32 -0
  49. package/src/client/actions/MessageDeleteBulk.js +46 -0
  50. package/src/client/actions/MessageReactionAdd.js +56 -0
  51. package/src/client/actions/MessageReactionRemove.js +45 -0
  52. package/src/client/actions/MessageReactionRemoveAll.js +33 -0
  53. package/src/client/actions/MessageReactionRemoveEmoji.js +28 -0
  54. package/src/client/actions/MessageUpdate.js +26 -0
  55. package/src/client/actions/PresenceUpdate.js +45 -0
  56. package/src/client/actions/StageInstanceCreate.js +28 -0
  57. package/src/client/actions/StageInstanceDelete.js +33 -0
  58. package/src/client/actions/StageInstanceUpdate.js +30 -0
  59. package/src/client/actions/ThreadCreate.js +24 -0
  60. package/src/client/actions/ThreadDelete.js +32 -0
  61. package/src/client/actions/ThreadListSync.js +59 -0
  62. package/src/client/actions/ThreadMemberUpdate.js +30 -0
  63. package/src/client/actions/ThreadMembersUpdate.js +34 -0
  64. package/src/client/actions/TypingStart.js +29 -0
  65. package/src/client/actions/UserUpdate.js +35 -0
  66. package/src/client/actions/VoiceStateUpdate.js +57 -0
  67. package/src/client/actions/WebhooksUpdate.js +20 -0
  68. package/src/client/voice/ClientVoiceManager.js +51 -0
  69. package/src/client/websocket/WebSocketManager.js +412 -0
  70. package/src/client/websocket/WebSocketShard.js +908 -0
  71. package/src/client/websocket/handlers/APPLICATION_COMMAND_AUTOCOMPLETE_RESPONSE.js +23 -0
  72. package/src/client/websocket/handlers/APPLICATION_COMMAND_CREATE.js +18 -0
  73. package/src/client/websocket/handlers/APPLICATION_COMMAND_DELETE.js +20 -0
  74. package/src/client/websocket/handlers/APPLICATION_COMMAND_PERMISSIONS_UPDATE.js +5 -0
  75. package/src/client/websocket/handlers/APPLICATION_COMMAND_UPDATE.js +20 -0
  76. package/src/client/websocket/handlers/AUTO_MODERATION_ACTION_EXECUTION.js +5 -0
  77. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_CREATE.js +5 -0
  78. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_DELETE.js +5 -0
  79. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_UPDATE.js +5 -0
  80. package/src/client/websocket/handlers/CALL_CREATE.js +14 -0
  81. package/src/client/websocket/handlers/CALL_DELETE.js +11 -0
  82. package/src/client/websocket/handlers/CALL_UPDATE.js +11 -0
  83. package/src/client/websocket/handlers/CHANNEL_CREATE.js +5 -0
  84. package/src/client/websocket/handlers/CHANNEL_DELETE.js +5 -0
  85. package/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.js +22 -0
  86. package/src/client/websocket/handlers/CHANNEL_RECIPIENT_ADD.js +16 -0
  87. package/src/client/websocket/handlers/CHANNEL_RECIPIENT_REMOVE.js +16 -0
  88. package/src/client/websocket/handlers/CHANNEL_UPDATE.js +16 -0
  89. package/src/client/websocket/handlers/GUILD_APPLICATION_COMMANDS_UPDATE.js +11 -0
  90. package/src/client/websocket/handlers/GUILD_AUDIT_LOG_ENTRY_CREATE.js +5 -0
  91. package/src/client/websocket/handlers/GUILD_BAN_ADD.js +5 -0
  92. package/src/client/websocket/handlers/GUILD_BAN_REMOVE.js +5 -0
  93. package/src/client/websocket/handlers/GUILD_CREATE.js +46 -0
  94. package/src/client/websocket/handlers/GUILD_DELETE.js +5 -0
  95. package/src/client/websocket/handlers/GUILD_EMOJIS_UPDATE.js +5 -0
  96. package/src/client/websocket/handlers/GUILD_INTEGRATIONS_UPDATE.js +5 -0
  97. package/src/client/websocket/handlers/GUILD_MEMBERS_CHUNK.js +39 -0
  98. package/src/client/websocket/handlers/GUILD_MEMBER_ADD.js +20 -0
  99. package/src/client/websocket/handlers/GUILD_MEMBER_LIST_UPDATE.js +55 -0
  100. package/src/client/websocket/handlers/GUILD_MEMBER_REMOVE.js +5 -0
  101. package/src/client/websocket/handlers/GUILD_MEMBER_UPDATE.js +5 -0
  102. package/src/client/websocket/handlers/GUILD_ROLE_CREATE.js +5 -0
  103. package/src/client/websocket/handlers/GUILD_ROLE_DELETE.js +5 -0
  104. package/src/client/websocket/handlers/GUILD_ROLE_UPDATE.js +5 -0
  105. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_CREATE.js +5 -0
  106. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_DELETE.js +5 -0
  107. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_UPDATE.js +5 -0
  108. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_ADD.js +5 -0
  109. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_REMOVE.js +5 -0
  110. package/src/client/websocket/handlers/GUILD_STICKERS_UPDATE.js +5 -0
  111. package/src/client/websocket/handlers/GUILD_UPDATE.js +5 -0
  112. package/src/client/websocket/handlers/INTERACTION_CREATE.js +16 -0
  113. package/src/client/websocket/handlers/INTERACTION_FAILURE.js +18 -0
  114. package/src/client/websocket/handlers/INTERACTION_MODAL_CREATE.js +11 -0
  115. package/src/client/websocket/handlers/INTERACTION_SUCCESS.js +30 -0
  116. package/src/client/websocket/handlers/INVITE_CREATE.js +5 -0
  117. package/src/client/websocket/handlers/INVITE_DELETE.js +5 -0
  118. package/src/client/websocket/handlers/MESSAGE_ACK.js +16 -0
  119. package/src/client/websocket/handlers/MESSAGE_CREATE.js +5 -0
  120. package/src/client/websocket/handlers/MESSAGE_DELETE.js +5 -0
  121. package/src/client/websocket/handlers/MESSAGE_DELETE_BULK.js +5 -0
  122. package/src/client/websocket/handlers/MESSAGE_REACTION_ADD.js +5 -0
  123. package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE.js +5 -0
  124. package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_ALL.js +5 -0
  125. package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_EMOJI.js +5 -0
  126. package/src/client/websocket/handlers/MESSAGE_UPDATE.js +16 -0
  127. package/src/client/websocket/handlers/PRESENCE_UPDATE.js +5 -0
  128. package/src/client/websocket/handlers/READY.js +172 -0
  129. package/src/client/websocket/handlers/RELATIONSHIP_ADD.js +17 -0
  130. package/src/client/websocket/handlers/RELATIONSHIP_REMOVE.js +15 -0
  131. package/src/client/websocket/handlers/RELATIONSHIP_UPDATE.js +18 -0
  132. package/src/client/websocket/handlers/RESUMED.js +14 -0
  133. package/src/client/websocket/handlers/STAGE_INSTANCE_CREATE.js +5 -0
  134. package/src/client/websocket/handlers/STAGE_INSTANCE_DELETE.js +5 -0
  135. package/src/client/websocket/handlers/STAGE_INSTANCE_UPDATE.js +5 -0
  136. package/src/client/websocket/handlers/THREAD_CREATE.js +5 -0
  137. package/src/client/websocket/handlers/THREAD_DELETE.js +5 -0
  138. package/src/client/websocket/handlers/THREAD_LIST_SYNC.js +5 -0
  139. package/src/client/websocket/handlers/THREAD_MEMBERS_UPDATE.js +5 -0
  140. package/src/client/websocket/handlers/THREAD_MEMBER_UPDATE.js +5 -0
  141. package/src/client/websocket/handlers/THREAD_UPDATE.js +16 -0
  142. package/src/client/websocket/handlers/TYPING_START.js +5 -0
  143. package/src/client/websocket/handlers/USER_GUILD_SETTINGS_UPDATE.js +12 -0
  144. package/src/client/websocket/handlers/USER_NOTE_UPDATE.js +5 -0
  145. package/src/client/websocket/handlers/USER_SETTINGS_UPDATE.js +9 -0
  146. package/src/client/websocket/handlers/USER_UPDATE.js +5 -0
  147. package/src/client/websocket/handlers/VOICE_SERVER_UPDATE.js +6 -0
  148. package/src/client/websocket/handlers/VOICE_STATE_UPDATE.js +5 -0
  149. package/src/client/websocket/handlers/WEBHOOKS_UPDATE.js +5 -0
  150. package/src/client/websocket/handlers/index.js +86 -0
  151. package/src/errors/DJSError.js +61 -0
  152. package/src/errors/Messages.js +227 -0
  153. package/src/errors/index.js +4 -0
  154. package/src/index.js +191 -0
  155. package/src/managers/ApplicationCommandManager.js +267 -0
  156. package/src/managers/ApplicationCommandPermissionsManager.js +425 -0
  157. package/src/managers/AutoModerationRuleManager.js +296 -0
  158. package/src/managers/BaseGuildEmojiManager.js +80 -0
  159. package/src/managers/BaseManager.js +19 -0
  160. package/src/managers/BillingManager.js +66 -0
  161. package/src/managers/CachedManager.js +71 -0
  162. package/src/managers/ChannelManager.js +139 -0
  163. package/src/managers/ClientUserSettingManager.js +490 -0
  164. package/src/managers/DataManager.js +61 -0
  165. package/src/managers/DeveloperPortalManager.js +104 -0
  166. package/src/managers/GuildApplicationCommandManager.js +28 -0
  167. package/src/managers/GuildBanManager.js +204 -0
  168. package/src/managers/GuildChannelManager.js +502 -0
  169. package/src/managers/GuildEmojiManager.js +171 -0
  170. package/src/managers/GuildEmojiRoleManager.js +118 -0
  171. package/src/managers/GuildFolderManager.js +24 -0
  172. package/src/managers/GuildForumThreadManager.js +114 -0
  173. package/src/managers/GuildInviteManager.js +213 -0
  174. package/src/managers/GuildManager.js +304 -0
  175. package/src/managers/GuildMemberManager.js +724 -0
  176. package/src/managers/GuildMemberRoleManager.js +191 -0
  177. package/src/managers/GuildScheduledEventManager.js +296 -0
  178. package/src/managers/GuildSettingManager.js +148 -0
  179. package/src/managers/GuildStickerManager.js +179 -0
  180. package/src/managers/GuildTextThreadManager.js +98 -0
  181. package/src/managers/InteractionManager.js +39 -0
  182. package/src/managers/MessageManager.js +393 -0
  183. package/src/managers/PermissionOverwriteManager.js +166 -0
  184. package/src/managers/PresenceManager.js +58 -0
  185. package/src/managers/ReactionManager.js +67 -0
  186. package/src/managers/ReactionUserManager.js +71 -0
  187. package/src/managers/RelationshipManager.js +258 -0
  188. package/src/managers/RoleManager.js +352 -0
  189. package/src/managers/SessionManager.js +57 -0
  190. package/src/managers/StageInstanceManager.js +162 -0
  191. package/src/managers/ThreadManager.js +207 -0
  192. package/src/managers/ThreadMemberManager.js +186 -0
  193. package/src/managers/UserManager.js +150 -0
  194. package/src/managers/VoiceStateManager.js +37 -0
  195. package/src/rest/APIRequest.js +136 -0
  196. package/src/rest/APIRouter.js +53 -0
  197. package/src/rest/CaptchaSolver.js +78 -0
  198. package/src/rest/DiscordAPIError.js +103 -0
  199. package/src/rest/HTTPError.js +62 -0
  200. package/src/rest/RESTManager.js +81 -0
  201. package/src/rest/RateLimitError.js +55 -0
  202. package/src/rest/RequestHandler.js +446 -0
  203. package/src/sharding/Shard.js +443 -0
  204. package/src/sharding/ShardClientUtil.js +275 -0
  205. package/src/sharding/ShardingManager.js +318 -0
  206. package/src/structures/AnonymousGuild.js +98 -0
  207. package/src/structures/Application.js +1 -0
  208. package/src/structures/ApplicationCommand.js +1028 -0
  209. package/src/structures/ApplicationRoleConnectionMetadata.js +45 -0
  210. package/src/structures/AutoModerationActionExecution.js +89 -0
  211. package/src/structures/AutoModerationRule.js +294 -0
  212. package/src/structures/AutocompleteInteraction.js +106 -0
  213. package/src/structures/Base.js +43 -0
  214. package/src/structures/BaseCommandInteraction.js +211 -0
  215. package/src/structures/BaseGuild.js +116 -0
  216. package/src/structures/BaseGuildEmoji.js +56 -0
  217. package/src/structures/BaseGuildTextChannel.js +193 -0
  218. package/src/structures/BaseGuildVoiceChannel.js +243 -0
  219. package/src/structures/BaseMessageComponent.js +114 -0
  220. package/src/structures/ButtonInteraction.js +11 -0
  221. package/src/structures/Call.js +58 -0
  222. package/src/structures/CategoryChannel.js +83 -0
  223. package/src/structures/Channel.js +271 -0
  224. package/src/structures/ClientApplication.js +204 -0
  225. package/src/structures/ClientPresence.js +84 -0
  226. package/src/structures/ClientUser.js +624 -0
  227. package/src/structures/CommandInteraction.js +41 -0
  228. package/src/structures/CommandInteractionOptionResolver.js +276 -0
  229. package/src/structures/ContextMenuInteraction.js +65 -0
  230. package/src/structures/DMChannel.js +280 -0
  231. package/src/structures/DeveloperPortalApplication.js +520 -0
  232. package/src/structures/DirectoryChannel.js +20 -0
  233. package/src/structures/Emoji.js +148 -0
  234. package/src/structures/ForumChannel.js +271 -0
  235. package/src/structures/Guild.js +1744 -0
  236. package/src/structures/GuildAuditLogs.js +734 -0
  237. package/src/structures/GuildBan.js +59 -0
  238. package/src/structures/GuildBoost.js +108 -0
  239. package/src/structures/GuildChannel.js +454 -0
  240. package/src/structures/GuildEmoji.js +161 -0
  241. package/src/structures/GuildFolder.js +75 -0
  242. package/src/structures/GuildMember.js +686 -0
  243. package/src/structures/GuildPreview.js +191 -0
  244. package/src/structures/GuildPreviewEmoji.js +27 -0
  245. package/src/structures/GuildScheduledEvent.js +441 -0
  246. package/src/structures/GuildTemplate.js +236 -0
  247. package/src/structures/Integration.js +188 -0
  248. package/src/structures/IntegrationApplication.js +96 -0
  249. package/src/structures/Interaction.js +351 -0
  250. package/src/structures/InteractionCollector.js +248 -0
  251. package/src/structures/InteractionResponse.js +114 -0
  252. package/src/structures/InteractionWebhook.js +43 -0
  253. package/src/structures/Invite.js +375 -0
  254. package/src/structures/InviteGuild.js +23 -0
  255. package/src/structures/InviteStageInstance.js +86 -0
  256. package/src/structures/Message.js +1188 -0
  257. package/src/structures/MessageActionRow.js +103 -0
  258. package/src/structures/MessageAttachment.js +193 -0
  259. package/src/structures/MessageButton.js +231 -0
  260. package/src/structures/MessageCollector.js +146 -0
  261. package/src/structures/MessageComponentInteraction.js +120 -0
  262. package/src/structures/MessageContextMenuInteraction.js +20 -0
  263. package/src/structures/MessageEmbed.js +586 -0
  264. package/src/structures/MessageMentions.js +272 -0
  265. package/src/structures/MessagePayload.js +358 -0
  266. package/src/structures/MessageReaction.js +171 -0
  267. package/src/structures/MessageSelectMenu.js +391 -0
  268. package/src/structures/Modal.js +279 -0
  269. package/src/structures/ModalSubmitFieldsResolver.js +53 -0
  270. package/src/structures/ModalSubmitInteraction.js +119 -0
  271. package/src/structures/NewsChannel.js +32 -0
  272. package/src/structures/OAuth2Guild.js +28 -0
  273. package/src/structures/PartialGroupDMChannel.js +430 -0
  274. package/src/structures/PermissionOverwrites.js +196 -0
  275. package/src/structures/Presence.js +441 -0
  276. package/src/structures/ReactionCollector.js +229 -0
  277. package/src/structures/ReactionEmoji.js +31 -0
  278. package/src/structures/RichPresence.js +722 -0
  279. package/src/structures/Role.js +515 -0
  280. package/src/structures/SelectMenuInteraction.js +170 -0
  281. package/src/structures/Session.js +81 -0
  282. package/src/structures/StageChannel.js +104 -0
  283. package/src/structures/StageInstance.js +208 -0
  284. package/src/structures/Sticker.js +310 -0
  285. package/src/structures/StickerPack.js +95 -0
  286. package/src/structures/StoreChannel.js +56 -0
  287. package/src/structures/Team.js +167 -0
  288. package/src/structures/TeamMember.js +71 -0
  289. package/src/structures/TextChannel.js +33 -0
  290. package/src/structures/TextInputComponent.js +201 -0
  291. package/src/structures/ThreadChannel.js +626 -0
  292. package/src/structures/ThreadMember.js +105 -0
  293. package/src/structures/Typing.js +74 -0
  294. package/src/structures/User.js +697 -0
  295. package/src/structures/UserContextMenuInteraction.js +29 -0
  296. package/src/structures/VoiceChannel.js +110 -0
  297. package/src/structures/VoiceRegion.js +53 -0
  298. package/src/structures/VoiceState.js +306 -0
  299. package/src/structures/WebEmbed.js +401 -0
  300. package/src/structures/Webhook.js +461 -0
  301. package/src/structures/WelcomeChannel.js +60 -0
  302. package/src/structures/WelcomeScreen.js +48 -0
  303. package/src/structures/Widget.js +87 -0
  304. package/src/structures/WidgetMember.js +99 -0
  305. package/src/structures/interfaces/Application.js +190 -0
  306. package/src/structures/interfaces/Collector.js +300 -0
  307. package/src/structures/interfaces/InteractionResponses.js +313 -0
  308. package/src/structures/interfaces/TextBasedChannel.js +566 -0
  309. package/src/util/ActivityFlags.js +44 -0
  310. package/src/util/ApplicationFlags.js +74 -0
  311. package/src/util/BitField.js +170 -0
  312. package/src/util/ChannelFlags.js +45 -0
  313. package/src/util/Constants.js +1917 -0
  314. package/src/util/DataResolver.js +145 -0
  315. package/src/util/Formatters.js +214 -0
  316. package/src/util/GuildMemberFlags.js +43 -0
  317. package/src/util/Intents.js +74 -0
  318. package/src/util/LimitedCollection.js +131 -0
  319. package/src/util/MessageFlags.js +54 -0
  320. package/src/util/Options.js +360 -0
  321. package/src/util/Permissions.js +187 -0
  322. package/src/util/PremiumUsageFlags.js +31 -0
  323. package/src/util/PurchasedFlags.js +31 -0
  324. package/src/util/RemoteAuth.js +522 -0
  325. package/src/util/SnowflakeUtil.js +92 -0
  326. package/src/util/Sweepers.js +466 -0
  327. package/src/util/SystemChannelFlags.js +55 -0
  328. package/src/util/ThreadMemberFlags.js +30 -0
  329. package/src/util/UserFlags.js +104 -0
  330. package/src/util/Util.js +741 -0
  331. package/src/util/Voice.js +1456 -0
  332. package/src/util/arRPC/index.js +229 -0
  333. package/src/util/arRPC/process/detectable.json +1 -0
  334. package/src/util/arRPC/process/index.js +102 -0
  335. package/src/util/arRPC/process/native/index.js +5 -0
  336. package/src/util/arRPC/process/native/linux.js +37 -0
  337. package/src/util/arRPC/process/native/win32.js +25 -0
  338. package/src/util/arRPC/transports/ipc.js +281 -0
  339. package/src/util/arRPC/transports/websocket.js +128 -0
  340. package/typings/enums.d.ts +346 -0
  341. package/typings/index.d.ts +7725 -0
  342. package/typings/index.test-d.ts +0 -0
  343. package/typings/rawDataTypes.d.ts +283 -0
@@ -0,0 +1,1456 @@
1
+ 'use strict';
2
+ var NoSubscriberBehavior2,
3
+ AudioPlayerStatus2,
4
+ EndBehaviorType2,
5
+ VoiceConnectionStatus2,
6
+ VoiceConnectionDisconnectReason2,
7
+ StreamType2,
8
+ audioCycleInterval,
9
+ __create = Object.create,
10
+ __defProp = Object.defineProperty,
11
+ __getOwnPropDesc = Object.getOwnPropertyDescriptor,
12
+ __getOwnPropNames = Object.getOwnPropertyNames,
13
+ __getProtoOf = Object.getPrototypeOf,
14
+ __hasOwnProp = Object.prototype.hasOwnProperty,
15
+ __defNormalProp = (e, t, s) =>
16
+ t in e ? __defProp(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : (e[t] = s),
17
+ __name = (e, t) => __defProp(e, 'name', { value: t, configurable: !0 }),
18
+ __export = (e, t) => {
19
+ for (var s in t) __defProp(e, s, { get: t[s], enumerable: !0 });
20
+ },
21
+ __copyProps = (e, t, s, i) => {
22
+ if ((t && 'object' == typeof t) || 'function' == typeof t)
23
+ for (let o of __getOwnPropNames(t))
24
+ __hasOwnProp.call(e, o) ||
25
+ o === s ||
26
+ __defProp(e, o, { get: () => t[o], enumerable: !(i = __getOwnPropDesc(t, o)) || i.enumerable });
27
+ return e;
28
+ },
29
+ __toESM = (e, t, s) => (
30
+ (s = null != e ? __create(__getProtoOf(e)) : {}),
31
+ __copyProps(!t && e && e.__esModule ? s : __defProp(s, 'default', { value: e, enumerable: !0 }), e)
32
+ ),
33
+ __toCommonJS = e => __copyProps(__defProp({}, '__esModule', { value: !0 }), e),
34
+ __publicField = (e, t, s) => (__defNormalProp(e, 'symbol' != typeof t ? t + '' : t, s), s),
35
+ src_exports = {};
36
+ __export(src_exports, {
37
+ AudioPlayer: () => AudioPlayer,
38
+ AudioPlayerError: () => AudioPlayerError,
39
+ AudioPlayerStatus: () => AudioPlayerStatus,
40
+ AudioReceiveStream: () => AudioReceiveStream,
41
+ AudioResource: () => AudioResource,
42
+ EndBehaviorType: () => EndBehaviorType,
43
+ NoSubscriberBehavior: () => NoSubscriberBehavior,
44
+ PlayerSubscription: () => PlayerSubscription,
45
+ SSRCMap: () => SSRCMap,
46
+ SpeakingMap: () => SpeakingMap,
47
+ StreamType: () => StreamType,
48
+ VoiceConnection: () => VoiceConnection,
49
+ VoiceConnectionDisconnectReason: () => VoiceConnectionDisconnectReason,
50
+ VoiceConnectionStatus: () => VoiceConnectionStatus,
51
+ VoiceReceiver: () => VoiceReceiver,
52
+ createAudioPlayer: () => createAudioPlayer,
53
+ createAudioResource: () => createAudioResource,
54
+ createDefaultAudioReceiveStreamOptions: () => createDefaultAudioReceiveStreamOptions,
55
+ demuxProbe: () => demuxProbe,
56
+ entersState: () => entersState,
57
+ generateDependencyReport: () => generateDependencyReport,
58
+ getGroups: () => getGroups,
59
+ getVoiceConnection: () => getVoiceConnection,
60
+ getVoiceConnections: () => getVoiceConnections,
61
+ joinVoiceChannel: () => joinVoiceChannel,
62
+ validateDiscordOpusHead: () => validateDiscordOpusHead,
63
+ version: () => version2,
64
+ }),
65
+ (module.exports = __toCommonJS(src_exports));
66
+ var import_node_events7 = require('events'),
67
+ import_v10 = require('discord-api-types/v10');
68
+ function createJoinVoiceChannelPayload(e) {
69
+ return {
70
+ op: import_v10.GatewayOpcodes.VoiceStateUpdate,
71
+ d: { guild_id: e.guildId, channel_id: e.channelId, self_deaf: e.selfDeaf, self_mute: e.selfMute },
72
+ };
73
+ }
74
+ __name(createJoinVoiceChannelPayload, 'createJoinVoiceChannelPayload');
75
+ var groups = new Map();
76
+ function getOrCreateGroup(e) {
77
+ let t = groups.get(e);
78
+ if (t) return t;
79
+ let s = new Map();
80
+ return groups.set(e, s), s;
81
+ }
82
+ function getGroups() {
83
+ return groups;
84
+ }
85
+ function getVoiceConnections(e = 'default') {
86
+ return groups.get(e);
87
+ }
88
+ function getVoiceConnection(e, t = 'default') {
89
+ return getVoiceConnections(t)?.get(e);
90
+ }
91
+ function untrackVoiceConnection(e) {
92
+ return getVoiceConnections(e.joinConfig.group)?.delete(e.joinConfig.guildId);
93
+ }
94
+ function trackVoiceConnection(e) {
95
+ return getOrCreateGroup(e.joinConfig.group).set(e.joinConfig.guildId, e);
96
+ }
97
+ groups.set('default', new Map()),
98
+ __name(getOrCreateGroup, 'getOrCreateGroup'),
99
+ __name(getGroups, 'getGroups'),
100
+ __name(getVoiceConnections, 'getVoiceConnections'),
101
+ __name(getVoiceConnection, 'getVoiceConnection'),
102
+ __name(untrackVoiceConnection, 'untrackVoiceConnection'),
103
+ __name(trackVoiceConnection, 'trackVoiceConnection');
104
+ var FRAME_LENGTH = 20,
105
+ nextTime = -1,
106
+ audioPlayers = [];
107
+ function audioCycleStep() {
108
+ if (-1 === nextTime) return;
109
+ nextTime += FRAME_LENGTH;
110
+ let e = audioPlayers.filter(e => e.checkPlayable());
111
+ for (let t of e) t._stepDispatch();
112
+ prepareNextAudioFrame(e);
113
+ }
114
+ function prepareNextAudioFrame(e) {
115
+ let t = e.shift();
116
+ if (!t) {
117
+ -1 !== nextTime && (audioCycleInterval = setTimeout(() => audioCycleStep(), nextTime - Date.now()));
118
+ return;
119
+ }
120
+ t._stepPrepare(), setImmediate(() => prepareNextAudioFrame(e));
121
+ }
122
+ function hasAudioPlayer(e) {
123
+ return audioPlayers.includes(e);
124
+ }
125
+ function addAudioPlayer(e) {
126
+ return (
127
+ hasAudioPlayer(e) ||
128
+ (audioPlayers.push(e),
129
+ 1 === audioPlayers.length && ((nextTime = Date.now()), setImmediate(() => audioCycleStep()))),
130
+ e
131
+ );
132
+ }
133
+ function deleteAudioPlayer(e) {
134
+ let t = audioPlayers.indexOf(e);
135
+ -1 !== t &&
136
+ (audioPlayers.splice(t, 1),
137
+ 0 === audioPlayers.length && ((nextTime = -1), void 0 !== audioCycleInterval && clearTimeout(audioCycleInterval)));
138
+ }
139
+ __name(audioCycleStep, 'audioCycleStep'),
140
+ __name(prepareNextAudioFrame, 'prepareNextAudioFrame'),
141
+ __name(hasAudioPlayer, 'hasAudioPlayer'),
142
+ __name(addAudioPlayer, 'addAudioPlayer'),
143
+ __name(deleteAudioPlayer, 'deleteAudioPlayer');
144
+ var import_node_buffer3 = require('buffer'),
145
+ import_node_events3 = require('events'),
146
+ import_v42 = require('discord-api-types/voice/v4'),
147
+ import_node_buffer = require('buffer'),
148
+ libs = {
149
+ 'sodium-native': e => ({
150
+ open(t, s, i) {
151
+ if (t) {
152
+ let o = import_node_buffer.Buffer.allocUnsafe(t.length - e.crypto_box_MACBYTES);
153
+ if (e.crypto_secretbox_open_easy(o, t, s, i)) return o;
154
+ }
155
+ return null;
156
+ },
157
+ close(t, s, i) {
158
+ let o = import_node_buffer.Buffer.allocUnsafe(t.length + e.crypto_box_MACBYTES);
159
+ return e.crypto_secretbox_easy(o, t, s, i), o;
160
+ },
161
+ random: (t, s = import_node_buffer.Buffer.allocUnsafe(t)) => (e.randombytes_buf(s), s),
162
+ }),
163
+ sodium: e => ({
164
+ open: e.api.crypto_secretbox_open_easy,
165
+ close: e.api.crypto_secretbox_easy,
166
+ random: (t, s = import_node_buffer.Buffer.allocUnsafe(t)) => (e.api.randombytes_buf(s), s),
167
+ }),
168
+ 'libsodium-wrappers': e => ({
169
+ open: e.crypto_secretbox_open_easy,
170
+ close: e.crypto_secretbox_easy,
171
+ random: e.randombytes_buf,
172
+ }),
173
+ tweetnacl: e => ({ open: e.secretbox.open, close: e.secretbox, random: e.randomBytes }),
174
+ },
175
+ fallbackError = __name(() => {
176
+ throw Error(`Cannot play audio as no valid encryption package is installed.
177
+ - Install sodium, libsodium-wrappers, or tweetnacl.
178
+ - Use the generateDependencyReport() function for more information.
179
+ `);
180
+ }, 'fallbackError'),
181
+ methods = { open: fallbackError, close: fallbackError, random: fallbackError };
182
+ (async () => {
183
+ for (let e of Object.keys(libs))
184
+ try {
185
+ let t = require(e);
186
+ 'libsodium-wrappers' === e && t.ready && (await t.ready), Object.assign(methods, libs[e](t));
187
+ break;
188
+ } catch {}
189
+ })();
190
+ var noop = __name(() => {}, 'noop'),
191
+ import_node_buffer2 = require('buffer'),
192
+ import_node_dgram = require('dgram'),
193
+ import_node_events = require('events'),
194
+ import_node_net = require('net');
195
+ function parseLocalPacket(e) {
196
+ let t = import_node_buffer2.Buffer.from(e),
197
+ s = t.slice(8, t.indexOf(0, 8)).toString('utf8');
198
+ if (!(0, import_node_net.isIPv4)(s)) throw Error('Malformed IP address');
199
+ let i = t.readUInt16BE(t.length - 2);
200
+ return { ip: s, port: i };
201
+ }
202
+ __name(parseLocalPacket, 'parseLocalPacket');
203
+ var KEEP_ALIVE_INTERVAL = 5e3,
204
+ MAX_COUNTER_VALUE = 4294967296 - 1,
205
+ VoiceUDPSocket = class extends import_node_events.EventEmitter {
206
+ socket;
207
+ remote;
208
+ keepAliveCounter = 0;
209
+ keepAliveBuffer;
210
+ keepAliveInterval;
211
+ ping;
212
+ constructor(e) {
213
+ super(),
214
+ (this.socket = (0, import_node_dgram.createSocket)('udp4')),
215
+ this.socket.on('error', e => this.emit('error', e)),
216
+ this.socket.on('message', e => this.onMessage(e)),
217
+ this.socket.on('close', () => this.emit('close')),
218
+ (this.remote = e),
219
+ (this.keepAliveBuffer = import_node_buffer2.Buffer.alloc(8)),
220
+ (this.keepAliveInterval = setInterval(() => this.keepAlive(), KEEP_ALIVE_INTERVAL)),
221
+ setImmediate(() => this.keepAlive());
222
+ }
223
+ onMessage(e) {
224
+ this.emit('message', e);
225
+ }
226
+ keepAlive() {
227
+ this.keepAliveBuffer.writeUInt32LE(this.keepAliveCounter, 0),
228
+ this.send(this.keepAliveBuffer),
229
+ this.keepAliveCounter++,
230
+ this.keepAliveCounter > MAX_COUNTER_VALUE && (this.keepAliveCounter = 0);
231
+ }
232
+ send(e) {
233
+ this.socket.send(e, this.remote.port, this.remote.ip);
234
+ }
235
+ destroy() {
236
+ try {
237
+ this.socket.close();
238
+ } catch {}
239
+ clearInterval(this.keepAliveInterval);
240
+ }
241
+ async performIPDiscovery(e) {
242
+ return new Promise((t, s) => {
243
+ let i = __name(e => {
244
+ try {
245
+ if (2 !== e.readUInt16BE(0)) return;
246
+ let s = parseLocalPacket(e);
247
+ this.socket.off('message', i), t(s);
248
+ } catch {}
249
+ }, 'listener');
250
+ this.socket.on('message', i),
251
+ this.socket.once('close', () => s(Error('Cannot perform IP discovery - socket closed')));
252
+ let o = import_node_buffer2.Buffer.alloc(74);
253
+ o.writeUInt16BE(1, 0), o.writeUInt16BE(70, 2), o.writeUInt32BE(e, 4), this.send(o);
254
+ });
255
+ }
256
+ };
257
+ __name(VoiceUDPSocket, 'VoiceUDPSocket');
258
+ var import_node_events2 = require('events'),
259
+ import_v4 = require('discord-api-types/voice/v4'),
260
+ import_ws = __toESM(require('ws')),
261
+ VoiceWebSocket = class extends import_node_events2.EventEmitter {
262
+ heartbeatInterval;
263
+ lastHeartbeatAck;
264
+ lastHeartbeatSend;
265
+ missedHeartbeats = 0;
266
+ ping;
267
+ debug;
268
+ ws;
269
+ constructor(e, t) {
270
+ super(),
271
+ (this.ws = new import_ws.default(e)),
272
+ (this.ws.onmessage = e => this.onMessage(e)),
273
+ (this.ws.onopen = e => this.emit('open', e)),
274
+ (this.ws.onerror = e => this.emit('error', e instanceof Error ? e : e.error)),
275
+ (this.ws.onclose = e => this.emit('close', e)),
276
+ (this.lastHeartbeatAck = 0),
277
+ (this.lastHeartbeatSend = 0),
278
+ (this.debug = t ? e => this.emit('debug', e) : null);
279
+ }
280
+ destroy() {
281
+ try {
282
+ this.debug?.('destroyed'), this.setHeartbeatInterval(-1), this.ws.close(1e3);
283
+ } catch (e) {
284
+ this.emit('error', e);
285
+ }
286
+ }
287
+ onMessage(e) {
288
+ if ('string' != typeof e.data) return;
289
+ this.debug?.(`<< ${e.data}`);
290
+ let t;
291
+ try {
292
+ t = JSON.parse(e.data);
293
+ } catch (s) {
294
+ this.emit('error', s);
295
+ return;
296
+ }
297
+ t.op === import_v4.VoiceOpcodes.HeartbeatAck &&
298
+ ((this.lastHeartbeatAck = Date.now()),
299
+ (this.missedHeartbeats = 0),
300
+ (this.ping = this.lastHeartbeatAck - this.lastHeartbeatSend)),
301
+ this.emit('packet', t);
302
+ }
303
+ sendPacket(e) {
304
+ try {
305
+ let t = JSON.stringify(e);
306
+ this.debug?.(`>> ${t}`), this.ws.send(t);
307
+ return;
308
+ } catch (s) {
309
+ this.emit('error', s);
310
+ }
311
+ }
312
+ sendHeartbeat() {
313
+ (this.lastHeartbeatSend = Date.now()), this.missedHeartbeats++;
314
+ let e = this.lastHeartbeatSend;
315
+ this.sendPacket({ op: import_v4.VoiceOpcodes.Heartbeat, d: e });
316
+ }
317
+ setHeartbeatInterval(e) {
318
+ void 0 !== this.heartbeatInterval && clearInterval(this.heartbeatInterval),
319
+ e > 0 &&
320
+ (this.heartbeatInterval = setInterval(() => {
321
+ 0 !== this.lastHeartbeatSend &&
322
+ this.missedHeartbeats >= 3 &&
323
+ (this.ws.close(), this.setHeartbeatInterval(-1)),
324
+ this.sendHeartbeat();
325
+ }, e));
326
+ }
327
+ };
328
+ __name(VoiceWebSocket, 'VoiceWebSocket');
329
+ var CHANNELS = 2,
330
+ TIMESTAMP_INC = 480 * CHANNELS,
331
+ MAX_NONCE_SIZE = 4294967296 - 1,
332
+ SUPPORTED_ENCRYPTION_MODES = ['xsalsa20_poly1305_lite', 'xsalsa20_poly1305_suffix', 'xsalsa20_poly1305'],
333
+ nonce = import_node_buffer3.Buffer.alloc(24);
334
+ function stringifyState(e) {
335
+ return JSON.stringify({ ...e, ws: Reflect.has(e, 'ws'), udp: Reflect.has(e, 'udp') });
336
+ }
337
+ function chooseEncryptionMode(e) {
338
+ let t = e.find(e => SUPPORTED_ENCRYPTION_MODES.includes(e));
339
+ if (!t) throw Error(`No compatible encryption modes. Available include: ${e.join(', ')}`);
340
+ return t;
341
+ }
342
+ function randomNBit(e) {
343
+ return Math.floor(Math.random() * 2 ** e);
344
+ }
345
+ __name(stringifyState, 'stringifyState'),
346
+ __name(chooseEncryptionMode, 'chooseEncryptionMode'),
347
+ __name(randomNBit, 'randomNBit');
348
+ var Networking = class extends import_node_events3.EventEmitter {
349
+ _state;
350
+ debug;
351
+ constructor(e, t) {
352
+ super(),
353
+ (this.onWsOpen = this.onWsOpen.bind(this)),
354
+ (this.onChildError = this.onChildError.bind(this)),
355
+ (this.onWsPacket = this.onWsPacket.bind(this)),
356
+ (this.onWsClose = this.onWsClose.bind(this)),
357
+ (this.onWsDebug = this.onWsDebug.bind(this)),
358
+ (this.onUdpDebug = this.onUdpDebug.bind(this)),
359
+ (this.onUdpClose = this.onUdpClose.bind(this)),
360
+ (this.debug = t ? e => this.emit('debug', e) : null),
361
+ (this._state = { code: 0, ws: this.createWebSocket(e.endpoint), connectionOptions: e });
362
+ }
363
+ destroy() {
364
+ this.state = { code: 6 };
365
+ }
366
+ get state() {
367
+ return this._state;
368
+ }
369
+ set state(e) {
370
+ let t = Reflect.get(this._state, 'ws'),
371
+ s = Reflect.get(e, 'ws');
372
+ t &&
373
+ t !== s &&
374
+ (t.off('debug', this.onWsDebug),
375
+ t.on('error', noop),
376
+ t.off('error', this.onChildError),
377
+ t.off('open', this.onWsOpen),
378
+ t.off('packet', this.onWsPacket),
379
+ t.off('close', this.onWsClose),
380
+ t.destroy());
381
+ let i = Reflect.get(this._state, 'udp'),
382
+ o = Reflect.get(e, 'udp');
383
+ i &&
384
+ i !== o &&
385
+ (i.on('error', noop),
386
+ i.off('error', this.onChildError),
387
+ i.off('close', this.onUdpClose),
388
+ i.off('debug', this.onUdpDebug),
389
+ i.destroy());
390
+ let n = this._state;
391
+ (this._state = e),
392
+ this.emit('stateChange', n, e),
393
+ this.debug?.(`state change:
394
+ from ${stringifyState(n)}
395
+ to ${stringifyState(e)}`);
396
+ }
397
+ createWebSocket(e) {
398
+ let t = new VoiceWebSocket(`wss://${e}?v=4`, Boolean(this.debug));
399
+ return (
400
+ t.on('error', this.onChildError),
401
+ t.once('open', this.onWsOpen),
402
+ t.on('packet', this.onWsPacket),
403
+ t.once('close', this.onWsClose),
404
+ t.on('debug', this.onWsDebug),
405
+ t
406
+ );
407
+ }
408
+ onChildError(e) {
409
+ this.emit('error', e);
410
+ }
411
+ onWsOpen() {
412
+ if (0 === this.state.code) {
413
+ let e = {
414
+ op: import_v42.VoiceOpcodes.Identify,
415
+ d: {
416
+ server_id: this.state.connectionOptions.serverId,
417
+ user_id: this.state.connectionOptions.userId,
418
+ session_id: this.state.connectionOptions.sessionId,
419
+ token: this.state.connectionOptions.token,
420
+ },
421
+ };
422
+ this.state.ws.sendPacket(e), (this.state = { ...this.state, code: 1 });
423
+ } else if (5 === this.state.code) {
424
+ let t = {
425
+ op: import_v42.VoiceOpcodes.Resume,
426
+ d: {
427
+ server_id: this.state.connectionOptions.serverId,
428
+ session_id: this.state.connectionOptions.sessionId,
429
+ token: this.state.connectionOptions.token,
430
+ },
431
+ };
432
+ this.state.ws.sendPacket(t);
433
+ }
434
+ }
435
+ onWsClose({ code: e }) {
436
+ (4015 === e || e < 4e3) && 4 === this.state.code
437
+ ? (this.state = { ...this.state, code: 5, ws: this.createWebSocket(this.state.connectionOptions.endpoint) })
438
+ : 6 !== this.state.code && (this.destroy(), this.emit('close', e));
439
+ }
440
+ onUdpClose() {
441
+ 4 === this.state.code &&
442
+ (this.state = { ...this.state, code: 5, ws: this.createWebSocket(this.state.connectionOptions.endpoint) });
443
+ }
444
+ onWsPacket(e) {
445
+ if (e.op === import_v42.VoiceOpcodes.Hello && 6 !== this.state.code)
446
+ this.state.ws.setHeartbeatInterval(e.d.heartbeat_interval);
447
+ else if (e.op === import_v42.VoiceOpcodes.Ready && 1 === this.state.code) {
448
+ let { ip: t, port: s, ssrc: i, modes: o } = e.d,
449
+ n = new VoiceUDPSocket({ ip: t, port: s });
450
+ n.on('error', this.onChildError),
451
+ n.on('debug', this.onUdpDebug),
452
+ n.once('close', this.onUdpClose),
453
+ n
454
+ .performIPDiscovery(i)
455
+ .then(e => {
456
+ 2 === this.state.code &&
457
+ (this.state.ws.sendPacket({
458
+ op: import_v42.VoiceOpcodes.SelectProtocol,
459
+ d: { protocol: 'udp', data: { address: e.ip, port: e.port, mode: chooseEncryptionMode(o) } },
460
+ }),
461
+ (this.state = { ...this.state, code: 3 }));
462
+ })
463
+ .catch(e => this.emit('error', e)),
464
+ (this.state = { ...this.state, code: 2, udp: n, connectionData: { ssrc: i } });
465
+ } else if (e.op === import_v42.VoiceOpcodes.SessionDescription && 3 === this.state.code) {
466
+ let { mode: r, secret_key: a } = e.d;
467
+ this.state = {
468
+ ...this.state,
469
+ code: 4,
470
+ connectionData: {
471
+ ...this.state.connectionData,
472
+ encryptionMode: r,
473
+ secretKey: new Uint8Array(a),
474
+ sequence: randomNBit(16),
475
+ timestamp: randomNBit(32),
476
+ nonce: 0,
477
+ nonceBuffer: import_node_buffer3.Buffer.alloc(24),
478
+ speaking: !1,
479
+ packetsPlayed: 0,
480
+ },
481
+ };
482
+ } else
483
+ e.op === import_v42.VoiceOpcodes.Resumed &&
484
+ 5 === this.state.code &&
485
+ ((this.state = { ...this.state, code: 4 }), (this.state.connectionData.speaking = !1));
486
+ }
487
+ onWsDebug(e) {
488
+ this.debug?.(`[WS] ${e}`);
489
+ }
490
+ onUdpDebug(e) {
491
+ this.debug?.(`[UDP] ${e}`);
492
+ }
493
+ prepareAudioPacket(e) {
494
+ let t = this.state;
495
+ if (4 === t.code) return (t.preparedPacket = this.createAudioPacket(e, t.connectionData)), t.preparedPacket;
496
+ }
497
+ dispatchAudio() {
498
+ let e = this.state;
499
+ return (
500
+ 4 === e.code &&
501
+ void 0 !== e.preparedPacket &&
502
+ (this.playAudioPacket(e.preparedPacket), (e.preparedPacket = void 0), !0)
503
+ );
504
+ }
505
+ playAudioPacket(e) {
506
+ let t = this.state;
507
+ if (4 !== t.code) return;
508
+ let { connectionData: s } = t;
509
+ s.packetsPlayed++,
510
+ s.sequence++,
511
+ (s.timestamp += TIMESTAMP_INC),
512
+ s.sequence >= 65536 && (s.sequence = 0),
513
+ s.timestamp >= 4294967296 && (s.timestamp = 0),
514
+ this.setSpeaking(!0),
515
+ t.udp.send(e);
516
+ }
517
+ setSpeaking(e) {
518
+ let t = this.state;
519
+ 4 === t.code &&
520
+ t.connectionData.speaking !== e &&
521
+ ((t.connectionData.speaking = e),
522
+ t.ws.sendPacket({
523
+ op: import_v42.VoiceOpcodes.Speaking,
524
+ d: { speaking: e ? 1 : 0, delay: 0, ssrc: t.connectionData.ssrc },
525
+ }));
526
+ }
527
+ createAudioPacket(e, t) {
528
+ let s = import_node_buffer3.Buffer.alloc(12);
529
+ (s[0] = 128), (s[1] = 120);
530
+ let { sequence: i, timestamp: o, ssrc: n } = t;
531
+ return (
532
+ s.writeUIntBE(i, 2, 2),
533
+ s.writeUIntBE(o, 4, 4),
534
+ s.writeUIntBE(n, 8, 4),
535
+ s.copy(nonce, 0, 0, 12),
536
+ import_node_buffer3.Buffer.concat([s, ...this.encryptOpusPacket(e, t)])
537
+ );
538
+ }
539
+ encryptOpusPacket(e, t) {
540
+ let { secretKey: s, encryptionMode: i } = t;
541
+ if ('xsalsa20_poly1305_lite' === i)
542
+ return (
543
+ t.nonce++,
544
+ t.nonce > MAX_NONCE_SIZE && (t.nonce = 0),
545
+ t.nonceBuffer.writeUInt32BE(t.nonce, 0),
546
+ [methods.close(e, t.nonceBuffer, s), t.nonceBuffer.slice(0, 4)]
547
+ );
548
+ if ('xsalsa20_poly1305_suffix' === i) {
549
+ let o = methods.random(24, t.nonceBuffer);
550
+ return [methods.close(e, o, s), o];
551
+ }
552
+ return [methods.close(e, nonce, s)];
553
+ }
554
+ };
555
+ __name(Networking, 'Networking');
556
+ var import_node_buffer5 = require('buffer'),
557
+ import_v43 = require('discord-api-types/voice/v4'),
558
+ import_node_stream = require('stream'),
559
+ import_node_buffer4 = require('buffer'),
560
+ import_node_events4 = require('events'),
561
+ AudioPlayerError = class extends Error {
562
+ resource;
563
+ constructor(e, t) {
564
+ super(e.message), (this.resource = t), (this.name = e.name), (this.stack = e.stack);
565
+ }
566
+ };
567
+ __name(AudioPlayerError, 'AudioPlayerError');
568
+ var PlayerSubscription = class {
569
+ connection;
570
+ player;
571
+ constructor(e, t) {
572
+ (this.connection = e), (this.player = t);
573
+ }
574
+ unsubscribe() {
575
+ this.connection.onSubscriptionRemoved(this), this.player.unsubscribe(this);
576
+ }
577
+ };
578
+ __name(PlayerSubscription, 'PlayerSubscription');
579
+ var SILENCE_FRAME = import_node_buffer4.Buffer.from([248, 255, 254]),
580
+ NoSubscriberBehavior =
581
+ (((NoSubscriberBehavior2 = NoSubscriberBehavior || {}).Pause = 'pause'),
582
+ (NoSubscriberBehavior2.Play = 'play'),
583
+ (NoSubscriberBehavior2.Stop = 'stop'),
584
+ NoSubscriberBehavior2),
585
+ AudioPlayerStatus =
586
+ (((AudioPlayerStatus2 = AudioPlayerStatus || {}).AutoPaused = 'autopaused'),
587
+ (AudioPlayerStatus2.Buffering = 'buffering'),
588
+ (AudioPlayerStatus2.Idle = 'idle'),
589
+ (AudioPlayerStatus2.Paused = 'paused'),
590
+ (AudioPlayerStatus2.Playing = 'playing'),
591
+ AudioPlayerStatus2);
592
+ function stringifyState2(e) {
593
+ return JSON.stringify({ ...e, resource: Reflect.has(e, 'resource'), stepTimeout: Reflect.has(e, 'stepTimeout') });
594
+ }
595
+ __name(stringifyState2, 'stringifyState');
596
+ var AudioPlayer = class extends import_node_events4.EventEmitter {
597
+ _state;
598
+ subscribers = [];
599
+ behaviors;
600
+ debug;
601
+ constructor(e = {}) {
602
+ super(),
603
+ (this._state = { status: 'idle' }),
604
+ (this.behaviors = { noSubscriber: 'pause', maxMissedFrames: 5, ...e.behaviors }),
605
+ (this.debug = !1 === e.debug ? null : e => this.emit('debug', e));
606
+ }
607
+ get playable() {
608
+ return this.subscribers.filter(({ connection: e }) => 'ready' === e.state.status).map(({ connection: e }) => e);
609
+ }
610
+ subscribe(e) {
611
+ let t = this.subscribers.find(t => t.connection === e);
612
+ if (!t) {
613
+ let s = new PlayerSubscription(e, this);
614
+ return this.subscribers.push(s), setImmediate(() => this.emit('subscribe', s)), s;
615
+ }
616
+ return t;
617
+ }
618
+ unsubscribe(e) {
619
+ let t = this.subscribers.indexOf(e),
620
+ s = -1 !== t;
621
+ return s && (this.subscribers.splice(t, 1), e.connection.setSpeaking(!1), this.emit('unsubscribe', e)), s;
622
+ }
623
+ get state() {
624
+ return this._state;
625
+ }
626
+ set state(e) {
627
+ let t = this._state,
628
+ s = Reflect.get(e, 'resource');
629
+ 'idle' !== t.status &&
630
+ t.resource !== s &&
631
+ (t.resource.playStream.on('error', noop),
632
+ t.resource.playStream.off('error', t.onStreamError),
633
+ (t.resource.audioPlayer = void 0),
634
+ t.resource.playStream.destroy(),
635
+ t.resource.playStream.read()),
636
+ 'buffering' === t.status &&
637
+ ('buffering' !== e.status || e.resource !== t.resource) &&
638
+ (t.resource.playStream.off('end', t.onFailureCallback),
639
+ t.resource.playStream.off('close', t.onFailureCallback),
640
+ t.resource.playStream.off('finish', t.onFailureCallback),
641
+ t.resource.playStream.off('readable', t.onReadableCallback)),
642
+ 'idle' === e.status && (this._signalStopSpeaking(), deleteAudioPlayer(this)),
643
+ s && addAudioPlayer(this);
644
+ let i = 'idle' !== t.status && 'playing' === e.status && t.resource !== e.resource;
645
+ (this._state = e),
646
+ this.emit('stateChange', t, this._state),
647
+ (t.status !== e.status || i) && this.emit(e.status, t, this._state),
648
+ this.debug?.(`state change:
649
+ from ${stringifyState2(t)}
650
+ to ${stringifyState2(e)}`);
651
+ }
652
+ play(e) {
653
+ if (e.ended) throw Error('Cannot play a resource that has already ended.');
654
+ if (e.audioPlayer) {
655
+ if (e.audioPlayer === this) return;
656
+ throw Error('Resource is already being played by another audio player.');
657
+ }
658
+ e.audioPlayer = this;
659
+ let t = __name(t => {
660
+ 'idle' !== this.state.status && this.emit('error', new AudioPlayerError(t, this.state.resource)),
661
+ 'idle' !== this.state.status && this.state.resource === e && (this.state = { status: 'idle' });
662
+ }, 'onStreamError');
663
+ if ((e.playStream.once('error', t), e.started))
664
+ this.state = { status: 'playing', missedFrames: 0, playbackDuration: 0, resource: e, onStreamError: t };
665
+ else {
666
+ let s = __name(() => {
667
+ 'buffering' === this.state.status &&
668
+ this.state.resource === e &&
669
+ (this.state = { status: 'playing', missedFrames: 0, playbackDuration: 0, resource: e, onStreamError: t });
670
+ }, 'onReadableCallback'),
671
+ i = __name(() => {
672
+ 'buffering' === this.state.status && this.state.resource === e && (this.state = { status: 'idle' });
673
+ }, 'onFailureCallback');
674
+ e.playStream.once('readable', s),
675
+ e.playStream.once('end', i),
676
+ e.playStream.once('close', i),
677
+ e.playStream.once('finish', i),
678
+ (this.state = {
679
+ status: 'buffering',
680
+ resource: e,
681
+ onReadableCallback: s,
682
+ onFailureCallback: i,
683
+ onStreamError: t,
684
+ });
685
+ }
686
+ }
687
+ pause(e = !0) {
688
+ return (
689
+ 'playing' === this.state.status &&
690
+ ((this.state = { ...this.state, status: 'paused', silencePacketsRemaining: e ? 5 : 0 }), !0)
691
+ );
692
+ }
693
+ unpause() {
694
+ return 'paused' === this.state.status && ((this.state = { ...this.state, status: 'playing', missedFrames: 0 }), !0);
695
+ }
696
+ stop(e = !1) {
697
+ return (
698
+ 'idle' !== this.state.status &&
699
+ (e || 0 === this.state.resource.silencePaddingFrames
700
+ ? (this.state = { status: 'idle' })
701
+ : -1 === this.state.resource.silenceRemaining &&
702
+ (this.state.resource.silenceRemaining = this.state.resource.silencePaddingFrames),
703
+ !0)
704
+ );
705
+ }
706
+ checkPlayable() {
707
+ let e = this._state;
708
+ return (
709
+ 'idle' !== e.status &&
710
+ 'buffering' !== e.status &&
711
+ (!!e.resource.readable || ((this.state = { status: 'idle' }), !1))
712
+ );
713
+ }
714
+ _stepDispatch() {
715
+ let e = this._state;
716
+ if ('idle' !== e.status && 'buffering' !== e.status) for (let t of this.playable) t.dispatchAudio();
717
+ }
718
+ _stepPrepare() {
719
+ let e = this._state;
720
+ if ('idle' === e.status || 'buffering' === e.status) return;
721
+ let t = this.playable;
722
+ if (
723
+ ('autopaused' === e.status && t.length > 0 && (this.state = { ...e, status: 'playing', missedFrames: 0 }),
724
+ 'paused' === e.status || 'autopaused' === e.status)
725
+ ) {
726
+ e.silencePacketsRemaining > 0 &&
727
+ (e.silencePacketsRemaining--,
728
+ this._preparePacket(SILENCE_FRAME, t, e),
729
+ 0 === e.silencePacketsRemaining && this._signalStopSpeaking());
730
+ return;
731
+ }
732
+ if (0 === t.length) {
733
+ if ('pause' === this.behaviors.noSubscriber) {
734
+ this.state = { ...e, status: 'autopaused', silencePacketsRemaining: 5 };
735
+ return;
736
+ }
737
+ 'stop' === this.behaviors.noSubscriber && this.stop(!0);
738
+ }
739
+ let s = e.resource.read();
740
+ 'playing' === e.status &&
741
+ (s
742
+ ? (this._preparePacket(s, t, e), (e.missedFrames = 0))
743
+ : (this._preparePacket(SILENCE_FRAME, t, e),
744
+ e.missedFrames++,
745
+ e.missedFrames >= this.behaviors.maxMissedFrames && this.stop()));
746
+ }
747
+ _signalStopSpeaking() {
748
+ for (let { connection: e } of this.subscribers) e.setSpeaking(!1);
749
+ }
750
+ _preparePacket(e, t, s) {
751
+ for (let i of ((s.playbackDuration += 20), t)) i.prepareAudioPacket(e);
752
+ }
753
+ };
754
+ function createAudioPlayer(e) {
755
+ return new AudioPlayer(e);
756
+ }
757
+ __name(AudioPlayer, 'AudioPlayer'), __name(createAudioPlayer, 'createAudioPlayer');
758
+ var EndBehaviorType =
759
+ (((EndBehaviorType2 = EndBehaviorType || {})[(EndBehaviorType2.Manual = 0)] = 'Manual'),
760
+ (EndBehaviorType2[(EndBehaviorType2.AfterSilence = 1)] = 'AfterSilence'),
761
+ (EndBehaviorType2[(EndBehaviorType2.AfterInactivity = 2)] = 'AfterInactivity'),
762
+ EndBehaviorType2);
763
+ function createDefaultAudioReceiveStreamOptions() {
764
+ return { end: { behavior: 0 } };
765
+ }
766
+ __name(createDefaultAudioReceiveStreamOptions, 'createDefaultAudioReceiveStreamOptions');
767
+ var AudioReceiveStream = class extends import_node_stream.Readable {
768
+ end;
769
+ endTimeout;
770
+ constructor({ end: e, ...t }) {
771
+ super({ ...t, objectMode: !0 }), (this.end = e);
772
+ }
773
+ push(e) {
774
+ return (
775
+ e &&
776
+ (2 === this.end.behavior ||
777
+ (1 === this.end.behavior && (0 !== e.compare(SILENCE_FRAME) || void 0 === this.endTimeout))) &&
778
+ this.renewEndTimeout(this.end),
779
+ super.push(e)
780
+ );
781
+ }
782
+ renewEndTimeout(e) {
783
+ this.endTimeout && clearTimeout(this.endTimeout), (this.endTimeout = setTimeout(() => this.push(null), e.duration));
784
+ }
785
+ _read() {}
786
+ };
787
+ __name(AudioReceiveStream, 'AudioReceiveStream');
788
+ var import_node_events5 = require('events'),
789
+ SSRCMap = class extends import_node_events5.EventEmitter {
790
+ map;
791
+ constructor() {
792
+ super(), (this.map = new Map());
793
+ }
794
+ update(e) {
795
+ let t = this.map.get(e.audioSSRC),
796
+ s = { ...this.map.get(e.audioSSRC), ...e };
797
+ this.map.set(e.audioSSRC, s), t || this.emit('create', s), this.emit('update', t, s);
798
+ }
799
+ get(e) {
800
+ if ('number' == typeof e) return this.map.get(e);
801
+ for (let t of this.map.values()) if (t.userId === e) return t;
802
+ }
803
+ delete(e) {
804
+ if ('number' == typeof e) {
805
+ let t = this.map.get(e);
806
+ return t && (this.map.delete(e), this.emit('delete', t)), t;
807
+ }
808
+ for (let [s, i] of this.map.entries()) if (i.userId === e) return this.map.delete(s), this.emit('delete', i), i;
809
+ }
810
+ };
811
+ __name(SSRCMap, 'SSRCMap');
812
+ var import_node_events6 = require('events'),
813
+ _SpeakingMap = class extends import_node_events6.EventEmitter {
814
+ users;
815
+ speakingTimeouts;
816
+ constructor() {
817
+ super(), (this.users = new Map()), (this.speakingTimeouts = new Map());
818
+ }
819
+ onPacket(e) {
820
+ let t = this.speakingTimeouts.get(e);
821
+ t ? clearTimeout(t) : (this.users.set(e, Date.now()), this.emit('start', e)), this.startTimeout(e);
822
+ }
823
+ startTimeout(e) {
824
+ this.speakingTimeouts.set(
825
+ e,
826
+ setTimeout(() => {
827
+ this.emit('end', e), this.speakingTimeouts.delete(e), this.users.delete(e);
828
+ }, _SpeakingMap.DELAY),
829
+ );
830
+ }
831
+ },
832
+ SpeakingMap = _SpeakingMap;
833
+ __name(SpeakingMap, 'SpeakingMap'), __publicField(SpeakingMap, 'DELAY', 100);
834
+ var VoiceReceiver = class {
835
+ voiceConnection;
836
+ ssrcMap;
837
+ subscriptions;
838
+ connectionData;
839
+ speaking;
840
+ constructor(e) {
841
+ (this.voiceConnection = e),
842
+ (this.ssrcMap = new SSRCMap()),
843
+ (this.speaking = new SpeakingMap()),
844
+ (this.subscriptions = new Map()),
845
+ (this.connectionData = {}),
846
+ (this.onWsPacket = this.onWsPacket.bind(this)),
847
+ (this.onUdpMessage = this.onUdpMessage.bind(this));
848
+ }
849
+ onWsPacket(e) {
850
+ e.op === import_v43.VoiceOpcodes.ClientDisconnect && 'string' == typeof e.d?.user_id
851
+ ? this.ssrcMap.delete(e.d.user_id)
852
+ : e.op === import_v43.VoiceOpcodes.Speaking && 'string' == typeof e.d?.user_id && 'number' == typeof e.d?.ssrc
853
+ ? this.ssrcMap.update({ userId: e.d.user_id, audioSSRC: e.d.ssrc })
854
+ : e.op === import_v43.VoiceOpcodes.ClientConnect &&
855
+ 'string' == typeof e.d?.user_id &&
856
+ 'number' == typeof e.d?.audio_ssrc &&
857
+ this.ssrcMap.update({
858
+ userId: e.d.user_id,
859
+ audioSSRC: e.d.audio_ssrc,
860
+ videoSSRC: 0 === e.d.video_ssrc ? void 0 : e.d.video_ssrc,
861
+ });
862
+ }
863
+ decrypt(e, t, s, i) {
864
+ let o;
865
+ 'xsalsa20_poly1305_lite' === t
866
+ ? (e.copy(s, 0, e.length - 4), (o = e.length - 4))
867
+ : 'xsalsa20_poly1305_suffix' === t
868
+ ? (e.copy(s, 0, e.length - 24), (o = e.length - 24))
869
+ : e.copy(s, 0, 0, 12);
870
+ let n = methods.open(e.slice(12, o), s, i);
871
+ if (n) return import_node_buffer5.Buffer.from(n);
872
+ }
873
+ parsePacket(e, t, s, i) {
874
+ let o = this.decrypt(e, t, s, i);
875
+ if (o) {
876
+ if (190 === o[0] && 222 === o[1]) {
877
+ let n = o.readUInt16BE(2);
878
+ o = o.subarray(4 + 4 * n);
879
+ }
880
+ return o;
881
+ }
882
+ }
883
+ onUdpMessage(e) {
884
+ if (e.length <= 8) return;
885
+ let t = e.readUInt32BE(8),
886
+ s = this.ssrcMap.get(t);
887
+ if (!s) return;
888
+ this.speaking.onPacket(s.userId);
889
+ let i = this.subscriptions.get(s.userId);
890
+ if (i && this.connectionData.encryptionMode && this.connectionData.nonceBuffer && this.connectionData.secretKey) {
891
+ let o = this.parsePacket(
892
+ e,
893
+ this.connectionData.encryptionMode,
894
+ this.connectionData.nonceBuffer,
895
+ this.connectionData.secretKey,
896
+ );
897
+ o ? i.push(o) : i.destroy(Error('Failed to parse packet'));
898
+ }
899
+ }
900
+ subscribe(e, t) {
901
+ let s = this.subscriptions.get(e);
902
+ if (s) return s;
903
+ let i = new AudioReceiveStream({ ...createDefaultAudioReceiveStreamOptions(), ...t });
904
+ return i.once('close', () => this.subscriptions.delete(e)), this.subscriptions.set(e, i), i;
905
+ }
906
+ };
907
+ __name(VoiceReceiver, 'VoiceReceiver');
908
+ var VoiceConnectionStatus =
909
+ (((VoiceConnectionStatus2 = VoiceConnectionStatus || {}).Connecting = 'connecting'),
910
+ (VoiceConnectionStatus2.Destroyed = 'destroyed'),
911
+ (VoiceConnectionStatus2.Disconnected = 'disconnected'),
912
+ (VoiceConnectionStatus2.Ready = 'ready'),
913
+ (VoiceConnectionStatus2.Signalling = 'signalling'),
914
+ VoiceConnectionStatus2),
915
+ VoiceConnectionDisconnectReason =
916
+ (((VoiceConnectionDisconnectReason2 = VoiceConnectionDisconnectReason || {})[
917
+ (VoiceConnectionDisconnectReason2.WebSocketClose = 0)
918
+ ] = 'WebSocketClose'),
919
+ (VoiceConnectionDisconnectReason2[(VoiceConnectionDisconnectReason2.AdapterUnavailable = 1)] =
920
+ 'AdapterUnavailable'),
921
+ (VoiceConnectionDisconnectReason2[(VoiceConnectionDisconnectReason2.EndpointRemoved = 2)] = 'EndpointRemoved'),
922
+ (VoiceConnectionDisconnectReason2[(VoiceConnectionDisconnectReason2.Manual = 3)] = 'Manual'),
923
+ VoiceConnectionDisconnectReason2),
924
+ VoiceConnection = class extends import_node_events7.EventEmitter {
925
+ rejoinAttempts;
926
+ _state;
927
+ joinConfig;
928
+ packets;
929
+ receiver;
930
+ debug;
931
+ constructor(e, t) {
932
+ super(),
933
+ (this.debug = t.debug ? e => this.emit('debug', e) : null),
934
+ (this.rejoinAttempts = 0),
935
+ (this.receiver = new VoiceReceiver(this)),
936
+ (this.onNetworkingClose = this.onNetworkingClose.bind(this)),
937
+ (this.onNetworkingStateChange = this.onNetworkingStateChange.bind(this)),
938
+ (this.onNetworkingError = this.onNetworkingError.bind(this)),
939
+ (this.onNetworkingDebug = this.onNetworkingDebug.bind(this));
940
+ let s = t.adapterCreator({
941
+ onVoiceServerUpdate: e => this.addServerPacket(e),
942
+ onVoiceStateUpdate: e => this.addStatePacket(e),
943
+ destroy: () => this.destroy(!1),
944
+ });
945
+ (this._state = { status: 'signalling', adapter: s }),
946
+ (this.packets = { server: void 0, state: void 0 }),
947
+ (this.joinConfig = e);
948
+ }
949
+ get state() {
950
+ return this._state;
951
+ }
952
+ set state(e) {
953
+ let t = this._state,
954
+ s = Reflect.get(t, 'networking'),
955
+ i = Reflect.get(e, 'networking'),
956
+ o = Reflect.get(t, 'subscription'),
957
+ n = Reflect.get(e, 'subscription');
958
+ if (
959
+ (s !== i &&
960
+ (s &&
961
+ (s.on('error', noop),
962
+ s.off('debug', this.onNetworkingDebug),
963
+ s.off('error', this.onNetworkingError),
964
+ s.off('close', this.onNetworkingClose),
965
+ s.off('stateChange', this.onNetworkingStateChange),
966
+ s.destroy()),
967
+ i && this.updateReceiveBindings(i.state, s?.state)),
968
+ 'ready' === e.status)
969
+ )
970
+ this.rejoinAttempts = 0;
971
+ else if ('destroyed' === e.status) for (let r of this.receiver.subscriptions.values()) r.destroyed || r.destroy();
972
+ 'destroyed' !== t.status && 'destroyed' === e.status && t.adapter.destroy(),
973
+ (this._state = e),
974
+ o && o !== n && o.unsubscribe(),
975
+ this.emit('stateChange', t, e),
976
+ t.status !== e.status && this.emit(e.status, t, e);
977
+ }
978
+ addServerPacket(e) {
979
+ (this.packets.server = e),
980
+ e.endpoint
981
+ ? this.configureNetworking()
982
+ : 'destroyed' !== this.state.status && (this.state = { ...this.state, status: 'disconnected', reason: 2 });
983
+ }
984
+ addStatePacket(e) {
985
+ (this.packets.state = e),
986
+ void 0 !== e.self_deaf && (this.joinConfig.selfDeaf = e.self_deaf),
987
+ void 0 !== e.self_mute && (this.joinConfig.selfMute = e.self_mute),
988
+ e.channel_id && (this.joinConfig.channelId = e.channel_id);
989
+ }
990
+ updateReceiveBindings(e, t) {
991
+ let s = Reflect.get(t ?? {}, 'ws'),
992
+ i = Reflect.get(e, 'ws'),
993
+ o = Reflect.get(t ?? {}, 'udp'),
994
+ n = Reflect.get(e, 'udp');
995
+ s !== i && (s?.off('packet', this.receiver.onWsPacket), i?.on('packet', this.receiver.onWsPacket)),
996
+ o !== n && (o?.off('message', this.receiver.onUdpMessage), n?.on('message', this.receiver.onUdpMessage)),
997
+ (this.receiver.connectionData = Reflect.get(e, 'connectionData') ?? {});
998
+ }
999
+ configureNetworking() {
1000
+ let { server: e, state: t } = this.packets;
1001
+ if (!e || !t || 'destroyed' === this.state.status || !e.endpoint) return;
1002
+ let s = new Networking(
1003
+ {
1004
+ endpoint: e.endpoint,
1005
+ serverId: e.guild_id ?? e.channel_id,
1006
+ token: e.token,
1007
+ sessionId: t.session_id,
1008
+ userId: t.user_id,
1009
+ },
1010
+ Boolean(this.debug),
1011
+ );
1012
+ s.once('close', this.onNetworkingClose),
1013
+ s.on('stateChange', this.onNetworkingStateChange),
1014
+ s.on('error', this.onNetworkingError),
1015
+ s.on('debug', this.onNetworkingDebug),
1016
+ (this.state = { ...this.state, status: 'connecting', networking: s });
1017
+ }
1018
+ onNetworkingClose(e) {
1019
+ 'destroyed' === this.state.status ||
1020
+ (4014 === e
1021
+ ? (this.state = { ...this.state, status: 'disconnected', reason: 0, closeCode: e })
1022
+ : ((this.state = { ...this.state, status: 'signalling' }),
1023
+ this.rejoinAttempts++,
1024
+ this.state.adapter.sendPayload(createJoinVoiceChannelPayload(this.joinConfig)) ||
1025
+ (this.state = { ...this.state, status: 'disconnected', reason: 1 })));
1026
+ }
1027
+ onNetworkingStateChange(e, t) {
1028
+ this.updateReceiveBindings(t, e),
1029
+ e.code !== t.code &&
1030
+ ('connecting' === this.state.status || 'ready' === this.state.status) &&
1031
+ (4 === t.code
1032
+ ? (this.state = { ...this.state, status: 'ready' })
1033
+ : 6 !== t.code && (this.state = { ...this.state, status: 'connecting' }));
1034
+ }
1035
+ onNetworkingError(e) {
1036
+ this.emit('error', e);
1037
+ }
1038
+ onNetworkingDebug(e) {
1039
+ this.debug?.(`[NW] ${e}`);
1040
+ }
1041
+ prepareAudioPacket(e) {
1042
+ let t = this.state;
1043
+ if ('ready' === t.status) return t.networking.prepareAudioPacket(e);
1044
+ }
1045
+ dispatchAudio() {
1046
+ let e = this.state;
1047
+ if ('ready' === e.status) return e.networking.dispatchAudio();
1048
+ }
1049
+ playOpusPacket(e) {
1050
+ let t = this.state;
1051
+ if ('ready' === t.status) return t.networking.prepareAudioPacket(e), t.networking.dispatchAudio();
1052
+ }
1053
+ destroy(e = !0) {
1054
+ if ('destroyed' === this.state.status)
1055
+ throw Error('Cannot destroy VoiceConnection - it has already been destroyed');
1056
+ getVoiceConnection(this.joinConfig.guildId, this.joinConfig.group) === this && untrackVoiceConnection(this),
1057
+ e && this.state.adapter.sendPayload(createJoinVoiceChannelPayload({ ...this.joinConfig, channelId: null })),
1058
+ (this.state = { status: 'destroyed' });
1059
+ }
1060
+ disconnect() {
1061
+ return (
1062
+ 'destroyed' !== this.state.status &&
1063
+ 'signalling' !== this.state.status &&
1064
+ (((this.joinConfig.channelId = null),
1065
+ this.state.adapter.sendPayload(createJoinVoiceChannelPayload(this.joinConfig)))
1066
+ ? ((this.state = { adapter: this.state.adapter, reason: 3, status: 'disconnected' }), !0)
1067
+ : ((this.state = {
1068
+ adapter: this.state.adapter,
1069
+ subscription: this.state.subscription,
1070
+ status: 'disconnected',
1071
+ reason: 1,
1072
+ }),
1073
+ !1))
1074
+ );
1075
+ }
1076
+ rejoin(e) {
1077
+ if ('destroyed' === this.state.status) return !1;
1078
+ let t = 'ready' !== this.state.status;
1079
+ return (t && this.rejoinAttempts++,
1080
+ Object.assign(this.joinConfig, e),
1081
+ this.state.adapter.sendPayload(createJoinVoiceChannelPayload(this.joinConfig)))
1082
+ ? (t && (this.state = { ...this.state, status: 'signalling' }), !0)
1083
+ : ((this.state = {
1084
+ adapter: this.state.adapter,
1085
+ subscription: this.state.subscription,
1086
+ status: 'disconnected',
1087
+ reason: 1,
1088
+ }),
1089
+ !1);
1090
+ }
1091
+ setSpeaking(e) {
1092
+ return 'ready' === this.state.status && this.state.networking.setSpeaking(e);
1093
+ }
1094
+ subscribe(e) {
1095
+ if ('destroyed' === this.state.status) return;
1096
+ let t = e.subscribe(this);
1097
+ return (this.state = { ...this.state, subscription: t }), t;
1098
+ }
1099
+ get ping() {
1100
+ return 'ready' === this.state.status && 4 === this.state.networking.state.code
1101
+ ? { ws: this.state.networking.state.ws.ping, udp: this.state.networking.state.udp.ping }
1102
+ : { ws: void 0, udp: void 0 };
1103
+ }
1104
+ onSubscriptionRemoved(e) {
1105
+ 'destroyed' !== this.state.status &&
1106
+ this.state.subscription === e &&
1107
+ (this.state = { ...this.state, subscription: void 0 });
1108
+ }
1109
+ };
1110
+ function createVoiceConnection(e, t) {
1111
+ let s = createJoinVoiceChannelPayload(e),
1112
+ i = getVoiceConnection(e.guildId, e.group);
1113
+ if (i && 'destroyed' !== i.state.status)
1114
+ return (
1115
+ 'disconnected' === i.state.status
1116
+ ? i.rejoin({ channelId: e.channelId, selfDeaf: e.selfDeaf, selfMute: e.selfMute })
1117
+ : i.state.adapter.sendPayload(s) || (i.state = { ...i.state, status: 'disconnected', reason: 1 }),
1118
+ i
1119
+ );
1120
+ let o = new VoiceConnection(e, t);
1121
+ return (
1122
+ trackVoiceConnection(o),
1123
+ 'destroyed' === o.state.status ||
1124
+ o.state.adapter.sendPayload(s) ||
1125
+ (o.state = { ...o.state, status: 'disconnected', reason: 1 }),
1126
+ o
1127
+ );
1128
+ }
1129
+ function joinVoiceChannel(e) {
1130
+ let t = { selfDeaf: !0, selfMute: !1, group: 'default', ...e };
1131
+ return createVoiceConnection(t, { adapterCreator: e.adapterCreator, debug: e.debug });
1132
+ }
1133
+ __name(VoiceConnection, 'VoiceConnection'),
1134
+ __name(createVoiceConnection, 'createVoiceConnection'),
1135
+ __name(joinVoiceChannel, 'joinVoiceChannel');
1136
+ var import_node_stream2 = require('stream'),
1137
+ import_prism_media2 = __toESM(require('prism-media')),
1138
+ import_prism_media = __toESM(require('prism-media')),
1139
+ FFMPEG_PCM_ARGUMENTS = ['-analyzeduration', '0', '-loglevel', '0', '-f', 's16le', '-ar', '48000', '-ac', '2'],
1140
+ FFMPEG_OPUS_ARGUMENTS = [
1141
+ '-analyzeduration',
1142
+ '0',
1143
+ '-loglevel',
1144
+ '0',
1145
+ '-acodec',
1146
+ 'libopus',
1147
+ '-f',
1148
+ 'opus',
1149
+ '-ar',
1150
+ '48000',
1151
+ '-ac',
1152
+ '2',
1153
+ ],
1154
+ StreamType =
1155
+ (((StreamType2 = StreamType || {}).Arbitrary = 'arbitrary'),
1156
+ (StreamType2.OggOpus = 'ogg/opus'),
1157
+ (StreamType2.Opus = 'opus'),
1158
+ (StreamType2.Raw = 'raw'),
1159
+ (StreamType2.WebmOpus = 'webm/opus'),
1160
+ StreamType2),
1161
+ Node = class {
1162
+ edges = [];
1163
+ type;
1164
+ constructor(e) {
1165
+ this.type = e;
1166
+ }
1167
+ addEdge(e) {
1168
+ this.edges.push({ ...e, from: this });
1169
+ }
1170
+ };
1171
+ __name(Node, 'Node');
1172
+ var NODES = new Map();
1173
+ for (const streamType of Object.values(StreamType)) NODES.set(streamType, new Node(streamType));
1174
+ function getNode(e) {
1175
+ let t = NODES.get(e);
1176
+ if (!t) throw Error(`Node type '${e}' does not exist!`);
1177
+ return t;
1178
+ }
1179
+ __name(getNode, 'getNode'),
1180
+ getNode('raw').addEdge({
1181
+ type: 'opus encoder',
1182
+ to: getNode('opus'),
1183
+ cost: 1.5,
1184
+ transformer: () => new import_prism_media.default.opus.Encoder({ rate: 48e3, channels: 2, frameSize: 960 }),
1185
+ }),
1186
+ getNode('opus').addEdge({
1187
+ type: 'opus decoder',
1188
+ to: getNode('raw'),
1189
+ cost: 1.5,
1190
+ transformer: () => new import_prism_media.default.opus.Decoder({ rate: 48e3, channels: 2, frameSize: 960 }),
1191
+ }),
1192
+ getNode('ogg/opus').addEdge({
1193
+ type: 'ogg/opus demuxer',
1194
+ to: getNode('opus'),
1195
+ cost: 1,
1196
+ transformer: () => new import_prism_media.default.opus.OggDemuxer(),
1197
+ }),
1198
+ getNode('webm/opus').addEdge({
1199
+ type: 'webm/opus demuxer',
1200
+ to: getNode('opus'),
1201
+ cost: 1,
1202
+ transformer: () => new import_prism_media.default.opus.WebmDemuxer(),
1203
+ });
1204
+ var FFMPEG_PCM_EDGE = {
1205
+ type: 'ffmpeg pcm',
1206
+ to: getNode('raw'),
1207
+ cost: 2,
1208
+ transformer: e =>
1209
+ new import_prism_media.default.FFmpeg({
1210
+ args: 'string' == typeof e ? ['-i', e, ...FFMPEG_PCM_ARGUMENTS] : FFMPEG_PCM_ARGUMENTS,
1211
+ }),
1212
+ };
1213
+ function canEnableFFmpegOptimizations() {
1214
+ try {
1215
+ return import_prism_media.default.FFmpeg.getInfo().output.includes('--enable-libopus');
1216
+ } catch {}
1217
+ return !1;
1218
+ }
1219
+ if (
1220
+ (getNode('arbitrary').addEdge(FFMPEG_PCM_EDGE),
1221
+ getNode('ogg/opus').addEdge(FFMPEG_PCM_EDGE),
1222
+ getNode('webm/opus').addEdge(FFMPEG_PCM_EDGE),
1223
+ getNode('raw').addEdge({
1224
+ type: 'volume transformer',
1225
+ to: getNode('raw'),
1226
+ cost: 0.5,
1227
+ transformer: () => new import_prism_media.default.VolumeTransformer({ type: 's16le' }),
1228
+ }),
1229
+ __name(canEnableFFmpegOptimizations, 'canEnableFFmpegOptimizations'),
1230
+ canEnableFFmpegOptimizations())
1231
+ ) {
1232
+ let e = {
1233
+ type: 'ffmpeg ogg',
1234
+ to: getNode('ogg/opus'),
1235
+ cost: 2,
1236
+ transformer: e =>
1237
+ new import_prism_media.default.FFmpeg({
1238
+ args: 'string' == typeof e ? ['-i', e, ...FFMPEG_OPUS_ARGUMENTS] : FFMPEG_OPUS_ARGUMENTS,
1239
+ }),
1240
+ };
1241
+ getNode('arbitrary').addEdge(e), getNode('ogg/opus').addEdge(e), getNode('webm/opus').addEdge(e);
1242
+ }
1243
+ function findPath(e, t, s = getNode('opus'), i = [], o = 5) {
1244
+ if (e === s && t(i)) return { cost: 0 };
1245
+ if (0 === o) return { cost: Number.POSITIVE_INFINITY };
1246
+ let n;
1247
+ for (let r of e.edges) {
1248
+ if (n && r.cost > n.cost) continue;
1249
+ let a = findPath(r.to, t, s, [...i, r], o - 1),
1250
+ c = r.cost + a.cost;
1251
+ (!n || c < n.cost) && (n = { cost: c, edge: r, next: a });
1252
+ }
1253
+ return n ?? { cost: Number.POSITIVE_INFINITY };
1254
+ }
1255
+ function constructPipeline(e) {
1256
+ let t = [],
1257
+ s = e;
1258
+ for (; s?.edge; ) t.push(s.edge), (s = s.next);
1259
+ return t;
1260
+ }
1261
+ function findPipeline(e, t) {
1262
+ return constructPipeline(findPath(getNode(e), t));
1263
+ }
1264
+ __name(findPath, 'findPath'), __name(constructPipeline, 'constructPipeline'), __name(findPipeline, 'findPipeline');
1265
+ var AudioResource = class {
1266
+ playStream;
1267
+ edges;
1268
+ metadata;
1269
+ volume;
1270
+ encoder;
1271
+ audioPlayer;
1272
+ playbackDuration = 0;
1273
+ started = !1;
1274
+ silencePaddingFrames;
1275
+ silenceRemaining = -1;
1276
+ constructor(e, t, s, i) {
1277
+ for (let o of ((this.edges = e),
1278
+ (this.playStream = t.length > 1 ? (0, import_node_stream2.pipeline)(t, noop) : t[0]),
1279
+ (this.metadata = s),
1280
+ (this.silencePaddingFrames = i),
1281
+ t))
1282
+ o instanceof import_prism_media2.default.VolumeTransformer
1283
+ ? (this.volume = o)
1284
+ : o instanceof import_prism_media2.default.opus.Encoder && (this.encoder = o);
1285
+ this.playStream.once('readable', () => (this.started = !0));
1286
+ }
1287
+ get readable() {
1288
+ if (0 === this.silenceRemaining) return !1;
1289
+ let e = this.playStream.readable;
1290
+ return (
1291
+ e ||
1292
+ (-1 === this.silenceRemaining && (this.silenceRemaining = this.silencePaddingFrames), 0 !== this.silenceRemaining)
1293
+ );
1294
+ }
1295
+ get ended() {
1296
+ return this.playStream.readableEnded || this.playStream.destroyed || 0 === this.silenceRemaining;
1297
+ }
1298
+ read() {
1299
+ if (0 === this.silenceRemaining) return null;
1300
+ if (this.silenceRemaining > 0) return this.silenceRemaining--, SILENCE_FRAME;
1301
+ let e = this.playStream.read();
1302
+ return e && (this.playbackDuration += 20), e;
1303
+ }
1304
+ };
1305
+ __name(AudioResource, 'AudioResource');
1306
+ var VOLUME_CONSTRAINT = __name(e => e.some(e => 'volume transformer' === e.type), 'VOLUME_CONSTRAINT'),
1307
+ NO_CONSTRAINT = __name(() => !0, 'NO_CONSTRAINT');
1308
+ function inferStreamType(e) {
1309
+ if (e instanceof import_prism_media2.default.opus.Encoder) return { streamType: 'opus', hasVolume: !1 };
1310
+ if (e instanceof import_prism_media2.default.opus.Decoder) return { streamType: 'raw', hasVolume: !1 };
1311
+ if (e instanceof import_prism_media2.default.VolumeTransformer) return { streamType: 'raw', hasVolume: !0 };
1312
+ if (e instanceof import_prism_media2.default.opus.OggDemuxer) return { streamType: 'opus', hasVolume: !1 };
1313
+ if (e instanceof import_prism_media2.default.opus.WebmDemuxer) return { streamType: 'opus', hasVolume: !1 };
1314
+ return { streamType: 'arbitrary', hasVolume: !1 };
1315
+ }
1316
+ function createAudioResource(e, t = {}) {
1317
+ let s = t.inputType,
1318
+ i = Boolean(t.inlineVolume);
1319
+ if ('string' == typeof e) s = 'arbitrary';
1320
+ else if (void 0 === s) {
1321
+ let o = inferStreamType(e);
1322
+ (s = o.streamType), (i = i && !o.hasVolume);
1323
+ }
1324
+ let n = findPipeline(s, i ? VOLUME_CONSTRAINT : NO_CONSTRAINT);
1325
+ if (0 === n.length) {
1326
+ if ('string' == typeof e) throw Error(`Invalid pipeline constructed for string resource '${e}'`);
1327
+ return new AudioResource([], [e], t.metadata ?? null, t.silencePaddingFrames ?? 5);
1328
+ }
1329
+ let r = n.map(t => t.transformer(e));
1330
+ return 'string' != typeof e && r.unshift(e), new AudioResource(n, r, t.metadata ?? null, t.silencePaddingFrames ?? 5);
1331
+ }
1332
+ __name(inferStreamType, 'inferStreamType'), __name(createAudioResource, 'createAudioResource');
1333
+ var import_node_path = require('path'),
1334
+ import_prism_media3 = __toESM(require('prism-media'));
1335
+ function findPackageJSON(e, t, s) {
1336
+ if (0 === s) return;
1337
+ let i = (0, import_node_path.resolve)(e, './package.json');
1338
+ try {
1339
+ let o = require(i);
1340
+ if (o.name !== t) throw Error('package.json does not match');
1341
+ return o;
1342
+ } catch {
1343
+ return findPackageJSON((0, import_node_path.resolve)(e, '..'), t, s - 1);
1344
+ }
1345
+ }
1346
+ function version(e) {
1347
+ try {
1348
+ if ('@discordjs/voice' === e) return '0.16.0';
1349
+ let t = findPackageJSON((0, import_node_path.dirname)(require.resolve(e)), e, 3);
1350
+ return t?.version ?? 'not found';
1351
+ } catch {
1352
+ return 'not found';
1353
+ }
1354
+ }
1355
+ function generateDependencyReport() {
1356
+ let e = [],
1357
+ t = __name(t => e.push(`- ${t}: ${version(t)}`), 'addVersion');
1358
+ e.push('Core Dependencies'),
1359
+ t('@discordjs/voice'),
1360
+ t('prism-media'),
1361
+ e.push(''),
1362
+ e.push('Opus Libraries'),
1363
+ t('@discordjs/opus'),
1364
+ t('opusscript'),
1365
+ e.push(''),
1366
+ e.push('Encryption Libraries'),
1367
+ t('sodium-native'),
1368
+ t('sodium'),
1369
+ t('libsodium-wrappers'),
1370
+ t('tweetnacl'),
1371
+ e.push(''),
1372
+ e.push('FFmpeg');
1373
+ try {
1374
+ let s = import_prism_media3.default.FFmpeg.getInfo();
1375
+ e.push(`- version: ${s.version}`), e.push(`- libopus: ${s.output.includes('--enable-libopus') ? 'yes' : 'no'}`);
1376
+ } catch {
1377
+ e.push('- not found');
1378
+ }
1379
+ return ['-'.repeat(50), ...e, '-'.repeat(50)].join('\n');
1380
+ }
1381
+ __name(findPackageJSON, 'findPackageJSON'),
1382
+ __name(version, 'version'),
1383
+ __name(generateDependencyReport, 'generateDependencyReport');
1384
+ var import_node_events8 = require('events');
1385
+ function abortAfter(e) {
1386
+ let t = new AbortController(),
1387
+ s = setTimeout(() => t.abort(), e);
1388
+ return t.signal.addEventListener('abort', () => clearTimeout(s)), [t, t.signal];
1389
+ }
1390
+ async function entersState(e, t, s) {
1391
+ if (e.state.status !== t) {
1392
+ let [i, o] = 'number' == typeof s ? abortAfter(s) : [void 0, s];
1393
+ try {
1394
+ await (0, import_node_events8.once)(e, t, { signal: o });
1395
+ } finally {
1396
+ i?.abort();
1397
+ }
1398
+ }
1399
+ return e;
1400
+ }
1401
+ __name(abortAfter, 'abortAfter'), __name(entersState, 'entersState');
1402
+ var import_node_buffer6 = require('buffer'),
1403
+ import_node_process = __toESM(require('process')),
1404
+ import_node_stream3 = require('stream'),
1405
+ import_prism_media4 = __toESM(require('prism-media'));
1406
+ function validateDiscordOpusHead(e) {
1407
+ let t = e.readUInt8(9),
1408
+ s = e.readUInt32LE(12);
1409
+ return 2 === t && 48e3 === s;
1410
+ }
1411
+ async function demuxProbe(e, t = 1024, s = validateDiscordOpusHead) {
1412
+ return new Promise((i, o) => {
1413
+ if (e.readableObjectMode) {
1414
+ o(Error('Cannot probe a readable stream in object mode'));
1415
+ return;
1416
+ }
1417
+ if (e.readableEnded) {
1418
+ o(Error('Cannot probe a stream that has ended'));
1419
+ return;
1420
+ }
1421
+ let n = import_node_buffer6.Buffer.alloc(0),
1422
+ r,
1423
+ a = __name(t => {
1424
+ e.off('data', l),
1425
+ e.off('close', p),
1426
+ e.off('end', p),
1427
+ e.pause(),
1428
+ (r = t),
1429
+ e.readableEnded
1430
+ ? i({ stream: import_node_stream3.Readable.from(n), type: t })
1431
+ : (n.length > 0 && e.push(n), i({ stream: e, type: t }));
1432
+ }, 'finish'),
1433
+ c = __name(
1434
+ e => t => {
1435
+ s(t) && a(e);
1436
+ },
1437
+ 'foundHead',
1438
+ ),
1439
+ d = new import_prism_media4.default.opus.WebmDemuxer();
1440
+ d.once('error', noop), d.on('head', c('webm/opus'));
1441
+ let u = new import_prism_media4.default.opus.OggDemuxer();
1442
+ u.once('error', noop), u.on('head', c('ogg/opus'));
1443
+ let p = __name(() => {
1444
+ r || a('arbitrary');
1445
+ }, 'onClose'),
1446
+ l = __name(s => {
1447
+ (n = import_node_buffer6.Buffer.concat([n, s])),
1448
+ d.write(s),
1449
+ u.write(s),
1450
+ n.length >= t && (e.off('data', l), e.pause(), import_node_process.default.nextTick(p));
1451
+ }, 'onData');
1452
+ e.once('error', o), e.on('data', l), e.once('close', p), e.once('end', p);
1453
+ });
1454
+ }
1455
+ __name(validateDiscordOpusHead, 'validateDiscordOpusHead'), __name(demuxProbe, 'demuxProbe');
1456
+ var version2 = '0.16.0';