@biggy1337/discord-sbjs 1.3.11

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.
Files changed (373) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +147 -0
  3. package/package.json +80 -0
  4. package/src/WebSocket.js +39 -0
  5. package/src/client/BaseClient.js +110 -0
  6. package/src/client/Client.js +1076 -0
  7. package/src/client/WebhookClient.js +61 -0
  8. package/src/client/actions/Action.js +133 -0
  9. package/src/client/actions/ActionsManager.js +80 -0
  10. package/src/client/actions/ApplicationCommandPermissionsUpdate.js +34 -0
  11. package/src/client/actions/AutoModerationActionExecution.js +27 -0
  12. package/src/client/actions/AutoModerationRuleCreate.js +28 -0
  13. package/src/client/actions/AutoModerationRuleDelete.js +32 -0
  14. package/src/client/actions/AutoModerationRuleUpdate.js +30 -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 +43 -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/InviteCreate.js +28 -0
  45. package/src/client/actions/InviteDelete.js +30 -0
  46. package/src/client/actions/MessageCreate.js +50 -0
  47. package/src/client/actions/MessageDelete.js +34 -0
  48. package/src/client/actions/MessageDeleteBulk.js +43 -0
  49. package/src/client/actions/MessagePollVoteAdd.js +33 -0
  50. package/src/client/actions/MessagePollVoteRemove.js +33 -0
  51. package/src/client/actions/MessageReactionAdd.js +71 -0
  52. package/src/client/actions/MessageReactionRemove.js +39 -0
  53. package/src/client/actions/MessageReactionRemoveAll.js +36 -0
  54. package/src/client/actions/MessageReactionRemoveEmoji.js +30 -0
  55. package/src/client/actions/MessageUpdate.js +28 -0
  56. package/src/client/actions/PresenceUpdate.js +55 -0
  57. package/src/client/actions/StageInstanceCreate.js +28 -0
  58. package/src/client/actions/StageInstanceDelete.js +33 -0
  59. package/src/client/actions/StageInstanceUpdate.js +30 -0
  60. package/src/client/actions/ThreadCreate.js +24 -0
  61. package/src/client/actions/ThreadDelete.js +32 -0
  62. package/src/client/actions/ThreadListSync.js +60 -0
  63. package/src/client/actions/ThreadMemberUpdate.js +30 -0
  64. package/src/client/actions/ThreadMembersUpdate.js +38 -0
  65. package/src/client/actions/TypingStart.js +31 -0
  66. package/src/client/actions/UserUpdate.js +35 -0
  67. package/src/client/actions/VoiceStateUpdate.js +63 -0
  68. package/src/client/actions/WebhooksUpdate.js +20 -0
  69. package/src/client/voice/ClientVoiceManager.js +162 -0
  70. package/src/client/voice/StreamEventRouter.js +60 -0
  71. package/src/client/voice/VoiceConnection.js +1173 -0
  72. package/src/client/voice/dispatcher/AnnexBDispatcher.js +120 -0
  73. package/src/client/voice/dispatcher/AudioDispatcher.js +145 -0
  74. package/src/client/voice/dispatcher/BaseDispatcher.js +459 -0
  75. package/src/client/voice/dispatcher/VPxDispatcher.js +54 -0
  76. package/src/client/voice/dispatcher/VideoDispatcher.js +68 -0
  77. package/src/client/voice/networking/VoiceUDPClient.js +187 -0
  78. package/src/client/voice/networking/VoiceWebSocket.js +347 -0
  79. package/src/client/voice/player/MediaPlayer.js +321 -0
  80. package/src/client/voice/player/processing/AnnexBNalSplitter.js +244 -0
  81. package/src/client/voice/player/processing/IvfSplitter.js +106 -0
  82. package/src/client/voice/player/processing/PCMInsertSilence.js +37 -0
  83. package/src/client/voice/receiver/PacketHandler.js +260 -0
  84. package/src/client/voice/receiver/Receiver.js +96 -0
  85. package/src/client/voice/receiver/Recorder.js +191 -0
  86. package/src/client/voice/util/Function.js +116 -0
  87. package/src/client/voice/util/PlayInterface.js +122 -0
  88. package/src/client/voice/util/Secretbox.js +64 -0
  89. package/src/client/voice/util/Silence.js +16 -0
  90. package/src/client/voice/util/Socket.js +62 -0
  91. package/src/client/voice/util/VolumeInterface.js +104 -0
  92. package/src/client/websocket/DispatchTable.js +7 -0
  93. package/src/client/websocket/GatewaySendScheduler.js +122 -0
  94. package/src/client/websocket/WebSocketManager.js +439 -0
  95. package/src/client/websocket/WebSocketShard.js +1085 -0
  96. package/src/client/websocket/handlers/APPLICATION_COMMAND_CREATE.js +18 -0
  97. package/src/client/websocket/handlers/APPLICATION_COMMAND_DELETE.js +20 -0
  98. package/src/client/websocket/handlers/APPLICATION_COMMAND_PERMISSIONS_UPDATE.js +5 -0
  99. package/src/client/websocket/handlers/APPLICATION_COMMAND_UPDATE.js +20 -0
  100. package/src/client/websocket/handlers/AUTO_MODERATION_ACTION_EXECUTION.js +5 -0
  101. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_CREATE.js +5 -0
  102. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_DELETE.js +5 -0
  103. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_UPDATE.js +5 -0
  104. package/src/client/websocket/handlers/CALL_CREATE.js +14 -0
  105. package/src/client/websocket/handlers/CALL_DELETE.js +11 -0
  106. package/src/client/websocket/handlers/CALL_UPDATE.js +11 -0
  107. package/src/client/websocket/handlers/CHANNEL_CREATE.js +5 -0
  108. package/src/client/websocket/handlers/CHANNEL_DELETE.js +5 -0
  109. package/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.js +22 -0
  110. package/src/client/websocket/handlers/CHANNEL_RECIPIENT_ADD.js +19 -0
  111. package/src/client/websocket/handlers/CHANNEL_RECIPIENT_REMOVE.js +16 -0
  112. package/src/client/websocket/handlers/CHANNEL_UPDATE.js +16 -0
  113. package/src/client/websocket/handlers/GUILD_AUDIT_LOG_ENTRY_CREATE.js +5 -0
  114. package/src/client/websocket/handlers/GUILD_BAN_ADD.js +5 -0
  115. package/src/client/websocket/handlers/GUILD_BAN_REMOVE.js +5 -0
  116. package/src/client/websocket/handlers/GUILD_CREATE.js +51 -0
  117. package/src/client/websocket/handlers/GUILD_DELETE.js +5 -0
  118. package/src/client/websocket/handlers/GUILD_EMOJIS_UPDATE.js +5 -0
  119. package/src/client/websocket/handlers/GUILD_INTEGRATIONS_UPDATE.js +5 -0
  120. package/src/client/websocket/handlers/GUILD_MEMBERS_CHUNK.js +45 -0
  121. package/src/client/websocket/handlers/GUILD_MEMBER_ADD.js +20 -0
  122. package/src/client/websocket/handlers/GUILD_MEMBER_REMOVE.js +5 -0
  123. package/src/client/websocket/handlers/GUILD_MEMBER_UPDATE.js +5 -0
  124. package/src/client/websocket/handlers/GUILD_ROLE_CREATE.js +5 -0
  125. package/src/client/websocket/handlers/GUILD_ROLE_DELETE.js +5 -0
  126. package/src/client/websocket/handlers/GUILD_ROLE_UPDATE.js +5 -0
  127. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_CREATE.js +5 -0
  128. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_DELETE.js +5 -0
  129. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_UPDATE.js +5 -0
  130. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_ADD.js +5 -0
  131. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_REMOVE.js +5 -0
  132. package/src/client/websocket/handlers/GUILD_STICKERS_UPDATE.js +5 -0
  133. package/src/client/websocket/handlers/GUILD_UPDATE.js +5 -0
  134. package/src/client/websocket/handlers/INTERACTION_MODAL_CREATE.js +12 -0
  135. package/src/client/websocket/handlers/INVITE_CREATE.js +5 -0
  136. package/src/client/websocket/handlers/INVITE_DELETE.js +5 -0
  137. package/src/client/websocket/handlers/MESSAGE_CREATE.js +5 -0
  138. package/src/client/websocket/handlers/MESSAGE_DELETE.js +5 -0
  139. package/src/client/websocket/handlers/MESSAGE_DELETE_BULK.js +5 -0
  140. package/src/client/websocket/handlers/MESSAGE_POLL_VOTE_ADD.js +5 -0
  141. package/src/client/websocket/handlers/MESSAGE_POLL_VOTE_REMOVE.js +5 -0
  142. package/src/client/websocket/handlers/MESSAGE_REACTION_ADD.js +5 -0
  143. package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE.js +5 -0
  144. package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_ALL.js +5 -0
  145. package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_EMOJI.js +5 -0
  146. package/src/client/websocket/handlers/MESSAGE_UPDATE.js +16 -0
  147. package/src/client/websocket/handlers/PRESENCE_UPDATE.js +5 -0
  148. package/src/client/websocket/handlers/READY.js +156 -0
  149. package/src/client/websocket/handlers/RELATIONSHIP_ADD.js +19 -0
  150. package/src/client/websocket/handlers/RELATIONSHIP_REMOVE.js +17 -0
  151. package/src/client/websocket/handlers/RELATIONSHIP_UPDATE.js +41 -0
  152. package/src/client/websocket/handlers/RESUMED.js +14 -0
  153. package/src/client/websocket/handlers/STAGE_INSTANCE_CREATE.js +5 -0
  154. package/src/client/websocket/handlers/STAGE_INSTANCE_DELETE.js +5 -0
  155. package/src/client/websocket/handlers/STAGE_INSTANCE_UPDATE.js +5 -0
  156. package/src/client/websocket/handlers/THREAD_CREATE.js +5 -0
  157. package/src/client/websocket/handlers/THREAD_DELETE.js +5 -0
  158. package/src/client/websocket/handlers/THREAD_LIST_SYNC.js +5 -0
  159. package/src/client/websocket/handlers/THREAD_MEMBERS_UPDATE.js +5 -0
  160. package/src/client/websocket/handlers/THREAD_MEMBER_UPDATE.js +5 -0
  161. package/src/client/websocket/handlers/THREAD_UPDATE.js +16 -0
  162. package/src/client/websocket/handlers/TYPING_START.js +5 -0
  163. package/src/client/websocket/handlers/USER_GUILD_SETTINGS_UPDATE.js +6 -0
  164. package/src/client/websocket/handlers/USER_NOTE_UPDATE.js +5 -0
  165. package/src/client/websocket/handlers/USER_REQUIRED_ACTION_UPDATE.js +82 -0
  166. package/src/client/websocket/handlers/USER_SETTINGS_UPDATE.js +5 -0
  167. package/src/client/websocket/handlers/USER_UPDATE.js +5 -0
  168. package/src/client/websocket/handlers/VOICE_CHANNEL_EFFECT_SEND.js +16 -0
  169. package/src/client/websocket/handlers/VOICE_CHANNEL_STATUS_UPDATE.js +12 -0
  170. package/src/client/websocket/handlers/VOICE_SERVER_UPDATE.js +12 -0
  171. package/src/client/websocket/handlers/VOICE_STATE_UPDATE.js +5 -0
  172. package/src/client/websocket/handlers/WEBHOOKS_UPDATE.js +5 -0
  173. package/src/client/websocket/handlers/index.js +84 -0
  174. package/src/errors/DJSError.js +61 -0
  175. package/src/errors/Messages.js +218 -0
  176. package/src/errors/index.js +4 -0
  177. package/src/index.js +172 -0
  178. package/src/managers/ApplicationCommandManager.js +264 -0
  179. package/src/managers/ApplicationCommandPermissionsManager.js +417 -0
  180. package/src/managers/AutoModerationRuleManager.js +296 -0
  181. package/src/managers/BaseGuildEmojiManager.js +80 -0
  182. package/src/managers/BaseManager.js +19 -0
  183. package/src/managers/BillingManager.js +66 -0
  184. package/src/managers/CachedManager.js +72 -0
  185. package/src/managers/ChannelManager.js +148 -0
  186. package/src/managers/ClientUserSettingManager.js +372 -0
  187. package/src/managers/DataManager.js +61 -0
  188. package/src/managers/DeveloperManager.js +265 -0
  189. package/src/managers/GuildBanManager.js +252 -0
  190. package/src/managers/GuildChannelManager.js +488 -0
  191. package/src/managers/GuildEmojiManager.js +171 -0
  192. package/src/managers/GuildEmojiRoleManager.js +118 -0
  193. package/src/managers/GuildForumThreadManager.js +108 -0
  194. package/src/managers/GuildInviteManager.js +213 -0
  195. package/src/managers/GuildManager.js +401 -0
  196. package/src/managers/GuildMemberManager.js +608 -0
  197. package/src/managers/GuildMemberRoleManager.js +195 -0
  198. package/src/managers/GuildScheduledEventManager.js +314 -0
  199. package/src/managers/GuildSettingManager.js +155 -0
  200. package/src/managers/GuildStickerManager.js +179 -0
  201. package/src/managers/GuildTextThreadManager.js +98 -0
  202. package/src/managers/InteractionManager.js +39 -0
  203. package/src/managers/MessageManager.js +457 -0
  204. package/src/managers/PermissionOverwriteManager.js +169 -0
  205. package/src/managers/PresenceManager.js +71 -0
  206. package/src/managers/QuestManager.js +391 -0
  207. package/src/managers/ReactionManager.js +67 -0
  208. package/src/managers/ReactionUserManager.js +73 -0
  209. package/src/managers/RelationshipManager.js +341 -0
  210. package/src/managers/RoleManager.js +448 -0
  211. package/src/managers/SessionManager.js +66 -0
  212. package/src/managers/StageInstanceManager.js +162 -0
  213. package/src/managers/ThreadManager.js +175 -0
  214. package/src/managers/ThreadMemberManager.js +186 -0
  215. package/src/managers/UserManager.js +274 -0
  216. package/src/managers/UserNoteManager.js +53 -0
  217. package/src/managers/VoiceStateManager.js +59 -0
  218. package/src/rest/APIRequest.js +198 -0
  219. package/src/rest/APIRouter.js +94 -0
  220. package/src/rest/DiscordAPIError.js +120 -0
  221. package/src/rest/HTTPError.js +62 -0
  222. package/src/rest/RESTManager.js +203 -0
  223. package/src/rest/RateLimitCoordinator.js +156 -0
  224. package/src/rest/RateLimitError.js +55 -0
  225. package/src/rest/RequestHandler.js +552 -0
  226. package/src/sharding/Shard.js +444 -0
  227. package/src/sharding/ShardClientUtil.js +279 -0
  228. package/src/sharding/ShardingManager.js +319 -0
  229. package/src/structures/AnonymousGuild.js +98 -0
  230. package/src/structures/ApplicationCommand.js +593 -0
  231. package/src/structures/ApplicationRoleConnectionMetadata.js +48 -0
  232. package/src/structures/AutoModerationActionExecution.js +89 -0
  233. package/src/structures/AutoModerationRule.js +294 -0
  234. package/src/structures/AutocompleteInteraction.js +107 -0
  235. package/src/structures/Base.js +43 -0
  236. package/src/structures/BaseCommandInteraction.js +211 -0
  237. package/src/structures/BaseGuild.js +124 -0
  238. package/src/structures/BaseGuildEmoji.js +56 -0
  239. package/src/structures/BaseGuildTextChannel.js +191 -0
  240. package/src/structures/BaseGuildVoiceChannel.js +241 -0
  241. package/src/structures/BaseMessageComponent.js +181 -0
  242. package/src/structures/ButtonInteraction.js +11 -0
  243. package/src/structures/CallState.js +63 -0
  244. package/src/structures/CategoryChannel.js +85 -0
  245. package/src/structures/Channel.js +284 -0
  246. package/src/structures/ClientPresence.js +77 -0
  247. package/src/structures/ClientUser.js +706 -0
  248. package/src/structures/CommandInteraction.js +41 -0
  249. package/src/structures/CommandInteractionOptionResolver.js +276 -0
  250. package/src/structures/ContainerComponent.js +68 -0
  251. package/src/structures/ContextMenuInteraction.js +65 -0
  252. package/src/structures/DMChannel.js +222 -0
  253. package/src/structures/DirectoryChannel.js +20 -0
  254. package/src/structures/Emoji.js +148 -0
  255. package/src/structures/FileComponent.js +49 -0
  256. package/src/structures/ForumChannel.js +31 -0
  257. package/src/structures/GroupDMChannel.js +415 -0
  258. package/src/structures/Guild.js +1804 -0
  259. package/src/structures/GuildAuditLogs.js +746 -0
  260. package/src/structures/GuildBan.js +59 -0
  261. package/src/structures/GuildBoost.js +108 -0
  262. package/src/structures/GuildChannel.js +470 -0
  263. package/src/structures/GuildEmoji.js +161 -0
  264. package/src/structures/GuildMember.js +636 -0
  265. package/src/structures/GuildPreview.js +191 -0
  266. package/src/structures/GuildPreviewEmoji.js +27 -0
  267. package/src/structures/GuildScheduledEvent.js +536 -0
  268. package/src/structures/GuildTemplate.js +236 -0
  269. package/src/structures/Integration.js +188 -0
  270. package/src/structures/IntegrationApplication.js +96 -0
  271. package/src/structures/Interaction.js +290 -0
  272. package/src/structures/InteractionCollector.js +248 -0
  273. package/src/structures/InteractionWebhook.js +43 -0
  274. package/src/structures/Invite.js +358 -0
  275. package/src/structures/InviteGuild.js +23 -0
  276. package/src/structures/InviteStageInstance.js +86 -0
  277. package/src/structures/MediaChannel.js +11 -0
  278. package/src/structures/MediaGalleryComponent.js +41 -0
  279. package/src/structures/MediaGalleryItem.js +47 -0
  280. package/src/structures/Message.js +1272 -0
  281. package/src/structures/MessageActionRow.js +105 -0
  282. package/src/structures/MessageAttachment.js +216 -0
  283. package/src/structures/MessageButton.js +166 -0
  284. package/src/structures/MessageCollector.js +146 -0
  285. package/src/structures/MessageComponentInteraction.js +120 -0
  286. package/src/structures/MessageContextMenuInteraction.js +20 -0
  287. package/src/structures/MessageEmbed.js +596 -0
  288. package/src/structures/MessageMentions.js +273 -0
  289. package/src/structures/MessagePayload.js +354 -0
  290. package/src/structures/MessageReaction.js +181 -0
  291. package/src/structures/MessageSelectMenu.js +141 -0
  292. package/src/structures/Modal.js +161 -0
  293. package/src/structures/ModalSubmitFieldsResolver.js +53 -0
  294. package/src/structures/ModalSubmitInteraction.js +119 -0
  295. package/src/structures/NewsChannel.js +32 -0
  296. package/src/structures/OAuth2Guild.js +28 -0
  297. package/src/structures/PermissionOverwrites.js +198 -0
  298. package/src/structures/Poll.js +108 -0
  299. package/src/structures/PollAnswer.js +88 -0
  300. package/src/structures/Presence.js +1165 -0
  301. package/src/structures/ReactionCollector.js +229 -0
  302. package/src/structures/ReactionEmoji.js +31 -0
  303. package/src/structures/Role.js +590 -0
  304. package/src/structures/SectionComponent.js +48 -0
  305. package/src/structures/SelectMenuInteraction.js +21 -0
  306. package/src/structures/SeparatorComponent.js +48 -0
  307. package/src/structures/Session.js +81 -0
  308. package/src/structures/StageChannel.js +104 -0
  309. package/src/structures/StageInstance.js +208 -0
  310. package/src/structures/Sticker.js +310 -0
  311. package/src/structures/StickerPack.js +95 -0
  312. package/src/structures/StoreChannel.js +56 -0
  313. package/src/structures/Team.js +118 -0
  314. package/src/structures/TeamMember.js +80 -0
  315. package/src/structures/TextChannel.js +33 -0
  316. package/src/structures/TextDisplayComponent.js +40 -0
  317. package/src/structures/TextInputComponent.js +132 -0
  318. package/src/structures/ThreadChannel.js +605 -0
  319. package/src/structures/ThreadMember.js +105 -0
  320. package/src/structures/ThreadOnlyChannel.js +249 -0
  321. package/src/structures/ThumbnailComponent.js +57 -0
  322. package/src/structures/Typing.js +74 -0
  323. package/src/structures/UnfurledMediaItem.js +29 -0
  324. package/src/structures/User.js +992 -0
  325. package/src/structures/UserContextMenuInteraction.js +29 -0
  326. package/src/structures/VoiceChannel.js +110 -0
  327. package/src/structures/VoiceChannelEffect.js +69 -0
  328. package/src/structures/VoiceRegion.js +53 -0
  329. package/src/structures/VoiceState.js +354 -0
  330. package/src/structures/WebEmbed.js +373 -0
  331. package/src/structures/Webhook.js +478 -0
  332. package/src/structures/WelcomeChannel.js +60 -0
  333. package/src/structures/WelcomeScreen.js +48 -0
  334. package/src/structures/Widget.js +87 -0
  335. package/src/structures/WidgetMember.js +100 -0
  336. package/src/structures/interfaces/Application.js +953 -0
  337. package/src/structures/interfaces/Collector.js +301 -0
  338. package/src/structures/interfaces/InteractionResponses.js +313 -0
  339. package/src/structures/interfaces/TextBasedChannel.js +821 -0
  340. package/src/util/APITypes.js +59 -0
  341. package/src/util/ActivityFlags.js +44 -0
  342. package/src/util/ApplicationFlags.js +76 -0
  343. package/src/util/AttachmentFlags.js +38 -0
  344. package/src/util/BitField.js +170 -0
  345. package/src/util/ChannelFlags.js +45 -0
  346. package/src/util/Constants.js +1953 -0
  347. package/src/util/DataResolver.js +162 -0
  348. package/src/util/FastQueue.js +93 -0
  349. package/src/util/FetchUtil.js +77 -0
  350. package/src/util/Formatters.js +228 -0
  351. package/src/util/GuildMemberFlags.js +43 -0
  352. package/src/util/Intents.js +74 -0
  353. package/src/util/InviteFlags.js +34 -0
  354. package/src/util/LimitedCollection.js +131 -0
  355. package/src/util/ListenerUtil.js +12 -0
  356. package/src/util/MessageFlags.js +63 -0
  357. package/src/util/Options.js +431 -0
  358. package/src/util/Permissions.js +202 -0
  359. package/src/util/PremiumUsageFlags.js +31 -0
  360. package/src/util/PurchasedFlags.js +33 -0
  361. package/src/util/RemoteAuth.js +425 -0
  362. package/src/util/RoleFlags.js +37 -0
  363. package/src/util/SnowflakeUtil.js +92 -0
  364. package/src/util/Speaking.js +33 -0
  365. package/src/util/Sweepers.js +493 -0
  366. package/src/util/SystemChannelFlags.js +55 -0
  367. package/src/util/ThreadMemberFlags.js +30 -0
  368. package/src/util/UserFlags.js +104 -0
  369. package/src/util/Util.js +1144 -0
  370. package/typings/enums.d.ts +437 -0
  371. package/typings/index.d.ts +8857 -0
  372. package/typings/index.test-d.ts +0 -0
  373. package/typings/rawDataTypes.d.ts +403 -0
@@ -0,0 +1,187 @@
1
+ 'use strict';
2
+
3
+ const udp = require('dgram');
4
+ const EventEmitter = require('events');
5
+ const { isIP } = require('net');
6
+ const { Buffer } = require('node:buffer');
7
+ const { Error } = require('../../../errors');
8
+ const { VoiceOpcodes } = require('../../../util/Constants');
9
+ const Util = require('../../../util/Util');
10
+
11
+ /**
12
+ * Represents a UDP client for a Voice Connection.
13
+ * @extends {EventEmitter}
14
+ * @private
15
+ */
16
+ class VoiceConnectionUDPClient extends EventEmitter {
17
+ constructor(voiceConnection) {
18
+ super();
19
+
20
+ /**
21
+ * The voice connection that this UDP client serves
22
+ * @type {VoiceConnection}
23
+ */
24
+ this.voiceConnection = voiceConnection;
25
+
26
+ /**
27
+ * The UDP socket
28
+ * @type {?Socket}
29
+ */
30
+ this.socket = null;
31
+
32
+ /**
33
+ * The address of the Discord voice server
34
+ * @type {?string}
35
+ */
36
+ this.discordAddress = null;
37
+
38
+ /**
39
+ * The local IP address
40
+ * @type {?string}
41
+ */
42
+ this.localAddress = null;
43
+
44
+ /**
45
+ * The local port
46
+ * @type {?string}
47
+ */
48
+ this.localPort = null;
49
+
50
+ this.voiceConnection.on('closing', this.shutdown.bind(this));
51
+ }
52
+
53
+ shutdown() {
54
+ this._debug('[UDP] shutdown requested');
55
+ if (this.socket) {
56
+ this.socket.removeAllListeners('message');
57
+ try {
58
+ this.socket.close();
59
+ } finally {
60
+ this.socket = null;
61
+ }
62
+ }
63
+ }
64
+
65
+ /**
66
+ * The port of the Discord voice server
67
+ * @type {number}
68
+ * @readonly
69
+ */
70
+ get discordPort() {
71
+ return this.voiceConnection.authentication.port;
72
+ }
73
+
74
+ _shouldEmitDebug() {
75
+ return this.voiceConnection.hasDebugListeners() || this.listenerCount('debug') > 0;
76
+ }
77
+
78
+ _debug(message) {
79
+ if (!this._shouldEmitDebug()) return;
80
+ this.emit('debug', message);
81
+ }
82
+
83
+ _debugLazy(factory) {
84
+ if (!this._shouldEmitDebug()) return;
85
+ this.emit('debug', factory());
86
+ }
87
+
88
+ /**
89
+ * Send a packet to the UDP client.
90
+ * @param {Object} packet The packet to send
91
+ * @returns {Promise<Object>}
92
+ */
93
+ send(packet) {
94
+ return new Promise((resolve, reject) => {
95
+ if (!this.socket) throw new Error('UDP_SEND_FAIL');
96
+ if (!this.discordAddress || !this.discordPort) throw new Error('UDP_ADDRESS_MALFORMED');
97
+ this.socket.send(packet, 0, packet.length, this.discordPort, this.discordAddress, error => {
98
+ if (error) {
99
+ this._debug(`[UDP] >> ERROR: ${error}`);
100
+ reject(error);
101
+ } else {
102
+ resolve(packet);
103
+ }
104
+ });
105
+ });
106
+ }
107
+
108
+ async createUDPSocket(address) {
109
+ this.discordAddress = address;
110
+ const socket = (this.socket = udp.createSocket('udp4'));
111
+ socket.on('error', e => {
112
+ this._debug(`[UDP] Error: ${e}`);
113
+ this.emit('error', e);
114
+ });
115
+ socket.on('close', () => {
116
+ this._debug('[UDP] socket closed');
117
+ });
118
+ this._debug('[UDP] created socket');
119
+ socket.once('message', message => {
120
+ this._debugLazy(() => `[UDP] message: [${[...message]}] (${message})`);
121
+ if (message.readUInt16BE(0) !== 2) {
122
+ throw new Error('UDP_WRONG_HANDSHAKE');
123
+ }
124
+ // Stop if the sockets have been deleted because the connection has been closed already
125
+ if (!this.voiceConnection.sockets.ws) return;
126
+
127
+ const packet = parseLocalPacket(message);
128
+ if (packet.error) {
129
+ this._debug(`[UDP] ERROR: ${packet.error}`);
130
+ this.emit('error', packet.error);
131
+ return;
132
+ }
133
+
134
+ this._debug(`[UDP] Parse local packet: ${packet.address}:${packet.port}`);
135
+
136
+ this.localAddress = packet.address;
137
+ this.localPort = packet.port;
138
+
139
+ this.voiceConnection.sockets.ws.sendPacket({
140
+ op: VoiceOpcodes.SELECT_PROTOCOL,
141
+ d: {
142
+ protocol: 'udp',
143
+ codecs: Util.getAllPayloadType(),
144
+ data: {
145
+ address: packet.address,
146
+ port: packet.port,
147
+ mode: this.voiceConnection.authentication.mode,
148
+ },
149
+ },
150
+ });
151
+
152
+ // Write = false
153
+ Object.defineProperty(this.voiceConnection, 'videoCodec', {
154
+ value: this.voiceConnection.videoCodec,
155
+ writable: false,
156
+ });
157
+
158
+ this._debugLazy(() => `[UDP] << ${JSON.stringify(packet)}`);
159
+
160
+ socket.on('message', buffer => this.voiceConnection.receiver.packets.push(buffer));
161
+ });
162
+
163
+ const blankMessage = Buffer.alloc(74);
164
+ blankMessage.writeUInt16BE(1, 0);
165
+ blankMessage.writeUInt16BE(70, 2);
166
+ blankMessage.writeUInt32BE(this.voiceConnection.authentication.ssrc, 4);
167
+ this._debugLazy(() => `Sending IP discovery packet: [${[...blankMessage]}]`);
168
+ await this.send(blankMessage);
169
+ this._debug('Successfully sent IP discovery packet');
170
+ }
171
+ }
172
+
173
+ function parseLocalPacket(message) {
174
+ try {
175
+ const packet = Buffer.from(message);
176
+ const address = packet.subarray(8, packet.indexOf(0, 8)).toString('utf8');
177
+ if (!isIP(address)) {
178
+ throw new Error('UDP_ADDRESS_MALFORMED');
179
+ }
180
+ const port = packet.readUInt16BE(packet.length - 2);
181
+ return { address, port };
182
+ } catch (error) {
183
+ return { error };
184
+ }
185
+ }
186
+
187
+ module.exports = VoiceConnectionUDPClient;
@@ -0,0 +1,347 @@
1
+ 'use strict';
2
+
3
+ const EventEmitter = require('events');
4
+ const { setTimeout, setInterval } = require('node:timers');
5
+ const WebSocket = require('../../../WebSocket');
6
+ const { Error } = require('../../../errors');
7
+ const { VoiceOpcodes, VoiceStatus } = require('../../../util/Constants');
8
+
9
+ /**
10
+ * Represents a Voice Connection's WebSocket.
11
+ * @extends {EventEmitter}
12
+ * @private
13
+ */
14
+ class VoiceWebSocket extends EventEmitter {
15
+ constructor(connection) {
16
+ super();
17
+ /**
18
+ * The Voice Connection that this WebSocket serves
19
+ * @type {VoiceConnection}
20
+ */
21
+ this.connection = connection;
22
+
23
+ /**
24
+ * How many connection attempts have been made
25
+ * @type {number}
26
+ */
27
+ this.attempts = 0;
28
+
29
+ this._sequenceNumber = this.connection._voiceSequence ?? -1;
30
+ this._resumeAttempted = false;
31
+
32
+ this.dead = false;
33
+ this.connection.on('closing', this.shutdown.bind(this));
34
+ }
35
+
36
+ /**
37
+ * The client of this voice WebSocket
38
+ * @type {Client}
39
+ * @readonly
40
+ */
41
+ get client() {
42
+ return this.connection.client;
43
+ }
44
+
45
+ _shouldEmitDebug() {
46
+ return this.connection.hasDebugListeners() || this.listenerCount('debug') > 0;
47
+ }
48
+
49
+ _debug(message) {
50
+ if (!this._shouldEmitDebug()) return;
51
+ this.emit('debug', message);
52
+ }
53
+
54
+ _debugLazy(factory) {
55
+ if (!this._shouldEmitDebug()) return;
56
+ this.emit('debug', factory());
57
+ }
58
+
59
+ shutdown() {
60
+ this._debug('[WS] shutdown requested');
61
+ this.dead = true;
62
+ this.reset();
63
+ }
64
+
65
+ /**
66
+ * Resets the current WebSocket.
67
+ */
68
+ reset() {
69
+ this._debug('[WS] reset requested');
70
+ if (this.ws) {
71
+ if (this.ws.readyState !== WebSocket.CLOSED) this.ws.close();
72
+ this.ws = null;
73
+ }
74
+ this.clearHeartbeat();
75
+ }
76
+
77
+ /**
78
+ * Starts connecting to the Voice WebSocket Server.
79
+ */
80
+ connect() {
81
+ this._debug('[WS] connect requested');
82
+ if (this.dead) return;
83
+ if (this.ws) this.reset();
84
+ if (this.attempts >= 5) {
85
+ this._debug(new Error('VOICE_CONNECTION_ATTEMPTS_EXCEEDED', this.attempts));
86
+ return;
87
+ }
88
+
89
+ this.attempts++;
90
+
91
+ /**
92
+ * The actual WebSocket used to connect to the Voice WebSocket Server.
93
+ * @type {WebSocket}
94
+ */
95
+ this.ws = WebSocket.create(`wss://${this.connection.authentication.endpoint}/`, { v: 9 });
96
+ this._debug(`[WS] connecting, ${this.attempts} attempts, ${this.ws.url}`);
97
+ this.ws.onopen = this.onOpen.bind(this);
98
+ this.ws.onmessage = this.onMessage.bind(this);
99
+ this.ws.onclose = this.onClose.bind(this);
100
+ this.ws.onerror = this.onError.bind(this);
101
+ }
102
+
103
+ /**
104
+ * Sends data to the WebSocket if it is open.
105
+ * @param {string} data The data to send to the WebSocket
106
+ * @returns {Promise<string>}
107
+ */
108
+ send(data) {
109
+ this._debug(`[WS] >> ${data}`);
110
+ return new Promise((resolve, reject) => {
111
+ if (!this.ws || this.ws.readyState !== WebSocket.OPEN) throw new Error('WS_NOT_OPEN', data);
112
+ this.ws.send(data, null, error => {
113
+ if (error) reject(error);
114
+ else resolve(data);
115
+ });
116
+ });
117
+ }
118
+
119
+ /**
120
+ * JSON.stringify's a packet and then sends it to the WebSocket Server.
121
+ * @param {Object} packet The packet to send
122
+ * @returns {Promise<string>}
123
+ */
124
+ async sendPacket(packet) {
125
+ packet = JSON.stringify(packet);
126
+ return this.send(packet);
127
+ }
128
+
129
+ sendIdentify() {
130
+ return this.sendPacket({
131
+ op: VoiceOpcodes.IDENTIFY,
132
+ d: {
133
+ server_id: this.connection.serverId || this.connection.channel.guild?.id || this.connection.channel.id,
134
+ channel_id: this.connection.channel.id,
135
+ user_id: this.client.user.id,
136
+ token: this.connection.authentication.token,
137
+ session_id: this.connection.authentication.sessionId,
138
+ streams: [{ type: 'screen', rid: '100', quality: 100 }],
139
+ video: true,
140
+ },
141
+ });
142
+ }
143
+
144
+ sendResume() {
145
+ return this.sendPacket({
146
+ op: VoiceOpcodes.RESUME,
147
+ d: {
148
+ server_id: this.connection.serverId || this.connection.channel.guild?.id || this.connection.channel.id,
149
+ session_id: this.connection.authentication.sessionId,
150
+ token: this.connection.authentication.token,
151
+ seq_ack: this._sequenceNumber,
152
+ channel_id: this.connection.channel.id,
153
+ },
154
+ });
155
+ }
156
+
157
+ /**
158
+ * Called whenever the WebSocket opens.
159
+ */
160
+ onOpen() {
161
+ this._debug(`[WS] opened at gateway ${this.connection.authentication.endpoint}`);
162
+
163
+ const shouldResume =
164
+ this.connection.status === VoiceStatus.RECONNECTING &&
165
+ this._sequenceNumber >= 0 &&
166
+ Boolean(this.connection.authentication.sessionId && this.connection.authentication.token);
167
+
168
+ const connectPromise = shouldResume ? this.sendResume() : this.sendIdentify();
169
+ this._resumeAttempted = shouldResume;
170
+ connectPromise.catch(() => {
171
+ if (shouldResume) {
172
+ this._resumeAttempted = false;
173
+ this.connection._voiceSequence = -1;
174
+ this._sequenceNumber = -1;
175
+ this.sendIdentify().catch(() => this.emit('error', new Error('VOICE_JOIN_SOCKET_CLOSED')));
176
+ } else {
177
+ this.emit('error', new Error('VOICE_JOIN_SOCKET_CLOSED'));
178
+ }
179
+ });
180
+ }
181
+
182
+ /**
183
+ * Called whenever a message is received from the WebSocket.
184
+ * @param {MessageEvent} event The message event that was received
185
+ * @returns {void}
186
+ */
187
+ onMessage(event) {
188
+ try {
189
+ return this.onPacket(WebSocket.unpack(event.data, 'json'));
190
+ } catch (error) {
191
+ return this.onError(error);
192
+ }
193
+ }
194
+
195
+ /**
196
+ * Called whenever the connection to the WebSocket server is lost.
197
+ * @param {CloseEvent} event The WebSocket close event
198
+ */
199
+ onClose(event) {
200
+ this._debug(`[WS] closed with code ${event.code} and reason: ${event.reason}`);
201
+ if (this._resumeAttempted) {
202
+ this.connection._voiceSequence = -1;
203
+ this._sequenceNumber = -1;
204
+ this._resumeAttempted = false;
205
+ }
206
+ if (!this.dead) setTimeout(this.connect.bind(this), this.attempts * 1000).unref();
207
+ }
208
+
209
+ /**
210
+ * Called whenever an error occurs with the WebSocket.
211
+ * @param {Error} error The error that occurred
212
+ */
213
+ onError(error) {
214
+ this._debug(`[WS] Error: ${error}`);
215
+ this.emit('error', error);
216
+ }
217
+
218
+ /**
219
+ * Called whenever a valid packet is received from the WebSocket.
220
+ * @param {Object} packet The received packet
221
+ */
222
+ onPacket(packet) {
223
+ this._debugLazy(() => `[WS] << ${JSON.stringify(packet)}`);
224
+ if (packet.seq != null) {
225
+ this._sequenceNumber = packet.seq;
226
+ this.connection._voiceSequence = packet.seq;
227
+ }
228
+ switch (packet.op) {
229
+ case VoiceOpcodes.HELLO:
230
+ this.setHeartbeat(packet.d.heartbeat_interval);
231
+ break;
232
+ case VoiceOpcodes.READY:
233
+ this.attempts = 0;
234
+ this._resumeAttempted = false;
235
+ /**
236
+ * Emitted once the voice WebSocket receives the ready packet.
237
+ * @param {Object} packet The received packet
238
+ * @event VoiceWebSocket#ready
239
+ */
240
+ this.emit('ready', packet.d);
241
+ this.connection.setVideoStatus(false);
242
+ break;
243
+ case VoiceOpcodes.RESUMED:
244
+ this.attempts = 0;
245
+ this._resumeAttempted = false;
246
+ this.emit('resumed', packet.d);
247
+ break;
248
+ /* eslint-disable no-case-declarations */
249
+ case VoiceOpcodes.SESSION_DESCRIPTION:
250
+ packet.d.secret_key = new Uint8Array(packet.d.secret_key);
251
+ /**
252
+ * Emitted once the Voice Websocket receives a description of this voice session.
253
+ * @param {Object} packet The received packet
254
+ * @event VoiceWebSocket#sessionDescription
255
+ */
256
+ this.emit('sessionDescription', packet.d);
257
+ break;
258
+ case VoiceOpcodes.CLIENT_CONNECT:
259
+ this.connection.ssrcMap.set(+packet.d.audio_ssrc, {
260
+ userId: packet.d.user_id,
261
+ speaking: 0,
262
+ hasVideo: Boolean(packet.d.video_ssrc),
263
+ });
264
+ break;
265
+ case VoiceOpcodes.CLIENT_DISCONNECT:
266
+ const streamInfo = this.connection.receiver && this.connection.receiver.packets.streams.get(packet.d.user_id);
267
+ if (streamInfo) {
268
+ this.connection.receiver.packets.streams.delete(packet.d.user_id);
269
+ streamInfo.stream.push(null);
270
+ }
271
+ break;
272
+ case VoiceOpcodes.SPEAKING:
273
+ /**
274
+ * Emitted whenever a speaking packet is received.
275
+ * @param {Object} data
276
+ * @event VoiceWebSocket#startSpeaking
277
+ */
278
+ this.emit('startSpeaking', packet.d);
279
+ break;
280
+ case VoiceOpcodes.VIDEO:
281
+ case VoiceOpcodes.SOURCES:
282
+ /**
283
+ * Emitted whenever a streaming packet is received.
284
+ * @param {Object} data
285
+ * @event VoiceWebSocket#startStreaming
286
+ */
287
+ this.emit('startStreaming', packet.d);
288
+ break;
289
+ default:
290
+ /**
291
+ * Emitted when an unhandled packet is received.
292
+ * @param {Object} packet
293
+ * @event VoiceWebSocket#unknownPacket
294
+ */
295
+ this.emit('unknownPacket', packet);
296
+ break;
297
+ }
298
+ }
299
+
300
+ /**
301
+ * Sets an interval at which to send a heartbeat packet to the WebSocket.
302
+ * @param {number} interval The interval at which to send a heartbeat packet
303
+ */
304
+ setHeartbeat(interval) {
305
+ if (!interval || isNaN(interval)) {
306
+ this.onError(new Error('VOICE_INVALID_HEARTBEAT'));
307
+ return;
308
+ }
309
+ if (this.heartbeatInterval) {
310
+ /**
311
+ * Emitted whenever the voice WebSocket encounters a non-fatal error.
312
+ * @param {string} warn The warning
313
+ * @event VoiceWebSocket#warn
314
+ */
315
+ this.emit('warn', 'A voice heartbeat interval is being overwritten');
316
+ clearInterval(this.heartbeatInterval);
317
+ }
318
+ this.heartbeatInterval = setInterval(this.sendHeartbeat.bind(this), interval).unref();
319
+ }
320
+
321
+ /**
322
+ * Clears a heartbeat interval, if one exists.
323
+ */
324
+ clearHeartbeat() {
325
+ if (!this.heartbeatInterval) return;
326
+ clearInterval(this.heartbeatInterval);
327
+ this.heartbeatInterval = null;
328
+ }
329
+
330
+ /**
331
+ * Sends a heartbeat packet.
332
+ */
333
+ sendHeartbeat() {
334
+ this.sendPacket({
335
+ op: VoiceOpcodes.HEARTBEAT,
336
+ d: {
337
+ t: Date.now(),
338
+ seq_ack: this._sequenceNumber,
339
+ },
340
+ }).catch(() => {
341
+ this.emit('warn', 'Tried to send heartbeat, but connection is not open');
342
+ this.clearHeartbeat();
343
+ });
344
+ }
345
+ }
346
+
347
+ module.exports = VoiceWebSocket;