lolka.js 0.1.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 (337) hide show
  1. package/LICENSE +191 -0
  2. package/README.md +148 -0
  3. package/package.json +104 -0
  4. package/src/client/Client.js +943 -0
  5. package/src/client/actions/Action.js +151 -0
  6. package/src/client/actions/ActionsManager.js +75 -0
  7. package/src/client/actions/ChannelCreate.js +25 -0
  8. package/src/client/actions/ChannelDelete.js +24 -0
  9. package/src/client/actions/ChannelUpdate.js +42 -0
  10. package/src/client/actions/GuildChannelsPositionUpdate.js +21 -0
  11. package/src/client/actions/GuildEmojiCreate.js +21 -0
  12. package/src/client/actions/GuildEmojiDelete.js +20 -0
  13. package/src/client/actions/GuildEmojiUpdate.js +21 -0
  14. package/src/client/actions/GuildEmojisUpdate.js +34 -0
  15. package/src/client/actions/GuildMemberRemove.js +33 -0
  16. package/src/client/actions/GuildMemberUpdate.js +45 -0
  17. package/src/client/actions/GuildRoleCreate.js +27 -0
  18. package/src/client/actions/GuildRoleDelete.js +30 -0
  19. package/src/client/actions/GuildRolesPositionUpdate.js +21 -0
  20. package/src/client/actions/GuildScheduledEventDelete.js +32 -0
  21. package/src/client/actions/GuildScheduledEventUserAdd.js +33 -0
  22. package/src/client/actions/GuildScheduledEventUserRemove.js +33 -0
  23. package/src/client/actions/GuildSoundboardSoundDelete.js +30 -0
  24. package/src/client/actions/GuildStickerCreate.js +21 -0
  25. package/src/client/actions/GuildStickerDelete.js +20 -0
  26. package/src/client/actions/GuildStickerUpdate.js +21 -0
  27. package/src/client/actions/GuildStickersUpdate.js +34 -0
  28. package/src/client/actions/GuildUpdate.js +34 -0
  29. package/src/client/actions/InteractionCreate.js +110 -0
  30. package/src/client/actions/MessageCreate.js +43 -0
  31. package/src/client/actions/MessageDelete.js +33 -0
  32. package/src/client/actions/MessageDeleteBulk.js +49 -0
  33. package/src/client/actions/MessagePollVoteAdd.js +41 -0
  34. package/src/client/actions/MessagePollVoteRemove.js +39 -0
  35. package/src/client/actions/MessageReactionAdd.js +72 -0
  36. package/src/client/actions/MessageReactionRemove.js +51 -0
  37. package/src/client/actions/MessageReactionRemoveAll.js +34 -0
  38. package/src/client/actions/MessageReactionRemoveEmoji.js +29 -0
  39. package/src/client/actions/MessageUpdate.js +26 -0
  40. package/src/client/actions/StageInstanceCreate.js +29 -0
  41. package/src/client/actions/StageInstanceDelete.js +32 -0
  42. package/src/client/actions/StageInstanceUpdate.js +31 -0
  43. package/src/client/actions/ThreadCreate.js +26 -0
  44. package/src/client/actions/ThreadMembersUpdate.js +49 -0
  45. package/src/client/actions/TypingStart.js +30 -0
  46. package/src/client/actions/UserUpdate.js +37 -0
  47. package/src/client/voice/ClientVoiceManager.js +48 -0
  48. package/src/client/websocket/handlers/APPLICATION_COMMAND_PERMISSIONS_UPDATE.js +30 -0
  49. package/src/client/websocket/handlers/AUTO_MODERATION_ACTION_EXECUTION.js +18 -0
  50. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_CREATE.js +19 -0
  51. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_DELETE.js +22 -0
  52. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_UPDATE.js +21 -0
  53. package/src/client/websocket/handlers/CHANNEL_CREATE.js +5 -0
  54. package/src/client/websocket/handlers/CHANNEL_DELETE.js +5 -0
  55. package/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.js +23 -0
  56. package/src/client/websocket/handlers/CHANNEL_UPDATE.js +17 -0
  57. package/src/client/websocket/handlers/ENTITLEMENT_CREATE.js +15 -0
  58. package/src/client/websocket/handlers/ENTITLEMENT_DELETE.js +19 -0
  59. package/src/client/websocket/handlers/ENTITLEMENT_UPDATE.js +17 -0
  60. package/src/client/websocket/handlers/GUILD_AUDIT_LOG_ENTRY_CREATE.js +20 -0
  61. package/src/client/websocket/handlers/GUILD_BAN_ADD.js +16 -0
  62. package/src/client/websocket/handlers/GUILD_BAN_REMOVE.js +21 -0
  63. package/src/client/websocket/handlers/GUILD_CREATE.js +35 -0
  64. package/src/client/websocket/handlers/GUILD_DELETE.js +37 -0
  65. package/src/client/websocket/handlers/GUILD_EMOJIS_UPDATE.js +5 -0
  66. package/src/client/websocket/handlers/GUILD_INTEGRATIONS_UPDATE.js +16 -0
  67. package/src/client/websocket/handlers/GUILD_MEMBERS_CHUNK.js +41 -0
  68. package/src/client/websocket/handlers/GUILD_MEMBER_ADD.js +18 -0
  69. package/src/client/websocket/handlers/GUILD_MEMBER_REMOVE.js +5 -0
  70. package/src/client/websocket/handlers/GUILD_MEMBER_UPDATE.js +5 -0
  71. package/src/client/websocket/handlers/GUILD_ROLE_CREATE.js +5 -0
  72. package/src/client/websocket/handlers/GUILD_ROLE_DELETE.js +5 -0
  73. package/src/client/websocket/handlers/GUILD_ROLE_UPDATE.js +22 -0
  74. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_CREATE.js +18 -0
  75. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_DELETE.js +5 -0
  76. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_UPDATE.js +20 -0
  77. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_ADD.js +5 -0
  78. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_REMOVE.js +5 -0
  79. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUNDS_UPDATE.js +25 -0
  80. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_CREATE.js +19 -0
  81. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_DELETE.js +5 -0
  82. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_UPDATE.js +21 -0
  83. package/src/client/websocket/handlers/GUILD_STICKERS_UPDATE.js +5 -0
  84. package/src/client/websocket/handlers/GUILD_UPDATE.js +5 -0
  85. package/src/client/websocket/handlers/INTERACTION_CREATE.js +5 -0
  86. package/src/client/websocket/handlers/INVITE_CREATE.js +21 -0
  87. package/src/client/websocket/handlers/INVITE_DELETE.js +24 -0
  88. package/src/client/websocket/handlers/MESSAGE_CREATE.js +5 -0
  89. package/src/client/websocket/handlers/MESSAGE_DELETE.js +5 -0
  90. package/src/client/websocket/handlers/MESSAGE_DELETE_BULK.js +5 -0
  91. package/src/client/websocket/handlers/MESSAGE_POLL_VOTE_ADD.js +5 -0
  92. package/src/client/websocket/handlers/MESSAGE_POLL_VOTE_REMOVE.js +5 -0
  93. package/src/client/websocket/handlers/MESSAGE_REACTION_ADD.js +5 -0
  94. package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE.js +5 -0
  95. package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_ALL.js +5 -0
  96. package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_EMOJI.js +5 -0
  97. package/src/client/websocket/handlers/MESSAGE_UPDATE.js +17 -0
  98. package/src/client/websocket/handlers/PRESENCE_UPDATE.js +43 -0
  99. package/src/client/websocket/handlers/RATE_LIMITED.js +24 -0
  100. package/src/client/websocket/handlers/READY.js +30 -0
  101. package/src/client/websocket/handlers/SOUNDBOARD_SOUNDS.js +25 -0
  102. package/src/client/websocket/handlers/STAGE_INSTANCE_CREATE.js +5 -0
  103. package/src/client/websocket/handlers/STAGE_INSTANCE_DELETE.js +5 -0
  104. package/src/client/websocket/handlers/STAGE_INSTANCE_UPDATE.js +5 -0
  105. package/src/client/websocket/handlers/SUBSCRIPTION_CREATE.js +15 -0
  106. package/src/client/websocket/handlers/SUBSCRIPTION_DELETE.js +17 -0
  107. package/src/client/websocket/handlers/SUBSCRIPTION_UPDATE.js +17 -0
  108. package/src/client/websocket/handlers/THREAD_CREATE.js +5 -0
  109. package/src/client/websocket/handlers/THREAD_DELETE.js +18 -0
  110. package/src/client/websocket/handlers/THREAD_LIST_SYNC.js +52 -0
  111. package/src/client/websocket/handlers/THREAD_MEMBERS_UPDATE.js +5 -0
  112. package/src/client/websocket/handlers/THREAD_MEMBER_UPDATE.js +26 -0
  113. package/src/client/websocket/handlers/THREAD_UPDATE.js +17 -0
  114. package/src/client/websocket/handlers/TYPING_START.js +5 -0
  115. package/src/client/websocket/handlers/USER_UPDATE.js +5 -0
  116. package/src/client/websocket/handlers/VOICE_CHANNEL_EFFECT_SEND.js +17 -0
  117. package/src/client/websocket/handlers/VOICE_SERVER_UPDATE.js +33 -0
  118. package/src/client/websocket/handlers/VOICE_STATE_UPDATE.js +38 -0
  119. package/src/client/websocket/handlers/WEBHOOKS_UPDATE.js +17 -0
  120. package/src/client/websocket/handlers/index.js +78 -0
  121. package/src/errors/DJSError.js +52 -0
  122. package/src/errors/ErrorCodes.js +280 -0
  123. package/src/errors/Messages.js +159 -0
  124. package/src/errors/index.js +7 -0
  125. package/src/index.js +261 -0
  126. package/src/managers/ApplicationCommandManager.js +305 -0
  127. package/src/managers/ApplicationCommandPermissionsManager.js +452 -0
  128. package/src/managers/ApplicationEmojiManager.js +152 -0
  129. package/src/managers/AutoModerationRuleManager.js +310 -0
  130. package/src/managers/BaseManager.js +21 -0
  131. package/src/managers/CachedManager.js +68 -0
  132. package/src/managers/CategoryChannelChildManager.js +85 -0
  133. package/src/managers/ChannelManager.js +197 -0
  134. package/src/managers/DMMessageManager.js +19 -0
  135. package/src/managers/DataManager.js +66 -0
  136. package/src/managers/EntitlementManager.js +185 -0
  137. package/src/managers/GuildApplicationCommandManager.js +31 -0
  138. package/src/managers/GuildBanManager.js +224 -0
  139. package/src/managers/GuildChannelManager.js +556 -0
  140. package/src/managers/GuildEmojiManager.js +264 -0
  141. package/src/managers/GuildEmojiRoleManager.js +136 -0
  142. package/src/managers/GuildForumThreadManager.js +88 -0
  143. package/src/managers/GuildInviteManager.js +239 -0
  144. package/src/managers/GuildManager.js +268 -0
  145. package/src/managers/GuildMemberManager.js +622 -0
  146. package/src/managers/GuildMemberRoleManager.js +232 -0
  147. package/src/managers/GuildMessageManager.js +35 -0
  148. package/src/managers/GuildScheduledEventManager.js +333 -0
  149. package/src/managers/GuildSoundboardSoundManager.js +226 -0
  150. package/src/managers/GuildStickerManager.js +195 -0
  151. package/src/managers/GuildTextThreadManager.js +95 -0
  152. package/src/managers/MessageManager.js +355 -0
  153. package/src/managers/PartialGroupDMMessageManager.js +19 -0
  154. package/src/managers/PermissionOverwriteManager.js +177 -0
  155. package/src/managers/PollAnswerVoterManager.js +62 -0
  156. package/src/managers/PresenceManager.js +63 -0
  157. package/src/managers/ReactionManager.js +75 -0
  158. package/src/managers/ReactionUserManager.js +85 -0
  159. package/src/managers/RoleManager.js +446 -0
  160. package/src/managers/StageInstanceManager.js +169 -0
  161. package/src/managers/SubscriptionManager.js +86 -0
  162. package/src/managers/ThreadManager.js +213 -0
  163. package/src/managers/ThreadMemberManager.js +197 -0
  164. package/src/managers/UserManager.js +149 -0
  165. package/src/managers/VoiceStateManager.js +64 -0
  166. package/src/sharding/Shard.js +506 -0
  167. package/src/sharding/ShardClientUtil.js +292 -0
  168. package/src/sharding/ShardingManager.js +390 -0
  169. package/src/structures/ActionRow.js +34 -0
  170. package/src/structures/ActivityInstance.js +52 -0
  171. package/src/structures/ActivityLocation.js +65 -0
  172. package/src/structures/AnnouncementChannel.js +29 -0
  173. package/src/structures/AnonymousGuild.js +107 -0
  174. package/src/structures/ApplicationCommand.js +657 -0
  175. package/src/structures/ApplicationEmoji.js +186 -0
  176. package/src/structures/ApplicationRoleConnectionMetadata.js +52 -0
  177. package/src/structures/Attachment.js +181 -0
  178. package/src/structures/AuthorizingIntegrationOwners.js +64 -0
  179. package/src/structures/AutoModerationActionExecution.js +131 -0
  180. package/src/structures/AutoModerationRule.js +317 -0
  181. package/src/structures/AutocompleteInteraction.js +112 -0
  182. package/src/structures/Base.js +45 -0
  183. package/src/structures/BaseChannel.js +188 -0
  184. package/src/structures/BaseGuild.js +134 -0
  185. package/src/structures/BaseGuildEmoji.js +111 -0
  186. package/src/structures/BaseGuildTextChannel.js +225 -0
  187. package/src/structures/BaseGuildVoiceChannel.js +265 -0
  188. package/src/structures/BaseInteraction.js +378 -0
  189. package/src/structures/BaseInvite.js +187 -0
  190. package/src/structures/BaseSelectMenuComponent.js +62 -0
  191. package/src/structures/ButtonComponent.js +72 -0
  192. package/src/structures/ButtonInteraction.js +12 -0
  193. package/src/structures/CategoryChannel.js +50 -0
  194. package/src/structures/ChannelSelectMenuComponent.js +22 -0
  195. package/src/structures/ChannelSelectMenuInteraction.js +36 -0
  196. package/src/structures/ChatInputCommandInteraction.js +45 -0
  197. package/src/structures/ClientApplication.js +463 -0
  198. package/src/structures/ClientPresence.js +89 -0
  199. package/src/structures/ClientUser.js +221 -0
  200. package/src/structures/CommandInteraction.js +188 -0
  201. package/src/structures/CommandInteractionOptionResolver.js +336 -0
  202. package/src/structures/Component.js +62 -0
  203. package/src/structures/ContainerComponent.js +66 -0
  204. package/src/structures/ContextMenuCommandInteraction.js +69 -0
  205. package/src/structures/DMChannel.js +162 -0
  206. package/src/structures/DirectoryChannel.js +40 -0
  207. package/src/structures/Embed.js +254 -0
  208. package/src/structures/Emoji.js +115 -0
  209. package/src/structures/Entitlement.js +199 -0
  210. package/src/structures/FileComponent.js +44 -0
  211. package/src/structures/ForumChannel.js +34 -0
  212. package/src/structures/GroupDMInvite.js +37 -0
  213. package/src/structures/Guild.js +1557 -0
  214. package/src/structures/GuildAuditLogs.js +97 -0
  215. package/src/structures/GuildAuditLogsEntry.js +552 -0
  216. package/src/structures/GuildBan.js +65 -0
  217. package/src/structures/GuildChannel.js +511 -0
  218. package/src/structures/GuildEmoji.js +160 -0
  219. package/src/structures/GuildInvite.js +223 -0
  220. package/src/structures/GuildMember.js +650 -0
  221. package/src/structures/GuildOnboarding.js +71 -0
  222. package/src/structures/GuildOnboardingPrompt.js +88 -0
  223. package/src/structures/GuildOnboardingPromptOption.js +96 -0
  224. package/src/structures/GuildPreview.js +213 -0
  225. package/src/structures/GuildPreviewEmoji.js +30 -0
  226. package/src/structures/GuildScheduledEvent.js +579 -0
  227. package/src/structures/GuildTemplate.js +221 -0
  228. package/src/structures/Integration.js +243 -0
  229. package/src/structures/IntegrationApplication.js +82 -0
  230. package/src/structures/InteractionCallback.js +83 -0
  231. package/src/structures/InteractionCallbackResource.js +57 -0
  232. package/src/structures/InteractionCallbackResponse.js +36 -0
  233. package/src/structures/InteractionCollector.js +256 -0
  234. package/src/structures/InteractionWebhook.js +67 -0
  235. package/src/structures/InviteGuild.js +24 -0
  236. package/src/structures/LabelComponent.js +54 -0
  237. package/src/structures/MediaChannel.js +12 -0
  238. package/src/structures/MediaGalleryComponent.js +34 -0
  239. package/src/structures/MediaGalleryItem.js +56 -0
  240. package/src/structures/MentionableSelectMenuComponent.js +12 -0
  241. package/src/structures/MentionableSelectMenuInteraction.js +76 -0
  242. package/src/structures/Message.js +1203 -0
  243. package/src/structures/MessageCollector.js +157 -0
  244. package/src/structures/MessageComponentInteraction.js +128 -0
  245. package/src/structures/MessageContextMenuCommandInteraction.js +22 -0
  246. package/src/structures/MessageMentions.js +323 -0
  247. package/src/structures/MessagePayload.js +346 -0
  248. package/src/structures/MessageReaction.js +214 -0
  249. package/src/structures/ModalComponentResolver.js +269 -0
  250. package/src/structures/ModalSubmitInteraction.js +274 -0
  251. package/src/structures/OAuth2Guild.js +31 -0
  252. package/src/structures/PartialGroupDMChannel.js +146 -0
  253. package/src/structures/PermissionOverwrites.js +221 -0
  254. package/src/structures/Poll.js +190 -0
  255. package/src/structures/PollAnswer.js +98 -0
  256. package/src/structures/Presence.js +429 -0
  257. package/src/structures/PrimaryEntryPointCommandInteraction.js +12 -0
  258. package/src/structures/ReactionCollector.js +246 -0
  259. package/src/structures/ReactionEmoji.js +33 -0
  260. package/src/structures/Role.js +539 -0
  261. package/src/structures/RoleSelectMenuComponent.js +12 -0
  262. package/src/structures/RoleSelectMenuInteraction.js +36 -0
  263. package/src/structures/SKU.js +59 -0
  264. package/src/structures/SectionComponent.js +46 -0
  265. package/src/structures/SeparatorComponent.js +33 -0
  266. package/src/structures/SoundboardSound.js +220 -0
  267. package/src/structures/StageChannel.js +121 -0
  268. package/src/structures/StageInstance.js +170 -0
  269. package/src/structures/Sticker.js +292 -0
  270. package/src/structures/StickerPack.js +107 -0
  271. package/src/structures/StringSelectMenuComponent.js +22 -0
  272. package/src/structures/StringSelectMenuInteraction.js +23 -0
  273. package/src/structures/Subscription.js +131 -0
  274. package/src/structures/Team.js +129 -0
  275. package/src/structures/TeamMember.js +77 -0
  276. package/src/structures/TextChannel.js +36 -0
  277. package/src/structures/TextDisplayComponent.js +22 -0
  278. package/src/structures/TextInputComponent.js +32 -0
  279. package/src/structures/ThreadChannel.js +662 -0
  280. package/src/structures/ThreadMember.js +124 -0
  281. package/src/structures/ThreadOnlyChannel.js +270 -0
  282. package/src/structures/ThumbnailComponent.js +54 -0
  283. package/src/structures/Typing.js +82 -0
  284. package/src/structures/UnfurledMediaItem.js +36 -0
  285. package/src/structures/User.js +505 -0
  286. package/src/structures/UserContextMenuCommandInteraction.js +32 -0
  287. package/src/structures/UserSelectMenuComponent.js +12 -0
  288. package/src/structures/UserSelectMenuInteraction.js +55 -0
  289. package/src/structures/VoiceChannel.js +123 -0
  290. package/src/structures/VoiceChannelEffect.js +88 -0
  291. package/src/structures/VoiceRegion.js +51 -0
  292. package/src/structures/VoiceState.js +338 -0
  293. package/src/structures/Webhook.js +520 -0
  294. package/src/structures/WelcomeChannel.js +67 -0
  295. package/src/structures/WelcomeScreen.js +54 -0
  296. package/src/structures/Widget.js +107 -0
  297. package/src/structures/WidgetMember.js +114 -0
  298. package/src/structures/interfaces/Application.js +173 -0
  299. package/src/structures/interfaces/Collector.js +368 -0
  300. package/src/structures/interfaces/InteractionResponses.js +385 -0
  301. package/src/structures/interfaces/TextBasedChannel.js +431 -0
  302. package/src/util/APITypes.js +700 -0
  303. package/src/util/ActivityFlagsBitField.js +29 -0
  304. package/src/util/ApplicationFlagsBitField.js +46 -0
  305. package/src/util/AttachmentFlagsBitField.js +29 -0
  306. package/src/util/BitField.js +197 -0
  307. package/src/util/ChannelFlagsBitField.js +46 -0
  308. package/src/util/Channels.js +173 -0
  309. package/src/util/Colors.js +73 -0
  310. package/src/util/Components.js +329 -0
  311. package/src/util/Constants.js +253 -0
  312. package/src/util/DataResolver.js +161 -0
  313. package/src/util/Enums.js +14 -0
  314. package/src/util/Events.js +179 -0
  315. package/src/util/GuildMemberFlagsBitField.js +46 -0
  316. package/src/util/IntentsBitField.js +38 -0
  317. package/src/util/InviteFlagsBitField.js +29 -0
  318. package/src/util/Invites.js +31 -0
  319. package/src/util/LimitedCollection.js +75 -0
  320. package/src/util/LolkaSnowflake.js +47 -0
  321. package/src/util/MessageFlagsBitField.js +46 -0
  322. package/src/util/Options.js +221 -0
  323. package/src/util/Partials.js +51 -0
  324. package/src/util/PermissionsBitField.js +117 -0
  325. package/src/util/RoleFlagsBitField.js +29 -0
  326. package/src/util/SKUFlagsBitField.js +29 -0
  327. package/src/util/ShardEvents.js +27 -0
  328. package/src/util/Status.js +17 -0
  329. package/src/util/Sweepers.js +533 -0
  330. package/src/util/Symbols.js +3 -0
  331. package/src/util/SystemChannelFlagsBitField.js +48 -0
  332. package/src/util/ThreadMemberFlagsBitField.js +36 -0
  333. package/src/util/Transformers.js +124 -0
  334. package/src/util/UserFlagsBitField.js +36 -0
  335. package/src/util/Util.js +609 -0
  336. package/typings/index.d.mts +7512 -0
  337. package/typings/index.d.ts +7512 -0
@@ -0,0 +1,429 @@
1
+ /* eslint-disable no-use-before-define */
2
+ 'use strict';
3
+
4
+ const { ActivityFlagsBitField } = require('../util/ActivityFlagsBitField.js');
5
+ const { flatten } = require('../util/Util.js');
6
+ const { Base } = require('./Base.js');
7
+ const { Emoji } = require('./Emoji.js');
8
+
9
+ /**
10
+ * Activity sent in a message.
11
+ *
12
+ * @typedef {Object} MessageActivity
13
+ * @property {string} [partyId] Id of the party represented in activity
14
+ * @property {MessageActivityType} type Type of activity sent
15
+ */
16
+
17
+ /**
18
+ * The status of this presence:
19
+ * - `online` - user is online
20
+ * - `idle` - user is AFK
21
+ * - `offline` - user is offline or invisible
22
+ * - `dnd` - user is in Do Not Disturb
23
+ *
24
+ * @typedef {string} PresenceStatus
25
+ */
26
+
27
+ /**
28
+ * The status of this presence:
29
+ * - `online` - user is online
30
+ * - `idle` - user is AFK
31
+ * - `dnd` - user is in Do Not Disturb
32
+ *
33
+ * @typedef {string} ClientPresenceStatus
34
+ */
35
+
36
+ /**
37
+ * Represents a user's presence.
38
+ *
39
+ * @extends {Base}
40
+ */
41
+ class Presence extends Base {
42
+ constructor(client, data = {}) {
43
+ super(client);
44
+
45
+ /**
46
+ * The presence's user id
47
+ *
48
+ * @type {Snowflake}
49
+ */
50
+ this.userId = data.user.id;
51
+
52
+ /**
53
+ * The guild this presence is in
54
+ *
55
+ * @type {?Guild}
56
+ */
57
+ this.guild = data.guild ?? null;
58
+
59
+ this._patch(data);
60
+ }
61
+
62
+ /**
63
+ * The user of this presence
64
+ *
65
+ * @type {?User}
66
+ * @readonly
67
+ */
68
+ get user() {
69
+ return this.client.users.resolve(this.userId);
70
+ }
71
+
72
+ /**
73
+ * The member of this presence
74
+ *
75
+ * @type {?GuildMember}
76
+ * @readonly
77
+ */
78
+ get member() {
79
+ return this.guild.members.resolve(this.userId);
80
+ }
81
+
82
+ _patch(data) {
83
+ if ('status' in data) {
84
+ /**
85
+ * The status of this presence
86
+ *
87
+ * @type {PresenceStatus}
88
+ */
89
+ this.status = data.status;
90
+ } else {
91
+ this.status ??= 'offline';
92
+ }
93
+
94
+ if ('activities' in data) {
95
+ /**
96
+ * The activities of this presence
97
+ *
98
+ * @type {Activity[]}
99
+ */
100
+ this.activities = data.activities.map(activity => new Activity(this, activity));
101
+ } else {
102
+ this.activities ??= [];
103
+ }
104
+
105
+ if ('client_status' in data) {
106
+ /**
107
+ * @typedef {Object} ClientPresenceStatusData
108
+ * @property {?ClientPresenceStatus} web The current presence in the web application
109
+ * @property {?ClientPresenceStatus} mobile The current presence in the mobile application
110
+ * @property {?ClientPresenceStatus} desktop The current presence in the desktop application
111
+ */
112
+
113
+ /**
114
+ * The devices this presence is on
115
+ *
116
+ * @type {?ClientPresenceStatusData}
117
+ */
118
+ this.clientStatus = data.client_status;
119
+ } else {
120
+ this.clientStatus ??= null;
121
+ }
122
+
123
+ return this;
124
+ }
125
+
126
+ _clone() {
127
+ const clone = Object.assign(Object.create(this), this);
128
+ clone.activities = this.activities.map(activity => activity._clone());
129
+ return clone;
130
+ }
131
+
132
+ /**
133
+ * Whether this presence is equal to another.
134
+ *
135
+ * @param {Presence} presence The presence to compare with
136
+ * @returns {boolean}
137
+ */
138
+ equals(presence) {
139
+ return (
140
+ this === presence ||
141
+ (presence &&
142
+ this.status === presence.status &&
143
+ this.clientStatus?.web === presence.clientStatus?.web &&
144
+ this.clientStatus?.mobile === presence.clientStatus?.mobile &&
145
+ this.clientStatus?.desktop === presence.clientStatus?.desktop &&
146
+ this.activities.length === presence.activities.length &&
147
+ this.activities.every((activity, index) => activity.equals(presence.activities[index])))
148
+ );
149
+ }
150
+
151
+ toJSON() {
152
+ return flatten(this);
153
+ }
154
+ }
155
+
156
+ /**
157
+ * Represents an activity that is part of a user's presence.
158
+ */
159
+ class Activity {
160
+ constructor(presence, data) {
161
+ /**
162
+ * The presence of the Activity
163
+ *
164
+ * @type {Presence}
165
+ * @readonly
166
+ * @name Activity#presence
167
+ */
168
+ Object.defineProperty(this, 'presence', { value: presence });
169
+
170
+ /**
171
+ * The activity's name
172
+ *
173
+ * @type {string}
174
+ */
175
+ this.name = data.name;
176
+
177
+ /**
178
+ * The activity status's type
179
+ *
180
+ * @type {ActivityType}
181
+ */
182
+ this.type = data.type;
183
+
184
+ /**
185
+ * If the activity is being streamed, a link to the stream
186
+ *
187
+ * @type {?string}
188
+ */
189
+ this.url = data.url ?? null;
190
+
191
+ /**
192
+ * Details about the activity
193
+ *
194
+ * @type {?string}
195
+ */
196
+ this.details = data.details ?? null;
197
+
198
+ /**
199
+ * State of the activity
200
+ *
201
+ * @type {?string}
202
+ */
203
+ this.state = data.state ?? null;
204
+
205
+ /**
206
+ * The id of the application associated with this activity
207
+ *
208
+ * @type {?Snowflake}
209
+ */
210
+ this.applicationId = data.application_id ?? null;
211
+
212
+ /**
213
+ * Represents timestamps of an activity
214
+ *
215
+ * @typedef {Object} ActivityTimestamps
216
+ * @property {?Date} start When the activity started
217
+ * @property {?Date} end When the activity will end
218
+ */
219
+
220
+ /**
221
+ * Timestamps for the activity
222
+ *
223
+ * @type {?ActivityTimestamps}
224
+ */
225
+ this.timestamps = data.timestamps
226
+ ? {
227
+ start: data.timestamps.start ? new Date(Number(data.timestamps.start)) : null,
228
+ end: data.timestamps.end ? new Date(Number(data.timestamps.end)) : null,
229
+ }
230
+ : null;
231
+
232
+ /**
233
+ * Represents a party of an activity
234
+ *
235
+ * @typedef {Object} ActivityParty
236
+ * @property {?string} id The party's id
237
+ * @property {number[]} size Size of the party as `[current, max]`
238
+ */
239
+
240
+ /**
241
+ * Party of the activity
242
+ *
243
+ * @type {?ActivityParty}
244
+ */
245
+ this.party = data.party ?? null;
246
+
247
+ /**
248
+ * The sync id of the activity
249
+ * <info>This property is not documented by Discord and represents the track id in spotify activities.</info>
250
+ *
251
+ * @type {?string}
252
+ */
253
+ this.syncId = data.sync_id ?? null;
254
+
255
+ /**
256
+ * Assets for rich presence
257
+ *
258
+ * @type {?RichPresenceAssets}
259
+ */
260
+ this.assets = data.assets ? new RichPresenceAssets(this, data.assets) : null;
261
+
262
+ /**
263
+ * Flags that describe the activity
264
+ *
265
+ * @type {Readonly<ActivityFlagsBitField>}
266
+ */
267
+ this.flags = new ActivityFlagsBitField(data.flags).freeze();
268
+
269
+ /**
270
+ * Emoji for a custom activity
271
+ *
272
+ * @type {?Emoji}
273
+ */
274
+ this.emoji = data.emoji ? new Emoji(presence.client, data.emoji) : null;
275
+
276
+ /**
277
+ * The labels of the buttons of this rich presence
278
+ *
279
+ * @type {string[]}
280
+ */
281
+ this.buttons = data.buttons ?? [];
282
+
283
+ /**
284
+ * Creation date of the activity
285
+ *
286
+ * @type {number}
287
+ */
288
+ this.createdTimestamp = data.created_at;
289
+ }
290
+
291
+ /**
292
+ * Whether this activity is equal to another activity.
293
+ *
294
+ * @param {Activity} activity The activity to compare with
295
+ * @returns {boolean}
296
+ */
297
+ equals(activity) {
298
+ return (
299
+ this === activity ||
300
+ (activity &&
301
+ this.name === activity.name &&
302
+ this.type === activity.type &&
303
+ this.url === activity.url &&
304
+ this.state === activity.state &&
305
+ this.details === activity.details &&
306
+ this.emoji?.id === activity.emoji?.id &&
307
+ this.emoji?.name === activity.emoji?.name)
308
+ );
309
+ }
310
+
311
+ /**
312
+ * The time the activity was created at
313
+ *
314
+ * @type {Date}
315
+ * @readonly
316
+ */
317
+ get createdAt() {
318
+ return new Date(this.createdTimestamp);
319
+ }
320
+
321
+ /**
322
+ * When concatenated with a string, this automatically returns the activity's name instead of the Activity object.
323
+ *
324
+ * @returns {string}
325
+ */
326
+ toString() {
327
+ return this.name;
328
+ }
329
+
330
+ _clone() {
331
+ return Object.assign(Object.create(this), this);
332
+ }
333
+ }
334
+
335
+ /**
336
+ * Assets for a rich presence
337
+ */
338
+ class RichPresenceAssets {
339
+ constructor(activity, assets) {
340
+ /**
341
+ * The activity of the RichPresenceAssets
342
+ *
343
+ * @type {Activity}
344
+ * @readonly
345
+ * @name RichPresenceAssets#activity
346
+ */
347
+ Object.defineProperty(this, 'activity', { value: activity });
348
+
349
+ /**
350
+ * Hover text for the large image
351
+ *
352
+ * @type {?string}
353
+ */
354
+ this.largeText = assets.large_text ?? null;
355
+
356
+ /**
357
+ * Hover text for the small image
358
+ *
359
+ * @type {?string}
360
+ */
361
+ this.smallText = assets.small_text ?? null;
362
+
363
+ /**
364
+ * The large image asset's id
365
+ *
366
+ * @type {?Snowflake}
367
+ */
368
+ this.largeImage = assets.large_image ?? null;
369
+
370
+ /**
371
+ * The small image asset's id
372
+ *
373
+ * @type {?Snowflake}
374
+ */
375
+ this.smallImage = assets.small_image ?? null;
376
+ }
377
+
378
+ /**
379
+ * Gets the URL of the small image asset
380
+ *
381
+ * @param {ImageURLOptions} [options={}] Options for the image URL
382
+ * @returns {?string}
383
+ */
384
+ smallImageURL(options = {}) {
385
+ if (!this.smallImage) return null;
386
+ if (this.smallImage.includes(':')) {
387
+ const [platform, id] = this.smallImage.split(':');
388
+ switch (platform) {
389
+ case 'mp':
390
+ return `https://media.discordapp.net/${id}`;
391
+ default:
392
+ return null;
393
+ }
394
+ }
395
+
396
+ return this.activity.presence.client.rest.cdn.appAsset(this.activity.applicationId, this.smallImage, options);
397
+ }
398
+
399
+ /**
400
+ * Gets the URL of the large image asset
401
+ *
402
+ * @param {ImageURLOptions} [options={}] Options for the image URL
403
+ * @returns {?string}
404
+ */
405
+ largeImageURL(options = {}) {
406
+ if (!this.largeImage) return null;
407
+ if (this.largeImage.includes(':')) {
408
+ const [platform, id] = this.largeImage.split(':');
409
+ switch (platform) {
410
+ case 'mp':
411
+ return `https://media.discordapp.net/${id}`;
412
+ case 'spotify':
413
+ return `https://i.scdn.co/image/${id}`;
414
+ case 'youtube':
415
+ return `https://i.ytimg.com/vi/${id}/hqdefault_live.jpg`;
416
+ case 'twitch':
417
+ return `https://static-cdn.jtvnw.net/previews-ttv/live_user_${id}.png`;
418
+ default:
419
+ return null;
420
+ }
421
+ }
422
+
423
+ return this.activity.presence.client.rest.cdn.appAsset(this.activity.applicationId, this.largeImage, options);
424
+ }
425
+ }
426
+
427
+ exports.Presence = Presence;
428
+ exports.Activity = Activity;
429
+ exports.RichPresenceAssets = RichPresenceAssets;
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ const { CommandInteraction } = require('./CommandInteraction.js');
4
+
5
+ /**
6
+ * Represents a primary entry point command interaction.
7
+ *
8
+ * @extends {CommandInteraction}
9
+ */
10
+ class PrimaryEntryPointCommandInteraction extends CommandInteraction {}
11
+
12
+ exports.PrimaryEntryPointCommandInteraction = PrimaryEntryPointCommandInteraction;
@@ -0,0 +1,246 @@
1
+ 'use strict';
2
+
3
+ const { Collection } = require('@discordjs/collection');
4
+ const { Events } = require('../util/Events.js');
5
+ const { Collector } = require('./interfaces/Collector.js');
6
+
7
+ /**
8
+ * @typedef {CollectorOptions} ReactionCollectorOptions
9
+ * @property {number} max The maximum total amount of reactions to collect
10
+ * @property {number} maxEmojis The maximum number of emojis to collect
11
+ * @property {number} maxUsers The maximum number of users to react
12
+ */
13
+
14
+ /**
15
+ * Collects reactions on messages.
16
+ * Will automatically stop if the message ({@link Client#event:messageDelete messageDelete} or
17
+ * {@link Client#event:messageDeleteBulk messageDeleteBulk}),
18
+ * channel ({@link Client#event:channelDelete channelDelete}),
19
+ * thread ({@link Client#event:threadDelete threadDelete}), or
20
+ * guild ({@link Client#event:guildDelete guildDelete}) is deleted.
21
+ *
22
+ * @extends {Collector}
23
+ */
24
+ class ReactionCollector extends Collector {
25
+ /**
26
+ * @param {Message} message The message upon which to collect reactions
27
+ * @param {ReactionCollectorOptions} [options={}] The options to apply to this collector
28
+ */
29
+ constructor(message, options = {}) {
30
+ super(message.client, options);
31
+
32
+ /**
33
+ * The message upon which to collect reactions
34
+ *
35
+ * @type {Message}
36
+ */
37
+ this.message = message;
38
+
39
+ /**
40
+ * The users that have reacted to this message
41
+ *
42
+ * @type {Collection}
43
+ */
44
+ this.users = new Collection();
45
+
46
+ /**
47
+ * The total number of reactions collected
48
+ *
49
+ * @type {number}
50
+ */
51
+ this.total = 0;
52
+
53
+ this.empty = this.empty.bind(this);
54
+ this._handleChannelDeletion = this._handleChannelDeletion.bind(this);
55
+ this._handleThreadDeletion = this._handleThreadDeletion.bind(this);
56
+ this._handleGuildDeletion = this._handleGuildDeletion.bind(this);
57
+ this._handleMessageDeletion = this._handleMessageDeletion.bind(this);
58
+
59
+ const bulkDeleteListener = messages => {
60
+ if (messages.has(this.message.id)) this.stop('messageDelete');
61
+ };
62
+
63
+ this.client.incrementMaxListeners();
64
+ this.client.on(Events.MessageReactionAdd, this.handleCollect);
65
+ this.client.on(Events.MessageReactionRemove, this.handleDispose);
66
+ this.client.on(Events.MessageReactionRemoveAll, this.empty);
67
+ this.client.on(Events.MessageDelete, this._handleMessageDeletion);
68
+ this.client.on(Events.MessageBulkDelete, bulkDeleteListener);
69
+ this.client.on(Events.ChannelDelete, this._handleChannelDeletion);
70
+ this.client.on(Events.ThreadDelete, this._handleThreadDeletion);
71
+ this.client.on(Events.GuildDelete, this._handleGuildDeletion);
72
+
73
+ this.once('end', () => {
74
+ this.client.removeListener(Events.MessageReactionAdd, this.handleCollect);
75
+ this.client.removeListener(Events.MessageReactionRemove, this.handleDispose);
76
+ this.client.removeListener(Events.MessageReactionRemoveAll, this.empty);
77
+ this.client.removeListener(Events.MessageDelete, this._handleMessageDeletion);
78
+ this.client.removeListener(Events.MessageBulkDelete, bulkDeleteListener);
79
+ this.client.removeListener(Events.ChannelDelete, this._handleChannelDeletion);
80
+ this.client.removeListener(Events.ThreadDelete, this._handleThreadDeletion);
81
+ this.client.removeListener(Events.GuildDelete, this._handleGuildDeletion);
82
+ this.client.decrementMaxListeners();
83
+ });
84
+
85
+ this.on('collect', (reaction, user) => {
86
+ /**
87
+ * Emitted whenever a reaction is newly created on a message. Will emit only when a new reaction is
88
+ * added to the message, as opposed to {@link Collector#event:collect} which will
89
+ * be emitted even when a reaction has already been added to the message.
90
+ *
91
+ * @event ReactionCollector#create
92
+ * @param {MessageReaction} reaction The reaction that was added
93
+ * @param {User} user The user that added the reaction
94
+ */
95
+ if (reaction.count === 1) {
96
+ this.emit('create', reaction, user);
97
+ }
98
+
99
+ this.total++;
100
+ this.users.set(user.id, user);
101
+ });
102
+
103
+ this.on('remove', (_reaction, user) => {
104
+ this.total--;
105
+ if (!this.collected.some(reaction => reaction.users.cache.has(user.id))) this.users.delete(user.id);
106
+ });
107
+ }
108
+
109
+ /**
110
+ * Handles an incoming reaction for possible collection.
111
+ *
112
+ * @param {MessageReaction} reaction The reaction to possibly collect
113
+ * @returns {?(Snowflake|string)}
114
+ * @private
115
+ */
116
+ collect(reaction) {
117
+ /**
118
+ * Emitted whenever a reaction is collected.
119
+ *
120
+ * @event ReactionCollector#collect
121
+ * @param {MessageReaction} reaction The reaction that was collected
122
+ * @param {User} user The user that added the reaction
123
+ */
124
+ if (reaction.message.id !== this.message.id) return null;
125
+
126
+ return ReactionCollector.key(reaction);
127
+ }
128
+
129
+ /**
130
+ * Handles a reaction deletion for possible disposal.
131
+ *
132
+ * @param {MessageReaction} reaction The reaction to possibly dispose of
133
+ * @param {User} user The user that removed the reaction
134
+ * @returns {?(Snowflake|string)}
135
+ */
136
+ dispose(reaction, user) {
137
+ /**
138
+ * Emitted when the reaction had all the users removed and the `dispose` option is set to true.
139
+ *
140
+ * @event ReactionCollector#dispose
141
+ * @param {MessageReaction} reaction The reaction that was disposed of
142
+ * @param {User} user The user that removed the reaction
143
+ */
144
+ if (reaction.message.id !== this.message.id) return null;
145
+
146
+ /**
147
+ * Emitted when the reaction had one user removed and the `dispose` option is set to true.
148
+ *
149
+ * @event ReactionCollector#remove
150
+ * @param {MessageReaction} reaction The reaction that was removed
151
+ * @param {User} user The user that removed the reaction
152
+ */
153
+ if (this.collected.has(ReactionCollector.key(reaction)) && this.users.has(user.id)) {
154
+ this.emit('remove', reaction, user);
155
+ }
156
+
157
+ return reaction.count ? null : ReactionCollector.key(reaction);
158
+ }
159
+
160
+ /**
161
+ * Empties this reaction collector.
162
+ */
163
+ empty() {
164
+ this.total = 0;
165
+ this.collected.clear();
166
+ this.users.clear();
167
+ this.checkEnd();
168
+ }
169
+
170
+ /**
171
+ * The reason this collector has ended with, or null if it hasn't ended yet
172
+ *
173
+ * @type {?string}
174
+ * @readonly
175
+ */
176
+ get endReason() {
177
+ if (this.options.max && this.total >= this.options.max) return 'limit';
178
+ if (this.options.maxEmojis && this.collected.size >= this.options.maxEmojis) return 'emojiLimit';
179
+ if (this.options.maxUsers && this.users.size >= this.options.maxUsers) return 'userLimit';
180
+ return super.endReason;
181
+ }
182
+
183
+ /**
184
+ * Handles checking if the message has been deleted, and if so, stops the collector with the reason 'messageDelete'.
185
+ *
186
+ * @private
187
+ * @param {Message} message The message that was deleted
188
+ * @returns {void}
189
+ */
190
+ _handleMessageDeletion(message) {
191
+ if (message.id === this.message.id) {
192
+ this.stop('messageDelete');
193
+ }
194
+ }
195
+
196
+ /**
197
+ * Handles checking if the channel has been deleted, and if so, stops the collector with the reason 'channelDelete'.
198
+ *
199
+ * @private
200
+ * @param {GuildChannel} channel The channel that was deleted
201
+ * @returns {void}
202
+ */
203
+ _handleChannelDeletion(channel) {
204
+ if (channel.id === this.message.channelId || channel.threads?.cache.has(this.message.channelId)) {
205
+ this.stop('channelDelete');
206
+ }
207
+ }
208
+
209
+ /**
210
+ * Handles checking if the thread has been deleted, and if so, stops the collector with the reason 'threadDelete'.
211
+ *
212
+ * @private
213
+ * @param {ThreadChannel} thread The thread that was deleted
214
+ * @returns {void}
215
+ */
216
+ _handleThreadDeletion(thread) {
217
+ if (thread.id === this.message.channelId) {
218
+ this.stop('threadDelete');
219
+ }
220
+ }
221
+
222
+ /**
223
+ * Handles checking if the guild has been deleted, and if so, stops the collector with the reason 'guildDelete'.
224
+ *
225
+ * @private
226
+ * @param {Guild} guild The guild that was deleted
227
+ * @returns {void}
228
+ */
229
+ _handleGuildDeletion(guild) {
230
+ if (guild.id === this.message.guild?.id) {
231
+ this.stop('guildDelete');
232
+ }
233
+ }
234
+
235
+ /**
236
+ * Gets the collector key for a reaction.
237
+ *
238
+ * @param {MessageReaction} reaction The message reaction to get the key for
239
+ * @returns {Snowflake|string}
240
+ */
241
+ static key(reaction) {
242
+ return reaction.emoji.id ?? reaction.emoji.name;
243
+ }
244
+ }
245
+
246
+ exports.ReactionCollector = ReactionCollector;
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+
3
+ const { flatten } = require('../util/Util.js');
4
+ const { Emoji } = require('./Emoji.js');
5
+
6
+ /**
7
+ * Represents a limited emoji set used for both custom and unicode emojis. Custom emojis
8
+ * will use this class opposed to the Emoji class when the client doesn't know enough
9
+ * information about them.
10
+ *
11
+ * @extends {Emoji}
12
+ */
13
+ class ReactionEmoji extends Emoji {
14
+ constructor(reaction, emoji) {
15
+ super(reaction.message.client, emoji);
16
+ /**
17
+ * The message reaction this emoji refers to
18
+ *
19
+ * @type {MessageReaction}
20
+ */
21
+ this.reaction = reaction;
22
+ }
23
+
24
+ toJSON() {
25
+ return flatten(this, { identifier: true });
26
+ }
27
+
28
+ valueOf() {
29
+ return this.id;
30
+ }
31
+ }
32
+
33
+ exports.ReactionEmoji = ReactionEmoji;