@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,1165 @@
1
+ 'use strict';
2
+
3
+ const { randomUUID } = require('node:crypto');
4
+ const Base = require('./Base');
5
+ const ActivityFlags = require('../util/ActivityFlags');
6
+ const { ActivityTypes } = require('../util/Constants');
7
+ const Util = require('../util/Util');
8
+
9
+ /**
10
+ * Activity sent in a message.
11
+ * @typedef {Object} MessageActivity
12
+ * @property {string} [partyId] Id of the party represented in activity
13
+ * @property {MessageActivityType} type Type of activity sent
14
+ */
15
+
16
+ /**
17
+ * The status of this presence:
18
+ * * **`online`** - user is online
19
+ * * **`idle`** - user is AFK
20
+ * * **`offline`** - user is offline or invisible
21
+ * * **`dnd`** - user is in Do Not Disturb
22
+ * @typedef {string} PresenceStatus
23
+ */
24
+
25
+ /**
26
+ * The status of this presence:
27
+ * * **`online`** - user is online
28
+ * * **`idle`** - user is AFK
29
+ * * **`dnd`** - user is in Do Not Disturb
30
+ * @typedef {string} ClientPresenceStatus
31
+ */
32
+
33
+ /**
34
+ * Represents a user's presence.
35
+ * @extends {Base}
36
+ */
37
+ class Presence extends Base {
38
+ constructor(client, data = {}) {
39
+ super(client);
40
+
41
+ /**
42
+ * The presence's user id
43
+ * @type {Snowflake}
44
+ */
45
+ this.userId = data.user.id;
46
+
47
+ /**
48
+ * The guild this presence is in
49
+ * @type {?Guild}
50
+ */
51
+ this.guild = data.guild ?? null;
52
+
53
+ this._patch(data);
54
+ }
55
+
56
+ /**
57
+ * The user of this presence
58
+ * @type {?User}
59
+ * @readonly
60
+ */
61
+ get user() {
62
+ return this.client.users.resolve(this.userId);
63
+ }
64
+
65
+ /**
66
+ * The member of this presence
67
+ * @type {?GuildMember}
68
+ * @readonly
69
+ */
70
+ get member() {
71
+ return this.guild.members.resolve(this.userId);
72
+ }
73
+
74
+ _patch(data) {
75
+ if ('status' in data) {
76
+ /**
77
+ * The status of this presence
78
+ * @type {PresenceStatus}
79
+ */
80
+ this.status = data.status;
81
+ } else {
82
+ this.status ??= 'offline';
83
+ }
84
+
85
+ if ('activities' in data) {
86
+ /**
87
+ * The activities of this presence (Always `Activity[]` if not ClientUser)
88
+ * @type {CustomStatus[]|RichPresence[]|SpotifyRPC[]|Activity[]}
89
+ */
90
+ this.activities = data.activities.map(activity => {
91
+ if (this.userId == this.client.user.id) {
92
+ if ([ActivityTypes.CUSTOM, 'CUSTOM'].includes(activity.type)) {
93
+ return new CustomStatus(this.client, activity);
94
+ } else if (activity.id == 'spotify:1') {
95
+ return new SpotifyRPC(this.client, activity);
96
+ } else {
97
+ return new RichPresence(this.client, activity);
98
+ }
99
+ } else {
100
+ return new Activity(this, activity);
101
+ }
102
+ });
103
+ } else {
104
+ this.activities ??= [];
105
+ }
106
+
107
+ if ('client_status' in data) {
108
+ /**
109
+ * The devices this presence is on
110
+ * @type {?Object}
111
+ * @property {?ClientPresenceStatus} web The current presence in the web application
112
+ * @property {?ClientPresenceStatus} mobile The current presence in the mobile application
113
+ * @property {?ClientPresenceStatus} desktop The current presence in the desktop application
114
+ */
115
+ this.clientStatus = data.client_status;
116
+ } else {
117
+ this.clientStatus ??= null;
118
+ }
119
+
120
+ if ('last_modified' in data) {
121
+ /**
122
+ * The timestamp this presence was last updated
123
+ * @type {number}
124
+ */
125
+ this.lastModified = data.last_modified;
126
+ }
127
+
128
+ if ('afk' in data) {
129
+ this.afk = data.afk;
130
+ } else {
131
+ this.afk ??= false;
132
+ }
133
+
134
+ if ('since' in data) {
135
+ this.since = data.since;
136
+ } else {
137
+ this.since ??= 0;
138
+ }
139
+
140
+ return this;
141
+ }
142
+
143
+ _clone() {
144
+ const clone = Object.assign(Object.create(this), this);
145
+ if (!this.activities.length) {
146
+ clone.activities = this.activities;
147
+ return clone;
148
+ }
149
+ const clonedActivities = [];
150
+ for (const activity of this.activities) {
151
+ clonedActivities.push(typeof activity._clone === 'function' ? activity._clone() : activity);
152
+ }
153
+ clone.activities = clonedActivities;
154
+ return clone;
155
+ }
156
+
157
+ /**
158
+ * Whether this presence is equal to another.
159
+ * @param {Presence} presence The presence to compare with
160
+ * @returns {boolean}
161
+ */
162
+ equals(presence) {
163
+ return (
164
+ this === presence ||
165
+ (presence &&
166
+ this.status === presence.status &&
167
+ this.clientStatus?.web === presence.clientStatus?.web &&
168
+ this.clientStatus?.mobile === presence.clientStatus?.mobile &&
169
+ this.clientStatus?.desktop === presence.clientStatus?.desktop &&
170
+ this.activities.length === presence.activities.length &&
171
+ this.activities.every((activity, index) => activity.equals(presence.activities[index])))
172
+ );
173
+ }
174
+
175
+ toJSON() {
176
+ return Util.flatten(this);
177
+ }
178
+ }
179
+
180
+ /**
181
+ * The platform of this activity:
182
+ * * **`desktop`**
183
+ * * **`samsung`** - playing on Samsung Galaxy
184
+ * * **`xbox`** - playing on Xbox Live
185
+ * * **`ios`**
186
+ * * **`android`**
187
+ * * **`embedded`**
188
+ * * **`ps4`**
189
+ * * **`ps5`**
190
+ * @typedef {string} ActivityPlatform
191
+ */
192
+
193
+ /**
194
+ * Represents an activity that is part of a user's presence.
195
+ */
196
+ class Activity {
197
+ constructor(presence, data) {
198
+ if (!(presence instanceof Presence)) {
199
+ throw new Error("Class constructor Activity cannot be invoked without 'presence'");
200
+ }
201
+ /**
202
+ * The presence of the Activity
203
+ * @type {Presence}
204
+ * @readonly
205
+ * @name Activity#presence
206
+ */
207
+ Object.defineProperty(this, 'presence', { value: presence });
208
+
209
+ this._patch(data);
210
+ }
211
+
212
+ _patch(data = {}) {
213
+ if ('id' in data) {
214
+ /**
215
+ * The activity's id
216
+ * @type {string}
217
+ */
218
+ this.id = data.id;
219
+ }
220
+
221
+ if ('name' in data) {
222
+ /**
223
+ * The activity's name
224
+ * @type {string}
225
+ */
226
+ this.name = data.name;
227
+ }
228
+
229
+ if ('type' in data) {
230
+ /**
231
+ * The activity status's type
232
+ * @type {ActivityType}
233
+ */
234
+ this.type = typeof data.type === 'number' ? ActivityTypes[data.type] : data.type;
235
+ }
236
+
237
+ if ('url' in data) {
238
+ /**
239
+ * If the activity is being streamed, a link to the stream
240
+ * @type {?string}
241
+ */
242
+ this.url = data.url;
243
+ } else {
244
+ this.url = null;
245
+ }
246
+
247
+ if ('created_at' in data || 'createdTimestamp' in data) {
248
+ /**
249
+ * Creation date of the activity
250
+ * @type {number}
251
+ */
252
+ this.createdTimestamp = data.created_at || data.createdTimestamp;
253
+ }
254
+
255
+ if ('session_id' in data) {
256
+ /**
257
+ * The game's or Spotify session's id
258
+ * @type {?string}
259
+ */
260
+ this.sessionId = data.session_id;
261
+ } else {
262
+ this.sessionId = this.presence.client?.sessionId;
263
+ }
264
+
265
+ if ('platform' in data) {
266
+ /**
267
+ * The platform the game is being played on
268
+ * @type {?ActivityPlatform}
269
+ */
270
+ this.platform = data.platform;
271
+ } else {
272
+ this.platform = null;
273
+ }
274
+
275
+ if ('timestamps' in data && data.timestamps) {
276
+ /**
277
+ * Represents timestamps of an activity
278
+ * @typedef {Object} ActivityTimestamps
279
+ * @property {?number} start When the activity started
280
+ * @property {?number} end When the activity will end
281
+ */
282
+
283
+ /**
284
+ * Timestamps for the activity
285
+ * @type {?ActivityTimestamps}
286
+ */
287
+ this.timestamps = {
288
+ start: data.timestamps.start ? new Date(data.timestamps.start).getTime() : null,
289
+ end: data.timestamps.end ? new Date(data.timestamps.end).getTime() : null,
290
+ };
291
+ } else {
292
+ this.timestamps = null;
293
+ }
294
+
295
+ if ('application_id' in data || 'applicationId' in data) {
296
+ /**
297
+ * The id of the application associated with this activity
298
+ * @type {?Snowflake}
299
+ */
300
+ this.applicationId = data.application_id || data.applicationId;
301
+ } else {
302
+ this.applicationId = null;
303
+ }
304
+
305
+ if ('details' in data) {
306
+ /**
307
+ * Details about the activity
308
+ * @type {?string}
309
+ */
310
+ this.details = data.details;
311
+ } else {
312
+ this.details = null;
313
+ }
314
+
315
+ if ('details_url' in data) {
316
+ /**
317
+ * URL for the details of the activity
318
+ * @type {?string}
319
+ */
320
+ this.details_url = data.details_url;
321
+ } else {
322
+ this.details_url = null;
323
+ }
324
+
325
+ if ('state' in data) {
326
+ /**
327
+ * State of the activity
328
+ * @type {?string}
329
+ */
330
+ this.state = data.state;
331
+ } else {
332
+ this.state = null;
333
+ }
334
+
335
+ if ('state_url' in data) {
336
+ /**
337
+ * URL for the state of the activity
338
+ * @type {?string}
339
+ */
340
+ this.state_url = data.state_url;
341
+ } else {
342
+ this.state_url = null;
343
+ }
344
+
345
+ if ('sync_id' in data || 'syncId' in data) {
346
+ /**
347
+ * The sync id of the activity
348
+ * <info>This property is not documented by Discord and represents the track id in spotify activities.</info>
349
+ * @type {?string}
350
+ */
351
+ this.syncId = data.sync_id || data.syncId;
352
+ } else {
353
+ this.syncId = null;
354
+ }
355
+
356
+ if ('flags' in data) {
357
+ /**
358
+ * Flags that describe the activity
359
+ * @type {Readonly<ActivityFlags>}
360
+ */
361
+ this.flags = new ActivityFlags(data.flags).freeze();
362
+ } else {
363
+ this.flags = new ActivityFlags().freeze();
364
+ }
365
+
366
+ if ('buttons' in data) {
367
+ /**
368
+ * The labels of the buttons of this rich presence
369
+ * @type {string[]}
370
+ */
371
+ this.buttons = data.buttons;
372
+ } else {
373
+ this.buttons = [];
374
+ }
375
+
376
+ if ('emoji' in data && data.emoji) {
377
+ /**
378
+ * Emoji for a custom activity
379
+ * @type {?EmojiIdentifierResolvable}
380
+ */
381
+ this.emoji = Util.resolvePartialEmoji(data.emoji);
382
+ } else {
383
+ this.emoji = null;
384
+ }
385
+
386
+ if ('party' in data) {
387
+ /**
388
+ * Represents a party of an activity
389
+ * @typedef {Object} ActivityParty
390
+ * @property {?string} id The party's id
391
+ * @property {number[]} size Size of the party as `[current, max]`
392
+ */
393
+
394
+ /**
395
+ * Party of the activity
396
+ * @type {?ActivityParty}
397
+ */
398
+ this.party = data.party;
399
+ } else {
400
+ this.party = null;
401
+ }
402
+
403
+ /**
404
+ * Assets for rich presence
405
+ * @type {?RichPresenceAssets}
406
+ */
407
+ this.assets = new RichPresenceAssets(this, data.assets);
408
+ }
409
+
410
+ /**
411
+ * Whether this activity is equal to another activity.
412
+ * @param {Activity} activity The activity to compare with
413
+ * @returns {boolean}
414
+ */
415
+ equals(activity) {
416
+ return (
417
+ this === activity ||
418
+ (activity &&
419
+ this.name === activity.name &&
420
+ this.type === activity.type &&
421
+ this.url === activity.url &&
422
+ this.state === activity.state &&
423
+ this.state_url === activity.state_url &&
424
+ this.details === activity.details &&
425
+ this.details_url == activity.details_url &&
426
+ this.emoji?.id === activity.emoji?.id &&
427
+ this.emoji?.name === activity.emoji?.name)
428
+ );
429
+ }
430
+
431
+ /**
432
+ * The time the activity was created at
433
+ * @type {Date}
434
+ * @readonly
435
+ */
436
+ get createdAt() {
437
+ return new Date(this.createdTimestamp);
438
+ }
439
+
440
+ /**
441
+ * When concatenated with a string, this automatically returns the activities' name instead of the Activity object.
442
+ * @returns {string}
443
+ */
444
+ toString() {
445
+ return this.name;
446
+ }
447
+
448
+ _clone() {
449
+ return Object.assign(Object.create(this), this);
450
+ }
451
+
452
+ toJSON(...props) {
453
+ return Util.clearNullOrUndefinedObject({
454
+ ...Util.flatten(this, ...props),
455
+ type: typeof this.type === 'number' ? this.type : ActivityTypes[this.type],
456
+ });
457
+ }
458
+ }
459
+
460
+ /**
461
+ * Assets for a rich presence
462
+ */
463
+ class RichPresenceAssets {
464
+ constructor(activity, assets) {
465
+ /**
466
+ * The activity of the RichPresenceAssets
467
+ * @type {Activity}
468
+ * @readonly
469
+ * @name RichPresenceAssets#activity
470
+ */
471
+ Object.defineProperty(this, 'activity', { value: activity });
472
+
473
+ this._patch(assets);
474
+ }
475
+
476
+ _patch(assets = {}) {
477
+ if ('large_text' in assets || 'largeText' in assets) {
478
+ /**
479
+ * Hover text for the large image
480
+ * @type {?string}
481
+ */
482
+ this.largeText = assets.large_text || assets.largeText;
483
+ } else {
484
+ this.largeText = null;
485
+ }
486
+
487
+ if ('small_text' in assets || 'smallText' in assets) {
488
+ /**
489
+ * Hover text for the small image
490
+ * @type {?string}
491
+ */
492
+ this.smallText = assets.small_text || assets.smallText;
493
+ } else {
494
+ this.smallText = null;
495
+ }
496
+
497
+ if ('large_image' in assets || 'largeImage' in assets) {
498
+ /**
499
+ * The large image asset's id
500
+ * @type {?Snowflake}
501
+ */
502
+ this.largeImage = assets.large_image || assets.largeImage;
503
+ } else {
504
+ this.largeImage = null;
505
+ }
506
+
507
+ if ('small_image' in assets || 'smallImage' in assets) {
508
+ /**
509
+ * The small image asset's id
510
+ * @type {?Snowflake}
511
+ */
512
+ this.smallImage = assets.small_image || assets.smallImage;
513
+ } else {
514
+ this.smallImage = null;
515
+ }
516
+ }
517
+
518
+ /**
519
+ * Gets the URL of the small image asset
520
+ * @param {StaticImageURLOptions} [options] Options for the image URL
521
+ * @returns {?string}
522
+ */
523
+ smallImageURL({ format, size } = {}) {
524
+ if (!this.smallImage) return null;
525
+ if (this.smallImage.includes(':')) {
526
+ const [platform, id] = this.smallImage.split(':');
527
+ switch (platform) {
528
+ case 'mp':
529
+ return `https://media.discordapp.net/${id}`;
530
+ case 'spotify':
531
+ return `https://i.scdn.co/image/${id}`;
532
+ case 'youtube':
533
+ return `https://i.ytimg.com/vi/${id}/hqdefault_live.jpg`;
534
+ case 'twitch':
535
+ return `https://static-cdn.jtvnw.net/previews-ttv/live_user_${id}.png`;
536
+ default:
537
+ return null;
538
+ }
539
+ }
540
+
541
+ return this.activity.presence.client.rest.cdn.AppAsset(this.activity.applicationId, this.smallImage, {
542
+ format,
543
+ size,
544
+ });
545
+ }
546
+
547
+ /**
548
+ * Gets the URL of the large image asset
549
+ * @param {StaticImageURLOptions} [options] Options for the image URL
550
+ * @returns {?string}
551
+ */
552
+ largeImageURL({ format, size } = {}) {
553
+ if (!this.largeImage) return null;
554
+ if (this.largeImage.includes(':')) {
555
+ const [platform, id] = this.largeImage.split(':');
556
+ switch (platform) {
557
+ case 'mp':
558
+ return `https://media.discordapp.net/${id}`;
559
+ case 'spotify':
560
+ return `https://i.scdn.co/image/${id}`;
561
+ case 'youtube':
562
+ return `https://i.ytimg.com/vi/${id}/hqdefault_live.jpg`;
563
+ case 'twitch':
564
+ return `https://static-cdn.jtvnw.net/previews-ttv/live_user_${id}.png`;
565
+ default:
566
+ return null;
567
+ }
568
+ }
569
+
570
+ return this.activity.presence.client.rest.cdn.AppAsset(this.activity.applicationId, this.largeImage, {
571
+ format,
572
+ size,
573
+ });
574
+ }
575
+
576
+ static parseImage(image) {
577
+ if (typeof image != 'string') {
578
+ image = null;
579
+ } else if (URL.canParse(image) && ['http:', 'https:'].includes(new URL(image).protocol)) {
580
+ // Discord URL:
581
+ image = image
582
+ .replace('https://cdn.discordapp.com/', 'mp:')
583
+ .replace('http://cdn.discordapp.com/', 'mp:')
584
+ .replace('https://media.discordapp.net/', 'mp:')
585
+ .replace('http://media.discordapp.net/', 'mp:');
586
+ //
587
+ if (!image.startsWith('mp:')) {
588
+ throw new Error('INVALID_URL');
589
+ }
590
+ } else if (/^[0-9]{17,19}$/.test(image)) {
591
+ // ID Assets
592
+ } else if (['mp:', 'youtube:', 'spotify:', 'twitch:'].some(v => image.startsWith(v))) {
593
+ // Image
594
+ } else if (image.startsWith('external/')) {
595
+ image = `mp:${image}`;
596
+ }
597
+ return image;
598
+ }
599
+
600
+ toJSON() {
601
+ if (!this.largeImage && !this.largeText && !this.smallImage && !this.smallText) return null;
602
+ return {
603
+ large_image: RichPresenceAssets.parseImage(this.largeImage),
604
+ large_text: this.largeText,
605
+ small_image: RichPresenceAssets.parseImage(this.smallImage),
606
+ small_text: this.smallText,
607
+ };
608
+ }
609
+
610
+ /**
611
+ * @typedef {string} RichPresenceImage
612
+ * Support:
613
+ * - cdn.discordapp.com
614
+ * - media.discordapp.net
615
+ * - Assets ID (https://discord.com/api/v9/oauth2/applications/{application_id}/assets)
616
+ * - Media Proxy (mp:external/{hash})
617
+ * - Twitch (twitch:{username})
618
+ * - YouTube (youtube:{video_id})
619
+ * - Spotify (spotify:{image_id})
620
+ */
621
+
622
+ /**
623
+ * Set the large image of this activity
624
+ * @param {?RichPresenceImage} image The large image asset's id
625
+ * @returns {RichPresenceAssets}
626
+ */
627
+ setLargeImage(image) {
628
+ image = RichPresenceAssets.parseImage(image);
629
+ this.largeImage = image;
630
+ return this;
631
+ }
632
+
633
+ /**
634
+ * Set the small image of this activity
635
+ * @param {?RichPresenceImage} image The small image asset's id
636
+ * @returns {RichPresenceAssets}
637
+ */
638
+ setSmallImage(image) {
639
+ image = RichPresenceAssets.parseImage(image);
640
+ this.smallImage = image;
641
+ return this;
642
+ }
643
+
644
+ /**
645
+ * Hover text for the large image
646
+ * @param {string} text Assets text
647
+ * @returns {RichPresenceAssets}
648
+ */
649
+ setLargeText(text) {
650
+ this.largeText = text;
651
+ return this;
652
+ }
653
+
654
+ /**
655
+ * Hover text for the small image
656
+ * @param {string} text Assets text
657
+ * @returns {RichPresenceAssets}
658
+ */
659
+ setSmallText(text) {
660
+ this.smallText = text;
661
+ return this;
662
+ }
663
+ }
664
+
665
+ class CustomStatus extends Activity {
666
+ /**
667
+ * @typedef {Object} CustomStatusOptions
668
+ * @property {string} [state] The state to be displayed
669
+ * @property {EmojiIdentifierResolvable} [emoji] The emoji to be displayed
670
+ */
671
+
672
+ /**
673
+ * @param {Client} client Discord Client
674
+ * @param {CustomStatus|CustomStatusOptions} [data={}] CustomStatus to clone or raw data
675
+ */
676
+ constructor(client, data = {}) {
677
+ if (!client) throw new Error("Class constructor CustomStatus cannot be invoked without 'client'");
678
+ super('presence' in client ? client.presence : client, {
679
+ name: ' ',
680
+ type: ActivityTypes.CUSTOM,
681
+ ...data,
682
+ });
683
+ }
684
+
685
+ /**
686
+ * Set the emoji of this activity
687
+ * @param {EmojiIdentifierResolvable} emoji The emoji to be displayed
688
+ * @returns {CustomStatus}
689
+ */
690
+ setEmoji(emoji) {
691
+ this.emoji = Util.resolvePartialEmoji(emoji);
692
+ return this;
693
+ }
694
+
695
+ /**
696
+ * Set state of this activity
697
+ * @param {string | null} state The state to be displayed
698
+ * @returns {CustomStatus}
699
+ */
700
+ setState(state) {
701
+ if (typeof state == 'string' && state.length > 128) throw new Error('State must be less than 128 characters');
702
+ this.state = state;
703
+ return this;
704
+ }
705
+
706
+ /**
707
+ * Returns an object that can be used to set the status
708
+ * @returns {CustomStatus}
709
+ */
710
+ toJSON() {
711
+ if (!this.emoji & !this.state) throw new Error('CustomStatus must have at least one of emoji or state');
712
+ return {
713
+ name: this.name,
714
+ emoji: this.emoji,
715
+ type: ActivityTypes.CUSTOM,
716
+ state: this.state,
717
+ };
718
+ }
719
+ }
720
+
721
+ class RichPresence extends Activity {
722
+ /**
723
+ * @param {Client} client Discord client
724
+ * @param {RichPresence} [data={}] RichPresence to clone or raw data
725
+ */
726
+ constructor(client, data = {}) {
727
+ if (!client) throw new Error("Class constructor RichPresence cannot be invoked without 'client'");
728
+ super('presence' in client ? client.presence : client, { type: 0, ...data });
729
+ this.setup(data);
730
+ }
731
+
732
+ /**
733
+ * Sets the status from a JSON object
734
+ * @param {RichPresence} data data
735
+ * @private
736
+ */
737
+ setup(data = {}) {
738
+ this.secrets = 'secrets' in data ? data.secrets : {};
739
+ this.metadata = 'metadata' in data ? data.metadata : {};
740
+ }
741
+
742
+ /**
743
+ * Set the large image of this activity
744
+ * @param {?RichPresenceImage} image The large image asset's id
745
+ * @returns {RichPresence}
746
+ */
747
+ setAssetsLargeImage(image) {
748
+ this.assets.setLargeImage(image);
749
+ return this;
750
+ }
751
+
752
+ /**
753
+ * Set the small image of this activity
754
+ * @param {?RichPresenceImage} image The small image asset's id
755
+ * @returns {RichPresence}
756
+ */
757
+ setAssetsSmallImage(image) {
758
+ this.assets.setSmallImage(image);
759
+ return this;
760
+ }
761
+
762
+ /**
763
+ * Hover text for the large image
764
+ * @param {string} text Assets text
765
+ * @returns {RichPresence}
766
+ */
767
+ setAssetsLargeText(text) {
768
+ this.assets.setLargeText(text);
769
+ return this;
770
+ }
771
+
772
+ /**
773
+ * Hover text for the small image
774
+ * @param {string} text Assets text
775
+ * @returns {RichPresence}
776
+ */
777
+ setAssetsSmallText(text) {
778
+ this.assets.setSmallText(text);
779
+ return this;
780
+ }
781
+
782
+ /**
783
+ * Set the name of the activity
784
+ * @param {?string} name The activity's name
785
+ * @returns {RichPresence}
786
+ */
787
+ setName(name) {
788
+ this.name = name;
789
+ return this;
790
+ }
791
+
792
+ /**
793
+ * If the activity is being streamed, a link to the stream
794
+ * @param {?string} url URL of the stream
795
+ * @returns {RichPresence}
796
+ */
797
+ setURL(url) {
798
+ if (typeof url == 'string' && !URL.canParse(url)) throw new Error('URL must be a valid URL');
799
+ this.url = url;
800
+ return this;
801
+ }
802
+
803
+ /**
804
+ * The activity status's type
805
+ * @param {?ActivityTypes} type The type of activity
806
+ * @returns {RichPresence}
807
+ */
808
+ setType(type) {
809
+ this.type = typeof type == 'number' ? type : ActivityTypes[type];
810
+ return this;
811
+ }
812
+
813
+ /**
814
+ * Set the application id of this activity
815
+ * @param {?Snowflake} id Bot's id
816
+ * @returns {RichPresence}
817
+ */
818
+ setApplicationId(id) {
819
+ this.applicationId = id;
820
+ return this;
821
+ }
822
+
823
+ /**
824
+ * Set the state of the activity
825
+ * @param {?string} state The state of the activity
826
+ * @returns {RichPresence}
827
+ */
828
+ setState(state) {
829
+ this.state = state;
830
+ return this;
831
+ }
832
+
833
+ /**
834
+ * Set the URL of the state of the activity
835
+ * @param {?string} url The url of the state
836
+ * @returns {RichPresence}
837
+ */
838
+ setStateURL(url) {
839
+ if (!url) throw new Error('Detail URL must be a url');
840
+
841
+ if (typeof url !== 'string') throw new Error('Detail URL must be a url');
842
+ if (!URL.canParse(url)) throw new Error('Detail URL must be a valid url');
843
+
844
+ this.state_url = url;
845
+ return this;
846
+ }
847
+
848
+ /**
849
+ * Set the details of the activity
850
+ * @param {?string} details The details of the activity
851
+ * @returns {RichPresence}
852
+ */
853
+ setDetails(details) {
854
+ this.details = details;
855
+ return this;
856
+ }
857
+
858
+ /**
859
+ * Set the URL of the details of the activity
860
+ * @param {?string} url The url of the details
861
+ * @returns {RichPresence}
862
+ */
863
+ setDetailsURL(url) {
864
+ if (!url) throw new Error('Detail URL must be a url');
865
+
866
+ if (typeof url !== 'string') throw new Error('Detail URL must be a url');
867
+ if (!URL.canParse(url)) throw new Error('Detail URL must be a valid url');
868
+
869
+ this.details_url = url;
870
+ return this;
871
+ }
872
+
873
+ /**
874
+ * @typedef {Object} RichParty
875
+ * @property {string} id The id of the party
876
+ * @property {number} max The maximum number of members in the party
877
+ * @property {number} current The current number of members in the party
878
+ */
879
+
880
+ /**
881
+ * Set the party of this activity
882
+ * @param {?RichParty} party The party to be displayed
883
+ * @returns {RichPresence}
884
+ */
885
+ setParty(party) {
886
+ if (typeof party == 'object') {
887
+ if (!party.max || typeof party.max != 'number') throw new Error('Party must have max number');
888
+ if (!party.current || typeof party.current != 'number') throw new Error('Party must have current');
889
+ if (party.current > party.max) throw new Error('Party current must be less than max number');
890
+ if (!party.id || typeof party.id != 'string') party.id = randomUUID();
891
+ this.party = {
892
+ size: [party.current, party.max],
893
+ id: party.id,
894
+ };
895
+ } else {
896
+ this.party = null;
897
+ }
898
+ return this;
899
+ }
900
+
901
+ /**
902
+ * Sets the start timestamp of the activity
903
+ * @param {Date|number|null} timestamp The timestamp of the start of the activity
904
+ * @returns {RichPresence}
905
+ */
906
+ setStartTimestamp(timestamp) {
907
+ if (!this.timestamps) this.timestamps = {};
908
+ if (timestamp instanceof Date) timestamp = timestamp.getTime();
909
+ this.timestamps.start = timestamp;
910
+ return this;
911
+ }
912
+
913
+ /**
914
+ * Sets the end timestamp of the activity
915
+ * @param {Date|number|null} timestamp The timestamp of the end of the activity
916
+ * @returns {RichPresence}
917
+ */
918
+ setEndTimestamp(timestamp) {
919
+ if (!this.timestamps) this.timestamps = {};
920
+ if (timestamp instanceof Date) timestamp = timestamp.getTime();
921
+ this.timestamps.end = timestamp;
922
+ return this;
923
+ }
924
+
925
+ /**
926
+ * @typedef {object} RichButton
927
+ * @property {string} name The name of the button
928
+ * @property {string} url The url of the button
929
+ */
930
+ /**
931
+ * Set the buttons of the rich presence
932
+ * @param {...?RichButton} button A list of buttons to set
933
+ * @returns {RichPresence}
934
+ */
935
+ setButtons(...button) {
936
+ if (button.length == 0) {
937
+ this.buttons = [];
938
+ delete this.metadata.button_urls;
939
+ return this;
940
+ } else if (button.length > 2) {
941
+ throw new Error('RichPresence can only have up to 2 buttons');
942
+ }
943
+
944
+ this.buttons = [];
945
+ this.metadata.button_urls = [];
946
+
947
+ button.flat(2).forEach(b => {
948
+ if (b.name && b.url) {
949
+ this.buttons.push(b.name);
950
+ if (!URL.canParse(b.url)) throw new Error('Button url must be a valid url');
951
+ this.metadata.button_urls.push(b.url);
952
+ } else {
953
+ throw new Error('Button must have name and url');
954
+ }
955
+ });
956
+ return this;
957
+ }
958
+
959
+ /**
960
+ * The platform the activity is being played on
961
+ * @param {ActivityPlatform | null} platform Any platform
962
+ * @returns {RichPresence}
963
+ */
964
+ setPlatform(platform) {
965
+ this.platform = platform;
966
+ return this;
967
+ }
968
+
969
+ /**
970
+ * Secrets for rich presence joining and spectating (send-only)
971
+ * @param {?string} join Secrets for rich presence joining
972
+ * @returns {RichPresence}
973
+ */
974
+ setJoinSecret(join) {
975
+ this.secrets.join = join;
976
+ return this;
977
+ }
978
+
979
+ /**
980
+ * Add a button to the rich presence
981
+ * @param {string} name The name of the button
982
+ * @param {string} url The url of the button
983
+ * @returns {RichPresence}
984
+ */
985
+ addButton(name, url) {
986
+ if (!name || !url) {
987
+ throw new Error('Button must have name and url');
988
+ }
989
+ if (typeof name !== 'string') throw new Error('Button name must be a string');
990
+ if (!URL.canParse(url)) throw new Error('Button url must be a valid url');
991
+ this.buttons.push(name);
992
+ if (Array.isArray(this.metadata.button_urls)) this.metadata.button_urls.push(url);
993
+ else this.metadata.button_urls = [url];
994
+ return this;
995
+ }
996
+
997
+ /**
998
+ * Convert the rich presence to a JSON object
999
+ * @returns {Object}
1000
+ */
1001
+ toJSON(...props) {
1002
+ return super.toJSON(
1003
+ {
1004
+ applicationId: 'application_id',
1005
+ sessionId: 'session_id',
1006
+ syncId: 'sync_id',
1007
+ createdTimestamp: 'created_at',
1008
+ },
1009
+ ...props,
1010
+ );
1011
+ }
1012
+
1013
+ /**
1014
+ * @typedef {Object} ExternalAssets
1015
+ * @property {?string} url Orginal url of the image
1016
+ * @property {?string} external_asset_path Proxy url of the image (Using to RPC)
1017
+ */
1018
+
1019
+ /**
1020
+ * Retrieves external assets from a RichPresence
1021
+ * @param {Client} client - The Discord client instance.
1022
+ * @param {Snowflake} applicationId - The application ID associated with the Rich Presence.
1023
+ * @param {...string} images - 1 or 2 external image URLs (not hosted by Discord).
1024
+ * @returns {Promise<ExternalAssets[]>}
1025
+ */
1026
+ static async getExternal(client, applicationId, ...images) {
1027
+ if (!client || !client.token || !client.api) throw new Error('Client must be set');
1028
+ // Check if applicationId is discord snowflake (17 , 18, 19 numbers)
1029
+ if (!/^[0-9]{17,19}$/.test(applicationId)) {
1030
+ throw new Error('Application id must be a Discord Snowflake');
1031
+ }
1032
+ // Check if images are 1 or 2
1033
+ if (images.length > 2) {
1034
+ throw new Error('RichPresence can only have up to 2 external images');
1035
+ }
1036
+ // Check if all images are valid URLs
1037
+ if (images.some(image => !URL.canParse(image))) {
1038
+ throw new Error('Each image must be a valid URL.');
1039
+ }
1040
+ const res = await client.api.applications[applicationId]['external-assets'].post({
1041
+ data: {
1042
+ urls: images,
1043
+ },
1044
+ });
1045
+ return res;
1046
+ }
1047
+
1048
+ /**
1049
+ * When concatenated with a string, this automatically returns the activities' name instead of the Activity object.
1050
+ * @returns {string}
1051
+ */
1052
+ toString() {
1053
+ return this.name;
1054
+ }
1055
+
1056
+ _clone() {
1057
+ return Object.assign(Object.create(this), this);
1058
+ }
1059
+ }
1060
+
1061
+ /**
1062
+ * @extends {RichPresence}
1063
+ */
1064
+ class SpotifyRPC extends RichPresence {
1065
+ /**
1066
+ * Create a new RichPresence (Spotify style)
1067
+ * @param {Client} client Discord Client
1068
+ * @param {SpotifyRPC} [options] Options for the Spotify RPC
1069
+ */
1070
+ constructor(client, options = {}) {
1071
+ if (!client) throw new Error("Class constructor SpotifyRPC cannot be invoked without 'client'");
1072
+ super(client, {
1073
+ name: 'Spotify',
1074
+ type: ActivityTypes.LISTENING,
1075
+ party: {
1076
+ id: `spotify:${client.user.id}`,
1077
+ },
1078
+ id: 'spotify:1',
1079
+ flags: 48, // Sync + Play (ActivityFlags)
1080
+ ...options,
1081
+ });
1082
+ this.setup(options);
1083
+ }
1084
+ /**
1085
+ * Sets the status from a JSON object
1086
+ * @param {SpotifyRPC} options data
1087
+ * @private
1088
+ */
1089
+ setup(options) {
1090
+ /**
1091
+ * @typedef {Object} SpotifyMetadata
1092
+ * @property {string} album_id The Spotify ID of the album of the song being played
1093
+ * @property {Array<string>} artist_ids The Spotify IDs of the artists of the song being played
1094
+ * @property {string} context_uri The Spotify URI of the current player context
1095
+ */
1096
+
1097
+ /**
1098
+ * Spotify metadata
1099
+ * @type {SpotifyMetadata}
1100
+ */
1101
+ this.metadata = {
1102
+ album_id: options.metadata?.album_id || null,
1103
+ artist_ids: options.metadata?.artist_ids || [],
1104
+ context_uri: options.metadata?.context_uri || null,
1105
+ };
1106
+ }
1107
+
1108
+ /**
1109
+ * Set Spotify song id to sync with
1110
+ * @param {string} id Song id
1111
+ * @returns {SpotifyRPC}
1112
+ */
1113
+ setSongId(id) {
1114
+ this.syncId = id;
1115
+ return this;
1116
+ }
1117
+
1118
+ /**
1119
+ * Add the artist id
1120
+ * @param {string} id Artist id
1121
+ * @returns {SpotifyRPC}
1122
+ */
1123
+ addArtistId(id) {
1124
+ if (!this.metadata.artist_ids) this.metadata.artist_ids = [];
1125
+ this.metadata.artist_ids.push(id);
1126
+ return this;
1127
+ }
1128
+
1129
+ /**
1130
+ * Set the artist ids
1131
+ * @param {string | Array<string>} ids Artist ids
1132
+ * @returns {SpotifyRPC}
1133
+ */
1134
+ setArtistIds(...ids) {
1135
+ if (!ids?.length) {
1136
+ this.metadata.artist_ids = [];
1137
+ return this;
1138
+ }
1139
+ if (!this.metadata.artist_ids) this.metadata.artist_ids = [];
1140
+ ids.flat(2).forEach(id => this.metadata.artist_ids.push(id));
1141
+ return this;
1142
+ }
1143
+
1144
+ /**
1145
+ * Set the album id
1146
+ * @param {string} id Album id
1147
+ * @returns {SpotifyRPC}
1148
+ */
1149
+ setAlbumId(id) {
1150
+ this.metadata.album_id = id;
1151
+ this.metadata.context_uri = `spotify:album:${id}`;
1152
+ return this;
1153
+ }
1154
+
1155
+ toJSON() {
1156
+ return super.toJSON({ id: false, emoji: false, platform: false, buttons: false });
1157
+ }
1158
+ }
1159
+
1160
+ exports.Presence = Presence;
1161
+ exports.Activity = Activity;
1162
+ exports.RichPresenceAssets = RichPresenceAssets;
1163
+ exports.CustomStatus = CustomStatus;
1164
+ exports.RichPresence = RichPresence;
1165
+ exports.SpotifyRPC = SpotifyRPC;