discord.js-selfbot-v13-new 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (364) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +124 -0
  3. package/package.json +89 -0
  4. package/src/WebSocket.js +39 -0
  5. package/src/client/BaseClient.js +86 -0
  6. package/src/client/Client.js +934 -0
  7. package/src/client/WebhookClient.js +61 -0
  8. package/src/client/actions/Action.js +116 -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 +32 -0
  48. package/src/client/actions/MessageDeleteBulk.js +46 -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 +68 -0
  52. package/src/client/actions/MessageReactionRemove.js +50 -0
  53. package/src/client/actions/MessageReactionRemoveAll.js +33 -0
  54. package/src/client/actions/MessageReactionRemoveEmoji.js +28 -0
  55. package/src/client/actions/MessageUpdate.js +26 -0
  56. package/src/client/actions/PresenceUpdate.js +50 -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 +59 -0
  63. package/src/client/actions/ThreadMemberUpdate.js +30 -0
  64. package/src/client/actions/ThreadMembersUpdate.js +34 -0
  65. package/src/client/actions/TypingStart.js +29 -0
  66. package/src/client/actions/UserUpdate.js +35 -0
  67. package/src/client/actions/VoiceStateUpdate.js +50 -0
  68. package/src/client/actions/WebhooksUpdate.js +20 -0
  69. package/src/client/voice/ClientVoiceManager.js +151 -0
  70. package/src/client/voice/VoiceConnection.js +1249 -0
  71. package/src/client/voice/dispatcher/AnnexBDispatcher.js +120 -0
  72. package/src/client/voice/dispatcher/AudioDispatcher.js +145 -0
  73. package/src/client/voice/dispatcher/BaseDispatcher.js +459 -0
  74. package/src/client/voice/dispatcher/VPxDispatcher.js +54 -0
  75. package/src/client/voice/dispatcher/VideoDispatcher.js +68 -0
  76. package/src/client/voice/networking/VoiceUDPClient.js +173 -0
  77. package/src/client/voice/networking/VoiceWebSocket.js +286 -0
  78. package/src/client/voice/player/MediaPlayer.js +321 -0
  79. package/src/client/voice/player/processing/AnnexBNalSplitter.js +244 -0
  80. package/src/client/voice/player/processing/IvfSplitter.js +106 -0
  81. package/src/client/voice/player/processing/PCMInsertSilence.js +37 -0
  82. package/src/client/voice/receiver/PacketHandler.js +260 -0
  83. package/src/client/voice/receiver/Receiver.js +96 -0
  84. package/src/client/voice/receiver/Recorder.js +173 -0
  85. package/src/client/voice/util/Function.js +116 -0
  86. package/src/client/voice/util/PlayInterface.js +122 -0
  87. package/src/client/voice/util/Secretbox.js +64 -0
  88. package/src/client/voice/util/Silence.js +16 -0
  89. package/src/client/voice/util/Socket.js +62 -0
  90. package/src/client/voice/util/VolumeInterface.js +104 -0
  91. package/src/client/websocket/WebSocketManager.js +392 -0
  92. package/src/client/websocket/WebSocketShard.js +907 -0
  93. package/src/client/websocket/handlers/APPLICATION_COMMAND_CREATE.js +18 -0
  94. package/src/client/websocket/handlers/APPLICATION_COMMAND_DELETE.js +20 -0
  95. package/src/client/websocket/handlers/APPLICATION_COMMAND_PERMISSIONS_UPDATE.js +5 -0
  96. package/src/client/websocket/handlers/APPLICATION_COMMAND_UPDATE.js +20 -0
  97. package/src/client/websocket/handlers/AUTO_MODERATION_ACTION_EXECUTION.js +5 -0
  98. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_CREATE.js +5 -0
  99. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_DELETE.js +5 -0
  100. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_UPDATE.js +5 -0
  101. package/src/client/websocket/handlers/CALL_CREATE.js +14 -0
  102. package/src/client/websocket/handlers/CALL_DELETE.js +11 -0
  103. package/src/client/websocket/handlers/CALL_UPDATE.js +11 -0
  104. package/src/client/websocket/handlers/CHANNEL_CREATE.js +5 -0
  105. package/src/client/websocket/handlers/CHANNEL_DELETE.js +5 -0
  106. package/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.js +22 -0
  107. package/src/client/websocket/handlers/CHANNEL_RECIPIENT_ADD.js +19 -0
  108. package/src/client/websocket/handlers/CHANNEL_RECIPIENT_REMOVE.js +16 -0
  109. package/src/client/websocket/handlers/CHANNEL_UPDATE.js +16 -0
  110. package/src/client/websocket/handlers/GUILD_AUDIT_LOG_ENTRY_CREATE.js +5 -0
  111. package/src/client/websocket/handlers/GUILD_BAN_ADD.js +5 -0
  112. package/src/client/websocket/handlers/GUILD_BAN_REMOVE.js +5 -0
  113. package/src/client/websocket/handlers/GUILD_CREATE.js +52 -0
  114. package/src/client/websocket/handlers/GUILD_DELETE.js +5 -0
  115. package/src/client/websocket/handlers/GUILD_EMOJIS_UPDATE.js +5 -0
  116. package/src/client/websocket/handlers/GUILD_INTEGRATIONS_UPDATE.js +5 -0
  117. package/src/client/websocket/handlers/GUILD_MEMBERS_CHUNK.js +39 -0
  118. package/src/client/websocket/handlers/GUILD_MEMBER_ADD.js +20 -0
  119. package/src/client/websocket/handlers/GUILD_MEMBER_REMOVE.js +5 -0
  120. package/src/client/websocket/handlers/GUILD_MEMBER_UPDATE.js +5 -0
  121. package/src/client/websocket/handlers/GUILD_ROLE_CREATE.js +5 -0
  122. package/src/client/websocket/handlers/GUILD_ROLE_DELETE.js +5 -0
  123. package/src/client/websocket/handlers/GUILD_ROLE_UPDATE.js +5 -0
  124. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_CREATE.js +5 -0
  125. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_DELETE.js +5 -0
  126. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_UPDATE.js +5 -0
  127. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_ADD.js +5 -0
  128. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_REMOVE.js +5 -0
  129. package/src/client/websocket/handlers/GUILD_STICKERS_UPDATE.js +5 -0
  130. package/src/client/websocket/handlers/GUILD_UPDATE.js +5 -0
  131. package/src/client/websocket/handlers/INTERACTION_MODAL_CREATE.js +12 -0
  132. package/src/client/websocket/handlers/INVITE_CREATE.js +5 -0
  133. package/src/client/websocket/handlers/INVITE_DELETE.js +5 -0
  134. package/src/client/websocket/handlers/MESSAGE_CREATE.js +5 -0
  135. package/src/client/websocket/handlers/MESSAGE_DELETE.js +5 -0
  136. package/src/client/websocket/handlers/MESSAGE_DELETE_BULK.js +5 -0
  137. package/src/client/websocket/handlers/MESSAGE_POLL_VOTE_ADD.js +5 -0
  138. package/src/client/websocket/handlers/MESSAGE_POLL_VOTE_REMOVE.js +5 -0
  139. package/src/client/websocket/handlers/MESSAGE_REACTION_ADD.js +5 -0
  140. package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE.js +5 -0
  141. package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_ALL.js +5 -0
  142. package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_EMOJI.js +5 -0
  143. package/src/client/websocket/handlers/MESSAGE_UPDATE.js +16 -0
  144. package/src/client/websocket/handlers/PRESENCE_UPDATE.js +5 -0
  145. package/src/client/websocket/handlers/READY.js +121 -0
  146. package/src/client/websocket/handlers/RELATIONSHIP_ADD.js +19 -0
  147. package/src/client/websocket/handlers/RELATIONSHIP_REMOVE.js +17 -0
  148. package/src/client/websocket/handlers/RELATIONSHIP_UPDATE.js +41 -0
  149. package/src/client/websocket/handlers/RESUMED.js +14 -0
  150. package/src/client/websocket/handlers/STAGE_INSTANCE_CREATE.js +5 -0
  151. package/src/client/websocket/handlers/STAGE_INSTANCE_DELETE.js +5 -0
  152. package/src/client/websocket/handlers/STAGE_INSTANCE_UPDATE.js +5 -0
  153. package/src/client/websocket/handlers/THREAD_CREATE.js +5 -0
  154. package/src/client/websocket/handlers/THREAD_DELETE.js +5 -0
  155. package/src/client/websocket/handlers/THREAD_LIST_SYNC.js +5 -0
  156. package/src/client/websocket/handlers/THREAD_MEMBERS_UPDATE.js +5 -0
  157. package/src/client/websocket/handlers/THREAD_MEMBER_UPDATE.js +5 -0
  158. package/src/client/websocket/handlers/THREAD_UPDATE.js +16 -0
  159. package/src/client/websocket/handlers/TYPING_START.js +5 -0
  160. package/src/client/websocket/handlers/USER_GUILD_SETTINGS_UPDATE.js +6 -0
  161. package/src/client/websocket/handlers/USER_NOTE_UPDATE.js +5 -0
  162. package/src/client/websocket/handlers/USER_REQUIRED_ACTION_UPDATE.js +78 -0
  163. package/src/client/websocket/handlers/USER_SETTINGS_UPDATE.js +5 -0
  164. package/src/client/websocket/handlers/USER_UPDATE.js +5 -0
  165. package/src/client/websocket/handlers/VOICE_CHANNEL_EFFECT_SEND.js +16 -0
  166. package/src/client/websocket/handlers/VOICE_CHANNEL_STATUS_UPDATE.js +12 -0
  167. package/src/client/websocket/handlers/VOICE_SERVER_UPDATE.js +6 -0
  168. package/src/client/websocket/handlers/VOICE_STATE_UPDATE.js +5 -0
  169. package/src/client/websocket/handlers/WEBHOOKS_UPDATE.js +5 -0
  170. package/src/client/websocket/handlers/index.js +84 -0
  171. package/src/errors/DJSError.js +61 -0
  172. package/src/errors/Messages.js +217 -0
  173. package/src/errors/index.js +4 -0
  174. package/src/index.js +172 -0
  175. package/src/managers/ApplicationCommandManager.js +264 -0
  176. package/src/managers/ApplicationCommandPermissionsManager.js +417 -0
  177. package/src/managers/AutoModerationRuleManager.js +296 -0
  178. package/src/managers/BaseGuildEmojiManager.js +80 -0
  179. package/src/managers/BaseManager.js +19 -0
  180. package/src/managers/BillingManager.js +66 -0
  181. package/src/managers/CachedManager.js +71 -0
  182. package/src/managers/ChannelManager.js +148 -0
  183. package/src/managers/ClientUserSettingManager.js +372 -0
  184. package/src/managers/DataManager.js +61 -0
  185. package/src/managers/GuildBanManager.js +250 -0
  186. package/src/managers/GuildChannelManager.js +488 -0
  187. package/src/managers/GuildEmojiManager.js +171 -0
  188. package/src/managers/GuildEmojiRoleManager.js +118 -0
  189. package/src/managers/GuildForumThreadManager.js +108 -0
  190. package/src/managers/GuildInviteManager.js +213 -0
  191. package/src/managers/GuildManager.js +338 -0
  192. package/src/managers/GuildMemberManager.js +599 -0
  193. package/src/managers/GuildMemberRoleManager.js +195 -0
  194. package/src/managers/GuildScheduledEventManager.js +314 -0
  195. package/src/managers/GuildSettingManager.js +155 -0
  196. package/src/managers/GuildStickerManager.js +179 -0
  197. package/src/managers/GuildTextThreadManager.js +98 -0
  198. package/src/managers/InteractionManager.js +39 -0
  199. package/src/managers/MessageManager.js +423 -0
  200. package/src/managers/PermissionOverwriteManager.js +164 -0
  201. package/src/managers/PresenceManager.js +71 -0
  202. package/src/managers/ReactionManager.js +67 -0
  203. package/src/managers/ReactionUserManager.js +73 -0
  204. package/src/managers/RelationshipManager.js +278 -0
  205. package/src/managers/RoleManager.js +448 -0
  206. package/src/managers/SessionManager.js +66 -0
  207. package/src/managers/StageInstanceManager.js +162 -0
  208. package/src/managers/ThreadManager.js +175 -0
  209. package/src/managers/ThreadMemberManager.js +186 -0
  210. package/src/managers/UserManager.js +136 -0
  211. package/src/managers/UserNoteManager.js +53 -0
  212. package/src/managers/VoiceStateManager.js +59 -0
  213. package/src/rest/APIRequest.js +154 -0
  214. package/src/rest/APIRouter.js +53 -0
  215. package/src/rest/DiscordAPIError.js +119 -0
  216. package/src/rest/HTTPError.js +62 -0
  217. package/src/rest/RESTManager.js +67 -0
  218. package/src/rest/RateLimitError.js +55 -0
  219. package/src/rest/RequestHandler.js +466 -0
  220. package/src/sharding/Shard.js +444 -0
  221. package/src/sharding/ShardClientUtil.js +279 -0
  222. package/src/sharding/ShardingManager.js +319 -0
  223. package/src/structures/AnonymousGuild.js +98 -0
  224. package/src/structures/ApplicationCommand.js +593 -0
  225. package/src/structures/ApplicationRoleConnectionMetadata.js +48 -0
  226. package/src/structures/AutoModerationActionExecution.js +89 -0
  227. package/src/structures/AutoModerationRule.js +294 -0
  228. package/src/structures/AutocompleteInteraction.js +107 -0
  229. package/src/structures/Base.js +43 -0
  230. package/src/structures/BaseCommandInteraction.js +211 -0
  231. package/src/structures/BaseGuild.js +116 -0
  232. package/src/structures/BaseGuildEmoji.js +56 -0
  233. package/src/structures/BaseGuildTextChannel.js +191 -0
  234. package/src/structures/BaseGuildVoiceChannel.js +241 -0
  235. package/src/structures/BaseMessageComponent.js +181 -0
  236. package/src/structures/ButtonInteraction.js +11 -0
  237. package/src/structures/CallState.js +63 -0
  238. package/src/structures/CategoryChannel.js +85 -0
  239. package/src/structures/Channel.js +284 -0
  240. package/src/structures/ClientPresence.js +77 -0
  241. package/src/structures/ClientUser.js +449 -0
  242. package/src/structures/CommandInteraction.js +41 -0
  243. package/src/structures/CommandInteractionOptionResolver.js +276 -0
  244. package/src/structures/ContainerComponent.js +68 -0
  245. package/src/structures/ContextMenuInteraction.js +65 -0
  246. package/src/structures/DMChannel.js +219 -0
  247. package/src/structures/DirectoryChannel.js +20 -0
  248. package/src/structures/Emoji.js +148 -0
  249. package/src/structures/FileComponent.js +49 -0
  250. package/src/structures/ForumChannel.js +31 -0
  251. package/src/structures/GroupDMChannel.js +394 -0
  252. package/src/structures/Guild.js +1638 -0
  253. package/src/structures/GuildAuditLogs.js +746 -0
  254. package/src/structures/GuildBan.js +59 -0
  255. package/src/structures/GuildBoost.js +108 -0
  256. package/src/structures/GuildChannel.js +470 -0
  257. package/src/structures/GuildEmoji.js +161 -0
  258. package/src/structures/GuildMember.js +636 -0
  259. package/src/structures/GuildPreview.js +191 -0
  260. package/src/structures/GuildPreviewEmoji.js +27 -0
  261. package/src/structures/GuildScheduledEvent.js +536 -0
  262. package/src/structures/GuildTemplate.js +236 -0
  263. package/src/structures/Integration.js +188 -0
  264. package/src/structures/IntegrationApplication.js +96 -0
  265. package/src/structures/Interaction.js +290 -0
  266. package/src/structures/InteractionCollector.js +248 -0
  267. package/src/structures/InteractionWebhook.js +43 -0
  268. package/src/structures/Invite.js +358 -0
  269. package/src/structures/InviteGuild.js +23 -0
  270. package/src/structures/InviteStageInstance.js +86 -0
  271. package/src/structures/MediaChannel.js +11 -0
  272. package/src/structures/MediaGalleryComponent.js +41 -0
  273. package/src/structures/MediaGalleryItem.js +47 -0
  274. package/src/structures/Message.js +1252 -0
  275. package/src/structures/MessageActionRow.js +105 -0
  276. package/src/structures/MessageAttachment.js +216 -0
  277. package/src/structures/MessageButton.js +166 -0
  278. package/src/structures/MessageCollector.js +146 -0
  279. package/src/structures/MessageComponentInteraction.js +120 -0
  280. package/src/structures/MessageContextMenuInteraction.js +20 -0
  281. package/src/structures/MessageEmbed.js +596 -0
  282. package/src/structures/MessageMentions.js +273 -0
  283. package/src/structures/MessagePayload.js +354 -0
  284. package/src/structures/MessageReaction.js +181 -0
  285. package/src/structures/MessageSelectMenu.js +141 -0
  286. package/src/structures/Modal.js +161 -0
  287. package/src/structures/ModalSubmitFieldsResolver.js +53 -0
  288. package/src/structures/ModalSubmitInteraction.js +119 -0
  289. package/src/structures/NewsChannel.js +32 -0
  290. package/src/structures/OAuth2Guild.js +28 -0
  291. package/src/structures/PermissionOverwrites.js +198 -0
  292. package/src/structures/Poll.js +108 -0
  293. package/src/structures/PollAnswer.js +88 -0
  294. package/src/structures/Presence.js +1105 -0
  295. package/src/structures/ReactionCollector.js +229 -0
  296. package/src/structures/ReactionEmoji.js +31 -0
  297. package/src/structures/Role.js +590 -0
  298. package/src/structures/SectionComponent.js +48 -0
  299. package/src/structures/SelectMenuInteraction.js +21 -0
  300. package/src/structures/SeparatorComponent.js +48 -0
  301. package/src/structures/Session.js +81 -0
  302. package/src/structures/StageChannel.js +104 -0
  303. package/src/structures/StageInstance.js +208 -0
  304. package/src/structures/Sticker.js +310 -0
  305. package/src/structures/StickerPack.js +95 -0
  306. package/src/structures/StoreChannel.js +56 -0
  307. package/src/structures/Team.js +118 -0
  308. package/src/structures/TeamMember.js +80 -0
  309. package/src/structures/TextChannel.js +33 -0
  310. package/src/structures/TextDisplayComponent.js +40 -0
  311. package/src/structures/TextInputComponent.js +132 -0
  312. package/src/structures/ThreadChannel.js +605 -0
  313. package/src/structures/ThreadMember.js +105 -0
  314. package/src/structures/ThreadOnlyChannel.js +249 -0
  315. package/src/structures/ThumbnailComponent.js +57 -0
  316. package/src/structures/Typing.js +74 -0
  317. package/src/structures/UnfurledMediaItem.js +29 -0
  318. package/src/structures/User.js +622 -0
  319. package/src/structures/UserContextMenuInteraction.js +29 -0
  320. package/src/structures/VoiceChannel.js +110 -0
  321. package/src/structures/VoiceChannelEffect.js +69 -0
  322. package/src/structures/VoiceRegion.js +53 -0
  323. package/src/structures/VoiceState.js +354 -0
  324. package/src/structures/WebEmbed.js +373 -0
  325. package/src/structures/Webhook.js +478 -0
  326. package/src/structures/WelcomeChannel.js +60 -0
  327. package/src/structures/WelcomeScreen.js +48 -0
  328. package/src/structures/Widget.js +87 -0
  329. package/src/structures/WidgetMember.js +99 -0
  330. package/src/structures/interfaces/Application.js +825 -0
  331. package/src/structures/interfaces/Collector.js +300 -0
  332. package/src/structures/interfaces/InteractionResponses.js +313 -0
  333. package/src/structures/interfaces/TextBasedChannel.js +759 -0
  334. package/src/util/APITypes.js +59 -0
  335. package/src/util/ActivityFlags.js +44 -0
  336. package/src/util/ApplicationFlags.js +76 -0
  337. package/src/util/AttachmentFlags.js +38 -0
  338. package/src/util/BitField.js +170 -0
  339. package/src/util/ChannelFlags.js +45 -0
  340. package/src/util/Constants.js +1914 -0
  341. package/src/util/DataResolver.js +146 -0
  342. package/src/util/Formatters.js +228 -0
  343. package/src/util/GuildMemberFlags.js +43 -0
  344. package/src/util/Intents.js +74 -0
  345. package/src/util/InviteFlags.js +34 -0
  346. package/src/util/LimitedCollection.js +131 -0
  347. package/src/util/MessageFlags.js +63 -0
  348. package/src/util/Options.js +358 -0
  349. package/src/util/Permissions.js +202 -0
  350. package/src/util/PremiumUsageFlags.js +31 -0
  351. package/src/util/PurchasedFlags.js +33 -0
  352. package/src/util/RemoteAuth.js +382 -0
  353. package/src/util/RoleFlags.js +37 -0
  354. package/src/util/SnowflakeUtil.js +92 -0
  355. package/src/util/Speaking.js +33 -0
  356. package/src/util/Sweepers.js +466 -0
  357. package/src/util/SystemChannelFlags.js +55 -0
  358. package/src/util/ThreadMemberFlags.js +30 -0
  359. package/src/util/UserFlags.js +104 -0
  360. package/src/util/Util.js +1048 -0
  361. package/typings/enums.d.ts +439 -0
  362. package/typings/index.d.ts +8247 -0
  363. package/typings/index.test-d.ts +0 -0
  364. package/typings/rawDataTypes.d.ts +403 -0
@@ -0,0 +1,1105 @@
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
+ clone.activities = this.activities.map(activity => activity._clone());
146
+ return clone;
147
+ }
148
+
149
+ /**
150
+ * Whether this presence is equal to another.
151
+ * @param {Presence} presence The presence to compare with
152
+ * @returns {boolean}
153
+ */
154
+ equals(presence) {
155
+ return (
156
+ this === presence ||
157
+ (presence &&
158
+ this.status === presence.status &&
159
+ this.clientStatus?.web === presence.clientStatus?.web &&
160
+ this.clientStatus?.mobile === presence.clientStatus?.mobile &&
161
+ this.clientStatus?.desktop === presence.clientStatus?.desktop &&
162
+ this.activities.length === presence.activities.length &&
163
+ this.activities.every((activity, index) => activity.equals(presence.activities[index])))
164
+ );
165
+ }
166
+
167
+ toJSON() {
168
+ return Util.flatten(this);
169
+ }
170
+ }
171
+
172
+ /**
173
+ * The platform of this activity:
174
+ * * **`desktop`**
175
+ * * **`samsung`** - playing on Samsung Galaxy
176
+ * * **`xbox`** - playing on Xbox Live
177
+ * * **`ios`**
178
+ * * **`android`**
179
+ * * **`embedded`**
180
+ * * **`ps4`**
181
+ * * **`ps5`**
182
+ * @typedef {string} ActivityPlatform
183
+ */
184
+
185
+ /**
186
+ * Represents an activity that is part of a user's presence.
187
+ */
188
+ class Activity {
189
+ constructor(presence, data) {
190
+ if (!(presence instanceof Presence)) {
191
+ throw new Error("Class constructor Activity cannot be invoked without 'presence'");
192
+ }
193
+ /**
194
+ * The presence of the Activity
195
+ * @type {Presence}
196
+ * @readonly
197
+ * @name Activity#presence
198
+ */
199
+ Object.defineProperty(this, 'presence', { value: presence });
200
+
201
+ this._patch(data);
202
+ }
203
+
204
+ _patch(data = {}) {
205
+ if ('id' in data) {
206
+ /**
207
+ * The activity's id
208
+ * @type {string}
209
+ */
210
+ this.id = data.id;
211
+ }
212
+
213
+ if ('name' in data) {
214
+ /**
215
+ * The activity's name
216
+ * @type {string}
217
+ */
218
+ this.name = data.name;
219
+ }
220
+
221
+ if ('type' in data) {
222
+ /**
223
+ * The activity status's type
224
+ * @type {ActivityType}
225
+ */
226
+ this.type = typeof data.type === 'number' ? ActivityTypes[data.type] : data.type;
227
+ }
228
+
229
+ if ('url' in data) {
230
+ /**
231
+ * If the activity is being streamed, a link to the stream
232
+ * @type {?string}
233
+ */
234
+ this.url = data.url;
235
+ } else {
236
+ this.url = null;
237
+ }
238
+
239
+ if ('created_at' in data || 'createdTimestamp' in data) {
240
+ /**
241
+ * Creation date of the activity
242
+ * @type {number}
243
+ */
244
+ this.createdTimestamp = data.created_at || data.createdTimestamp;
245
+ }
246
+
247
+ if ('session_id' in data) {
248
+ /**
249
+ * The game's or Spotify session's id
250
+ * @type {?string}
251
+ */
252
+ this.sessionId = data.session_id;
253
+ } else {
254
+ this.sessionId = this.presence.client?.sessionId;
255
+ }
256
+
257
+ if ('platform' in data) {
258
+ /**
259
+ * The platform the game is being played on
260
+ * @type {?ActivityPlatform}
261
+ */
262
+ this.platform = data.platform;
263
+ } else {
264
+ this.platform = null;
265
+ }
266
+
267
+ if ('timestamps' in data && data.timestamps) {
268
+ /**
269
+ * Represents timestamps of an activity
270
+ * @typedef {Object} ActivityTimestamps
271
+ * @property {?number} start When the activity started
272
+ * @property {?number} end When the activity will end
273
+ */
274
+
275
+ /**
276
+ * Timestamps for the activity
277
+ * @type {?ActivityTimestamps}
278
+ */
279
+ this.timestamps = {
280
+ start: data.timestamps.start ? new Date(data.timestamps.start).getTime() : null,
281
+ end: data.timestamps.end ? new Date(data.timestamps.end).getTime() : null,
282
+ };
283
+ } else {
284
+ this.timestamps = null;
285
+ }
286
+
287
+ if ('application_id' in data || 'applicationId' in data) {
288
+ /**
289
+ * The id of the application associated with this activity
290
+ * @type {?Snowflake}
291
+ */
292
+ this.applicationId = data.application_id || data.applicationId;
293
+ } else {
294
+ this.applicationId = null;
295
+ }
296
+
297
+ if ('details' in data) {
298
+ /**
299
+ * Details about the activity
300
+ * @type {?string}
301
+ */
302
+ this.details = data.details;
303
+ } else {
304
+ this.details = null;
305
+ }
306
+
307
+ if ('state' in data) {
308
+ /**
309
+ * State of the activity
310
+ * @type {?string}
311
+ */
312
+ this.state = data.state;
313
+ } else {
314
+ this.state = null;
315
+ }
316
+
317
+ if ('sync_id' in data || 'syncId' in data) {
318
+ /**
319
+ * The sync id of the activity
320
+ * <info>This property is not documented by Discord and represents the track id in spotify activities.</info>
321
+ * @type {?string}
322
+ */
323
+ this.syncId = data.sync_id || data.syncId;
324
+ } else {
325
+ this.syncId = null;
326
+ }
327
+
328
+ if ('flags' in data) {
329
+ /**
330
+ * Flags that describe the activity
331
+ * @type {Readonly<ActivityFlags>}
332
+ */
333
+ this.flags = new ActivityFlags(data.flags).freeze();
334
+ } else {
335
+ this.flags = new ActivityFlags().freeze();
336
+ }
337
+
338
+ if ('buttons' in data) {
339
+ /**
340
+ * The labels of the buttons of this rich presence
341
+ * @type {string[]}
342
+ */
343
+ this.buttons = data.buttons;
344
+ } else {
345
+ this.buttons = [];
346
+ }
347
+
348
+ if ('emoji' in data && data.emoji) {
349
+ /**
350
+ * Emoji for a custom activity
351
+ * @type {?EmojiIdentifierResolvable}
352
+ */
353
+ this.emoji = Util.resolvePartialEmoji(data.emoji);
354
+ } else {
355
+ this.emoji = null;
356
+ }
357
+
358
+ if ('party' in data) {
359
+ /**
360
+ * Represents a party of an activity
361
+ * @typedef {Object} ActivityParty
362
+ * @property {?string} id The party's id
363
+ * @property {number[]} size Size of the party as `[current, max]`
364
+ */
365
+
366
+ /**
367
+ * Party of the activity
368
+ * @type {?ActivityParty}
369
+ */
370
+ this.party = data.party;
371
+ } else {
372
+ this.party = null;
373
+ }
374
+
375
+ /**
376
+ * Assets for rich presence
377
+ * @type {?RichPresenceAssets}
378
+ */
379
+ this.assets = new RichPresenceAssets(this, data.assets);
380
+ }
381
+
382
+ /**
383
+ * Whether this activity is equal to another activity.
384
+ * @param {Activity} activity The activity to compare with
385
+ * @returns {boolean}
386
+ */
387
+ equals(activity) {
388
+ return (
389
+ this === activity ||
390
+ (activity &&
391
+ this.name === activity.name &&
392
+ this.type === activity.type &&
393
+ this.url === activity.url &&
394
+ this.state === activity.state &&
395
+ this.details === activity.details &&
396
+ this.emoji?.id === activity.emoji?.id &&
397
+ this.emoji?.name === activity.emoji?.name)
398
+ );
399
+ }
400
+
401
+ /**
402
+ * The time the activity was created at
403
+ * @type {Date}
404
+ * @readonly
405
+ */
406
+ get createdAt() {
407
+ return new Date(this.createdTimestamp);
408
+ }
409
+
410
+ /**
411
+ * When concatenated with a string, this automatically returns the activities' name instead of the Activity object.
412
+ * @returns {string}
413
+ */
414
+ toString() {
415
+ return this.name;
416
+ }
417
+
418
+ _clone() {
419
+ return Object.assign(Object.create(this), this);
420
+ }
421
+
422
+ toJSON(...props) {
423
+ return Util.clearNullOrUndefinedObject({
424
+ ...Util.flatten(this, ...props),
425
+ type: typeof this.type === 'number' ? this.type : ActivityTypes[this.type],
426
+ });
427
+ }
428
+ }
429
+
430
+ /**
431
+ * Assets for a rich presence
432
+ */
433
+ class RichPresenceAssets {
434
+ constructor(activity, assets) {
435
+ /**
436
+ * The activity of the RichPresenceAssets
437
+ * @type {Activity}
438
+ * @readonly
439
+ * @name RichPresenceAssets#activity
440
+ */
441
+ Object.defineProperty(this, 'activity', { value: activity });
442
+
443
+ this._patch(assets);
444
+ }
445
+
446
+ _patch(assets = {}) {
447
+ if ('large_text' in assets || 'largeText' in assets) {
448
+ /**
449
+ * Hover text for the large image
450
+ * @type {?string}
451
+ */
452
+ this.largeText = assets.large_text || assets.largeText;
453
+ } else {
454
+ this.largeText = null;
455
+ }
456
+
457
+ if ('small_text' in assets || 'smallText' in assets) {
458
+ /**
459
+ * Hover text for the small image
460
+ * @type {?string}
461
+ */
462
+ this.smallText = assets.small_text || assets.smallText;
463
+ } else {
464
+ this.smallText = null;
465
+ }
466
+
467
+ if ('large_image' in assets || 'largeImage' in assets) {
468
+ /**
469
+ * The large image asset's id
470
+ * @type {?Snowflake}
471
+ */
472
+ this.largeImage = assets.large_image || assets.largeImage;
473
+ } else {
474
+ this.largeImage = null;
475
+ }
476
+
477
+ if ('small_image' in assets || 'smallImage' in assets) {
478
+ /**
479
+ * The small image asset's id
480
+ * @type {?Snowflake}
481
+ */
482
+ this.smallImage = assets.small_image || assets.smallImage;
483
+ } else {
484
+ this.smallImage = null;
485
+ }
486
+ }
487
+
488
+ /**
489
+ * Gets the URL of the small image asset
490
+ * @param {StaticImageURLOptions} [options] Options for the image URL
491
+ * @returns {?string}
492
+ */
493
+ smallImageURL({ format, size } = {}) {
494
+ if (!this.smallImage) return null;
495
+ if (this.smallImage.includes(':')) {
496
+ const [platform, id] = this.smallImage.split(':');
497
+ switch (platform) {
498
+ case 'mp':
499
+ return `https://media.discordapp.net/${id}`;
500
+ case 'spotify':
501
+ return `https://i.scdn.co/image/${id}`;
502
+ case 'youtube':
503
+ return `https://i.ytimg.com/vi/${id}/hqdefault_live.jpg`;
504
+ case 'twitch':
505
+ return `https://static-cdn.jtvnw.net/previews-ttv/live_user_${id}.png`;
506
+ default:
507
+ return null;
508
+ }
509
+ }
510
+
511
+ return this.activity.presence.client.rest.cdn.AppAsset(this.activity.applicationId, this.smallImage, {
512
+ format,
513
+ size,
514
+ });
515
+ }
516
+
517
+ /**
518
+ * Gets the URL of the large image asset
519
+ * @param {StaticImageURLOptions} [options] Options for the image URL
520
+ * @returns {?string}
521
+ */
522
+ largeImageURL({ format, size } = {}) {
523
+ if (!this.largeImage) return null;
524
+ if (this.largeImage.includes(':')) {
525
+ const [platform, id] = this.largeImage.split(':');
526
+ switch (platform) {
527
+ case 'mp':
528
+ return `https://media.discordapp.net/${id}`;
529
+ case 'spotify':
530
+ return `https://i.scdn.co/image/${id}`;
531
+ case 'youtube':
532
+ return `https://i.ytimg.com/vi/${id}/hqdefault_live.jpg`;
533
+ case 'twitch':
534
+ return `https://static-cdn.jtvnw.net/previews-ttv/live_user_${id}.png`;
535
+ default:
536
+ return null;
537
+ }
538
+ }
539
+
540
+ return this.activity.presence.client.rest.cdn.AppAsset(this.activity.applicationId, this.largeImage, {
541
+ format,
542
+ size,
543
+ });
544
+ }
545
+
546
+ static parseImage(image) {
547
+ if (typeof image != 'string') {
548
+ image = null;
549
+ } else if (URL.canParse(image) && ['http:', 'https:'].includes(new URL(image).protocol)) {
550
+ // Discord URL:
551
+ image = image
552
+ .replace('https://cdn.discordapp.com/', 'mp:')
553
+ .replace('http://cdn.discordapp.com/', 'mp:')
554
+ .replace('https://media.discordapp.net/', 'mp:')
555
+ .replace('http://media.discordapp.net/', 'mp:');
556
+ //
557
+ if (!image.startsWith('mp:')) {
558
+ throw new Error('INVALID_URL');
559
+ }
560
+ } else if (/^[0-9]{17,19}$/.test(image)) {
561
+ // ID Assets
562
+ } else if (['mp:', 'youtube:', 'spotify:', 'twitch:'].some(v => image.startsWith(v))) {
563
+ // Image
564
+ } else if (image.startsWith('external/')) {
565
+ image = `mp:${image}`;
566
+ }
567
+ return image;
568
+ }
569
+
570
+ toJSON() {
571
+ if (!this.largeImage && !this.largeText && !this.smallImage && !this.smallText) return null;
572
+ return {
573
+ large_image: RichPresenceAssets.parseImage(this.largeImage),
574
+ large_text: this.largeText,
575
+ small_image: RichPresenceAssets.parseImage(this.smallImage),
576
+ small_text: this.smallText,
577
+ };
578
+ }
579
+
580
+ /**
581
+ * @typedef {string} RichPresenceImage
582
+ * Support:
583
+ * - cdn.discordapp.com
584
+ * - media.discordapp.net
585
+ * - Assets ID (https://discord.com/api/v9/oauth2/applications/{application_id}/assets)
586
+ * - Media Proxy (mp:external/{hash})
587
+ * - Twitch (twitch:{username})
588
+ * - YouTube (youtube:{video_id})
589
+ * - Spotify (spotify:{image_id})
590
+ */
591
+
592
+ /**
593
+ * Set the large image of this activity
594
+ * @param {?RichPresenceImage} image The large image asset's id
595
+ * @returns {RichPresenceAssets}
596
+ */
597
+ setLargeImage(image) {
598
+ image = RichPresenceAssets.parseImage(image);
599
+ this.largeImage = image;
600
+ return this;
601
+ }
602
+
603
+ /**
604
+ * Set the small image of this activity
605
+ * @param {?RichPresenceImage} image The small image asset's id
606
+ * @returns {RichPresenceAssets}
607
+ */
608
+ setSmallImage(image) {
609
+ image = RichPresenceAssets.parseImage(image);
610
+ this.smallImage = image;
611
+ return this;
612
+ }
613
+
614
+ /**
615
+ * Hover text for the large image
616
+ * @param {string} text Assets text
617
+ * @returns {RichPresenceAssets}
618
+ */
619
+ setLargeText(text) {
620
+ this.largeText = text;
621
+ return this;
622
+ }
623
+
624
+ /**
625
+ * Hover text for the small image
626
+ * @param {string} text Assets text
627
+ * @returns {RichPresenceAssets}
628
+ */
629
+ setSmallText(text) {
630
+ this.smallText = text;
631
+ return this;
632
+ }
633
+ }
634
+
635
+ class CustomStatus extends Activity {
636
+ /**
637
+ * @typedef {Object} CustomStatusOptions
638
+ * @property {string} [state] The state to be displayed
639
+ * @property {EmojiIdentifierResolvable} [emoji] The emoji to be displayed
640
+ */
641
+
642
+ /**
643
+ * @param {Client} client Discord Client
644
+ * @param {CustomStatus|CustomStatusOptions} [data={}] CustomStatus to clone or raw data
645
+ */
646
+ constructor(client, data = {}) {
647
+ if (!client) throw new Error("Class constructor CustomStatus cannot be invoked without 'client'");
648
+ super('presence' in client ? client.presence : client, {
649
+ name: ' ',
650
+ type: ActivityTypes.CUSTOM,
651
+ ...data,
652
+ });
653
+ }
654
+
655
+ /**
656
+ * Set the emoji of this activity
657
+ * @param {EmojiIdentifierResolvable} emoji The emoji to be displayed
658
+ * @returns {CustomStatus}
659
+ */
660
+ setEmoji(emoji) {
661
+ this.emoji = Util.resolvePartialEmoji(emoji);
662
+ return this;
663
+ }
664
+
665
+ /**
666
+ * Set state of this activity
667
+ * @param {string | null} state The state to be displayed
668
+ * @returns {CustomStatus}
669
+ */
670
+ setState(state) {
671
+ if (typeof state == 'string' && state.length > 128) throw new Error('State must be less than 128 characters');
672
+ this.state = state;
673
+ return this;
674
+ }
675
+
676
+ /**
677
+ * Returns an object that can be used to set the status
678
+ * @returns {CustomStatus}
679
+ */
680
+ toJSON() {
681
+ if (!this.emoji & !this.state) throw new Error('CustomStatus must have at least one of emoji or state');
682
+ return {
683
+ name: this.name,
684
+ emoji: this.emoji,
685
+ type: ActivityTypes.CUSTOM,
686
+ state: this.state,
687
+ };
688
+ }
689
+ }
690
+
691
+ class RichPresence extends Activity {
692
+ /**
693
+ * @param {Client} client Discord client
694
+ * @param {RichPresence} [data={}] RichPresence to clone or raw data
695
+ */
696
+ constructor(client, data = {}) {
697
+ if (!client) throw new Error("Class constructor RichPresence cannot be invoked without 'client'");
698
+ super('presence' in client ? client.presence : client, { type: 0, ...data });
699
+ this.setup(data);
700
+ }
701
+
702
+ /**
703
+ * Sets the status from a JSON object
704
+ * @param {RichPresence} data data
705
+ * @private
706
+ */
707
+ setup(data = {}) {
708
+ this.secrets = 'secrets' in data ? data.secrets : {};
709
+ this.metadata = 'metadata' in data ? data.metadata : {};
710
+ }
711
+
712
+ /**
713
+ * Set the large image of this activity
714
+ * @param {?RichPresenceImage} image The large image asset's id
715
+ * @returns {RichPresence}
716
+ */
717
+ setAssetsLargeImage(image) {
718
+ this.assets.setLargeImage(image);
719
+ return this;
720
+ }
721
+
722
+ /**
723
+ * Set the small image of this activity
724
+ * @param {?RichPresenceImage} image The small image asset's id
725
+ * @returns {RichPresence}
726
+ */
727
+ setAssetsSmallImage(image) {
728
+ this.assets.setSmallImage(image);
729
+ return this;
730
+ }
731
+
732
+ /**
733
+ * Hover text for the large image
734
+ * @param {string} text Assets text
735
+ * @returns {RichPresence}
736
+ */
737
+ setAssetsLargeText(text) {
738
+ this.assets.setLargeText(text);
739
+ return this;
740
+ }
741
+
742
+ /**
743
+ * Hover text for the small image
744
+ * @param {string} text Assets text
745
+ * @returns {RichPresence}
746
+ */
747
+ setAssetsSmallText(text) {
748
+ this.assets.setSmallText(text);
749
+ return this;
750
+ }
751
+
752
+ /**
753
+ * Set the name of the activity
754
+ * @param {?string} name The activity's name
755
+ * @returns {RichPresence}
756
+ */
757
+ setName(name) {
758
+ this.name = name;
759
+ return this;
760
+ }
761
+
762
+ /**
763
+ * If the activity is being streamed, a link to the stream
764
+ * @param {?string} url URL of the stream
765
+ * @returns {RichPresence}
766
+ */
767
+ setURL(url) {
768
+ if (typeof url == 'string' && !URL.canParse(url)) throw new Error('URL must be a valid URL');
769
+ this.url = url;
770
+ return this;
771
+ }
772
+
773
+ /**
774
+ * The activity status's type
775
+ * @param {?ActivityTypes} type The type of activity
776
+ * @returns {RichPresence}
777
+ */
778
+ setType(type) {
779
+ this.type = typeof type == 'number' ? type : ActivityTypes[type];
780
+ return this;
781
+ }
782
+
783
+ /**
784
+ * Set the application id of this activity
785
+ * @param {?Snowflake} id Bot's id
786
+ * @returns {RichPresence}
787
+ */
788
+ setApplicationId(id) {
789
+ this.applicationId = id;
790
+ return this;
791
+ }
792
+
793
+ /**
794
+ * Set the state of the activity
795
+ * @param {?string} state The state of the activity
796
+ * @returns {RichPresence}
797
+ */
798
+ setState(state) {
799
+ this.state = state;
800
+ return this;
801
+ }
802
+
803
+ /**
804
+ * Set the details of the activity
805
+ * @param {?string} details The details of the activity
806
+ * @returns {RichPresence}
807
+ */
808
+ setDetails(details) {
809
+ this.details = details;
810
+ return this;
811
+ }
812
+
813
+ /**
814
+ * @typedef {Object} RichParty
815
+ * @property {string} id The id of the party
816
+ * @property {number} max The maximum number of members in the party
817
+ * @property {number} current The current number of members in the party
818
+ */
819
+
820
+ /**
821
+ * Set the party of this activity
822
+ * @param {?RichParty} party The party to be displayed
823
+ * @returns {RichPresence}
824
+ */
825
+ setParty(party) {
826
+ if (typeof party == 'object') {
827
+ if (!party.max || typeof party.max != 'number') throw new Error('Party must have max number');
828
+ if (!party.current || typeof party.current != 'number') throw new Error('Party must have current');
829
+ if (party.current > party.max) throw new Error('Party current must be less than max number');
830
+ if (!party.id || typeof party.id != 'string') party.id = randomUUID();
831
+ this.party = {
832
+ size: [party.current, party.max],
833
+ id: party.id,
834
+ };
835
+ } else {
836
+ this.party = null;
837
+ }
838
+ return this;
839
+ }
840
+
841
+ /**
842
+ * Sets the start timestamp of the activity
843
+ * @param {Date|number|null} timestamp The timestamp of the start of the activity
844
+ * @returns {RichPresence}
845
+ */
846
+ setStartTimestamp(timestamp) {
847
+ if (!this.timestamps) this.timestamps = {};
848
+ if (timestamp instanceof Date) timestamp = timestamp.getTime();
849
+ this.timestamps.start = timestamp;
850
+ return this;
851
+ }
852
+
853
+ /**
854
+ * Sets the end timestamp of the activity
855
+ * @param {Date|number|null} timestamp The timestamp of the end of the activity
856
+ * @returns {RichPresence}
857
+ */
858
+ setEndTimestamp(timestamp) {
859
+ if (!this.timestamps) this.timestamps = {};
860
+ if (timestamp instanceof Date) timestamp = timestamp.getTime();
861
+ this.timestamps.end = timestamp;
862
+ return this;
863
+ }
864
+
865
+ /**
866
+ * @typedef {object} RichButton
867
+ * @property {string} name The name of the button
868
+ * @property {string} url The url of the button
869
+ */
870
+ /**
871
+ * Set the buttons of the rich presence
872
+ * @param {...?RichButton} button A list of buttons to set
873
+ * @returns {RichPresence}
874
+ */
875
+ setButtons(...button) {
876
+ if (button.length == 0) {
877
+ this.buttons = [];
878
+ delete this.metadata.button_urls;
879
+ return this;
880
+ } else if (button.length > 2) {
881
+ throw new Error('RichPresence can only have up to 2 buttons');
882
+ }
883
+
884
+ this.buttons = [];
885
+ this.metadata.button_urls = [];
886
+
887
+ button.flat(2).forEach(b => {
888
+ if (b.name && b.url) {
889
+ this.buttons.push(b.name);
890
+ if (!URL.canParse(b.url)) throw new Error('Button url must be a valid url');
891
+ this.metadata.button_urls.push(b.url);
892
+ } else {
893
+ throw new Error('Button must have name and url');
894
+ }
895
+ });
896
+ return this;
897
+ }
898
+
899
+ /**
900
+ * The platform the activity is being played on
901
+ * @param {ActivityPlatform | null} platform Any platform
902
+ * @returns {RichPresence}
903
+ */
904
+ setPlatform(platform) {
905
+ this.platform = platform;
906
+ return this;
907
+ }
908
+
909
+ /**
910
+ * Secrets for rich presence joining and spectating (send-only)
911
+ * @param {?string} join Secrets for rich presence joining
912
+ * @returns {RichPresence}
913
+ */
914
+ setJoinSecret(join) {
915
+ this.secrets.join = join;
916
+ return this;
917
+ }
918
+
919
+ /**
920
+ * Add a button to the rich presence
921
+ * @param {string} name The name of the button
922
+ * @param {string} url The url of the button
923
+ * @returns {RichPresence}
924
+ */
925
+ addButton(name, url) {
926
+ if (!name || !url) {
927
+ throw new Error('Button must have name and url');
928
+ }
929
+ if (typeof name !== 'string') throw new Error('Button name must be a string');
930
+ if (!URL.canParse(url)) throw new Error('Button url must be a valid url');
931
+ this.buttons.push(name);
932
+ if (Array.isArray(this.metadata.button_urls)) this.metadata.button_urls.push(url);
933
+ else this.metadata.button_urls = [url];
934
+ return this;
935
+ }
936
+
937
+ /**
938
+ * Convert the rich presence to a JSON object
939
+ * @returns {Object}
940
+ */
941
+ toJSON(...props) {
942
+ return super.toJSON(
943
+ {
944
+ applicationId: 'application_id',
945
+ sessionId: 'session_id',
946
+ syncId: 'sync_id',
947
+ createdTimestamp: 'created_at',
948
+ },
949
+ ...props,
950
+ );
951
+ }
952
+
953
+ /**
954
+ * @typedef {Object} ExternalAssets
955
+ * @property {?string} url Orginal url of the image
956
+ * @property {?string} external_asset_path Proxy url of the image (Using to RPC)
957
+ */
958
+
959
+ /**
960
+ * Retrieves external assets from a RichPresence
961
+ * @param {Client} client - The Discord client instance.
962
+ * @param {Snowflake} applicationId - The application ID associated with the Rich Presence.
963
+ * @param {...string} images - 1 or 2 external image URLs (not hosted by Discord).
964
+ * @returns {Promise<ExternalAssets[]>}
965
+ */
966
+ static async getExternal(client, applicationId, ...images) {
967
+ if (!client || !client.token || !client.api) throw new Error('Client must be set');
968
+ // Check if applicationId is discord snowflake (17 , 18, 19 numbers)
969
+ if (!/^[0-9]{17,19}$/.test(applicationId)) {
970
+ throw new Error('Application id must be a Discord Snowflake');
971
+ }
972
+ // Check if images are 1 or 2
973
+ if (images.length > 2) {
974
+ throw new Error('RichPresence can only have up to 2 external images');
975
+ }
976
+ // Check if all images are valid URLs
977
+ if (images.some(image => !URL.canParse(image))) {
978
+ throw new Error('Each image must be a valid URL.');
979
+ }
980
+ const res = await client.api.applications[applicationId]['external-assets'].post({
981
+ data: {
982
+ urls: images,
983
+ },
984
+ });
985
+ return res;
986
+ }
987
+
988
+ /**
989
+ * When concatenated with a string, this automatically returns the activities' name instead of the Activity object.
990
+ * @returns {string}
991
+ */
992
+ toString() {
993
+ return this.name;
994
+ }
995
+
996
+ _clone() {
997
+ return Object.assign(Object.create(this), this);
998
+ }
999
+ }
1000
+
1001
+ /**
1002
+ * @extends {RichPresence}
1003
+ */
1004
+ class SpotifyRPC extends RichPresence {
1005
+ /**
1006
+ * Create a new RichPresence (Spotify style)
1007
+ * @param {Client} client Discord Client
1008
+ * @param {SpotifyRPC} [options] Options for the Spotify RPC
1009
+ */
1010
+ constructor(client, options = {}) {
1011
+ if (!client) throw new Error("Class constructor SpotifyRPC cannot be invoked without 'client'");
1012
+ super(client, {
1013
+ name: 'Spotify',
1014
+ type: ActivityTypes.LISTENING,
1015
+ party: {
1016
+ id: `spotify:${client.user.id}`,
1017
+ },
1018
+ id: 'spotify:1',
1019
+ flags: 48, // Sync + Play (ActivityFlags)
1020
+ ...options,
1021
+ });
1022
+ this.setup(options);
1023
+ }
1024
+ /**
1025
+ * Sets the status from a JSON object
1026
+ * @param {SpotifyRPC} options data
1027
+ * @private
1028
+ */
1029
+ setup(options) {
1030
+ /**
1031
+ * @typedef {Object} SpotifyMetadata
1032
+ * @property {string} album_id The Spotify ID of the album of the song being played
1033
+ * @property {Array<string>} artist_ids The Spotify IDs of the artists of the song being played
1034
+ * @property {string} context_uri The Spotify URI of the current player context
1035
+ */
1036
+
1037
+ /**
1038
+ * Spotify metadata
1039
+ * @type {SpotifyMetadata}
1040
+ */
1041
+ this.metadata = {
1042
+ album_id: options.metadata?.album_id || null,
1043
+ artist_ids: options.metadata?.artist_ids || [],
1044
+ context_uri: options.metadata?.context_uri || null,
1045
+ };
1046
+ }
1047
+
1048
+ /**
1049
+ * Set Spotify song id to sync with
1050
+ * @param {string} id Song id
1051
+ * @returns {SpotifyRPC}
1052
+ */
1053
+ setSongId(id) {
1054
+ this.syncId = id;
1055
+ return this;
1056
+ }
1057
+
1058
+ /**
1059
+ * Add the artist id
1060
+ * @param {string} id Artist id
1061
+ * @returns {SpotifyRPC}
1062
+ */
1063
+ addArtistId(id) {
1064
+ if (!this.metadata.artist_ids) this.metadata.artist_ids = [];
1065
+ this.metadata.artist_ids.push(id);
1066
+ return this;
1067
+ }
1068
+
1069
+ /**
1070
+ * Set the artist ids
1071
+ * @param {string | Array<string>} ids Artist ids
1072
+ * @returns {SpotifyRPC}
1073
+ */
1074
+ setArtistIds(...ids) {
1075
+ if (!ids?.length) {
1076
+ this.metadata.artist_ids = [];
1077
+ return this;
1078
+ }
1079
+ if (!this.metadata.artist_ids) this.metadata.artist_ids = [];
1080
+ ids.flat(2).forEach(id => this.metadata.artist_ids.push(id));
1081
+ return this;
1082
+ }
1083
+
1084
+ /**
1085
+ * Set the album id
1086
+ * @param {string} id Album id
1087
+ * @returns {SpotifyRPC}
1088
+ */
1089
+ setAlbumId(id) {
1090
+ this.metadata.album_id = id;
1091
+ this.metadata.context_uri = `spotify:album:${id}`;
1092
+ return this;
1093
+ }
1094
+
1095
+ toJSON() {
1096
+ return super.toJSON({ id: false, emoji: false, platform: false, buttons: false });
1097
+ }
1098
+ }
1099
+
1100
+ exports.Presence = Presence;
1101
+ exports.Activity = Activity;
1102
+ exports.RichPresenceAssets = RichPresenceAssets;
1103
+ exports.CustomStatus = CustomStatus;
1104
+ exports.RichPresence = RichPresence;
1105
+ exports.SpotifyRPC = SpotifyRPC;