@ovencord/discord.js 14.16.3

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 (332) hide show
  1. package/LICENSE +191 -0
  2. package/README.md +148 -0
  3. package/package.json +73 -0
  4. package/src/client/Client.ts +967 -0
  5. package/src/client/actions/Action.ts +141 -0
  6. package/src/client/actions/ActionsManager.ts +138 -0
  7. package/src/client/actions/ChannelCreate.ts +21 -0
  8. package/src/client/actions/ChannelDelete.ts +20 -0
  9. package/src/client/actions/ChannelUpdate.ts +38 -0
  10. package/src/client/actions/GuildChannelsPositionUpdate.ts +17 -0
  11. package/src/client/actions/GuildEmojiCreate.ts +17 -0
  12. package/src/client/actions/GuildEmojiDelete.ts +16 -0
  13. package/src/client/actions/GuildEmojiUpdate.ts +17 -0
  14. package/src/client/actions/GuildEmojisUpdate.ts +30 -0
  15. package/src/client/actions/GuildMemberRemove.ts +29 -0
  16. package/src/client/actions/GuildMemberUpdate.ts +41 -0
  17. package/src/client/actions/GuildRoleCreate.ts +23 -0
  18. package/src/client/actions/GuildRoleDelete.ts +26 -0
  19. package/src/client/actions/GuildRolesPositionUpdate.ts +17 -0
  20. package/src/client/actions/GuildScheduledEventDelete.ts +28 -0
  21. package/src/client/actions/GuildScheduledEventUserAdd.ts +29 -0
  22. package/src/client/actions/GuildScheduledEventUserRemove.ts +29 -0
  23. package/src/client/actions/GuildSoundboardSoundDelete.ts +26 -0
  24. package/src/client/actions/GuildStickerCreate.ts +17 -0
  25. package/src/client/actions/GuildStickerDelete.ts +16 -0
  26. package/src/client/actions/GuildStickerUpdate.ts +17 -0
  27. package/src/client/actions/GuildStickersUpdate.ts +30 -0
  28. package/src/client/actions/GuildUpdate.ts +30 -0
  29. package/src/client/actions/InteractionCreate.ts +104 -0
  30. package/src/client/actions/MessageCreate.ts +38 -0
  31. package/src/client/actions/MessageDelete.ts +29 -0
  32. package/src/client/actions/MessageDeleteBulk.ts +45 -0
  33. package/src/client/actions/MessagePollVoteAdd.ts +37 -0
  34. package/src/client/actions/MessagePollVoteRemove.ts +35 -0
  35. package/src/client/actions/MessageReactionAdd.ts +68 -0
  36. package/src/client/actions/MessageReactionRemove.ts +47 -0
  37. package/src/client/actions/MessageReactionRemoveAll.ts +30 -0
  38. package/src/client/actions/MessageReactionRemoveEmoji.ts +25 -0
  39. package/src/client/actions/MessageUpdate.ts +22 -0
  40. package/src/client/actions/StageInstanceCreate.ts +25 -0
  41. package/src/client/actions/StageInstanceDelete.ts +28 -0
  42. package/src/client/actions/StageInstanceUpdate.ts +27 -0
  43. package/src/client/actions/ThreadCreate.ts +22 -0
  44. package/src/client/actions/ThreadMembersUpdate.ts +45 -0
  45. package/src/client/actions/TypingStart.ts +26 -0
  46. package/src/client/actions/UserUpdate.ts +33 -0
  47. package/src/client/voice/ClientVoiceManager.ts +46 -0
  48. package/src/client/websocket/handlers/APPLICATION_COMMAND_PERMISSIONS_UPDATE.ts +19 -0
  49. package/src/client/websocket/handlers/AUTO_MODERATION_ACTION_EXECUTION.ts +17 -0
  50. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_CREATE.ts +18 -0
  51. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_DELETE.ts +21 -0
  52. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_UPDATE.ts +20 -0
  53. package/src/client/websocket/handlers/CHANNEL_CREATE.ts +4 -0
  54. package/src/client/websocket/handlers/CHANNEL_DELETE.ts +4 -0
  55. package/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.ts +22 -0
  56. package/src/client/websocket/handlers/CHANNEL_UPDATE.ts +16 -0
  57. package/src/client/websocket/handlers/ENTITLEMENT_CREATE.ts +14 -0
  58. package/src/client/websocket/handlers/ENTITLEMENT_DELETE.ts +18 -0
  59. package/src/client/websocket/handlers/ENTITLEMENT_UPDATE.ts +16 -0
  60. package/src/client/websocket/handlers/GUILD_AUDIT_LOG_ENTRY_CREATE.ts +19 -0
  61. package/src/client/websocket/handlers/GUILD_BAN_ADD.ts +15 -0
  62. package/src/client/websocket/handlers/GUILD_BAN_REMOVE.ts +20 -0
  63. package/src/client/websocket/handlers/GUILD_CREATE.ts +34 -0
  64. package/src/client/websocket/handlers/GUILD_DELETE.ts +36 -0
  65. package/src/client/websocket/handlers/GUILD_EMOJIS_UPDATE.ts +4 -0
  66. package/src/client/websocket/handlers/GUILD_INTEGRATIONS_UPDATE.ts +15 -0
  67. package/src/client/websocket/handlers/GUILD_MEMBERS_CHUNK.ts +40 -0
  68. package/src/client/websocket/handlers/GUILD_MEMBER_ADD.ts +17 -0
  69. package/src/client/websocket/handlers/GUILD_MEMBER_REMOVE.ts +4 -0
  70. package/src/client/websocket/handlers/GUILD_MEMBER_UPDATE.ts +4 -0
  71. package/src/client/websocket/handlers/GUILD_ROLE_CREATE.ts +4 -0
  72. package/src/client/websocket/handlers/GUILD_ROLE_DELETE.ts +4 -0
  73. package/src/client/websocket/handlers/GUILD_ROLE_UPDATE.ts +21 -0
  74. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_CREATE.ts +17 -0
  75. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_DELETE.ts +4 -0
  76. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_UPDATE.ts +19 -0
  77. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_ADD.ts +4 -0
  78. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_REMOVE.ts +4 -0
  79. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUNDS_UPDATE.ts +24 -0
  80. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_CREATE.ts +18 -0
  81. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_DELETE.ts +4 -0
  82. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_UPDATE.ts +20 -0
  83. package/src/client/websocket/handlers/GUILD_STICKERS_UPDATE.ts +4 -0
  84. package/src/client/websocket/handlers/GUILD_UPDATE.ts +4 -0
  85. package/src/client/websocket/handlers/INTERACTION_CREATE.ts +4 -0
  86. package/src/client/websocket/handlers/INVITE_CREATE.ts +20 -0
  87. package/src/client/websocket/handlers/INVITE_DELETE.ts +23 -0
  88. package/src/client/websocket/handlers/MESSAGE_CREATE.ts +4 -0
  89. package/src/client/websocket/handlers/MESSAGE_DELETE.ts +4 -0
  90. package/src/client/websocket/handlers/MESSAGE_DELETE_BULK.ts +4 -0
  91. package/src/client/websocket/handlers/MESSAGE_POLL_VOTE_ADD.ts +4 -0
  92. package/src/client/websocket/handlers/MESSAGE_POLL_VOTE_REMOVE.ts +4 -0
  93. package/src/client/websocket/handlers/MESSAGE_REACTION_ADD.ts +4 -0
  94. package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE.ts +4 -0
  95. package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_ALL.ts +4 -0
  96. package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_EMOJI.ts +4 -0
  97. package/src/client/websocket/handlers/MESSAGE_UPDATE.ts +16 -0
  98. package/src/client/websocket/handlers/PRESENCE_UPDATE.ts +42 -0
  99. package/src/client/websocket/handlers/RATE_LIMITED.ts +23 -0
  100. package/src/client/websocket/handlers/READY.ts +29 -0
  101. package/src/client/websocket/handlers/SOUNDBOARD_SOUNDS.ts +24 -0
  102. package/src/client/websocket/handlers/STAGE_INSTANCE_CREATE.ts +4 -0
  103. package/src/client/websocket/handlers/STAGE_INSTANCE_DELETE.ts +4 -0
  104. package/src/client/websocket/handlers/STAGE_INSTANCE_UPDATE.ts +4 -0
  105. package/src/client/websocket/handlers/SUBSCRIPTION_CREATE.ts +14 -0
  106. package/src/client/websocket/handlers/SUBSCRIPTION_DELETE.ts +16 -0
  107. package/src/client/websocket/handlers/SUBSCRIPTION_UPDATE.ts +16 -0
  108. package/src/client/websocket/handlers/THREAD_CREATE.ts +4 -0
  109. package/src/client/websocket/handlers/THREAD_DELETE.ts +17 -0
  110. package/src/client/websocket/handlers/THREAD_LIST_SYNC.ts +50 -0
  111. package/src/client/websocket/handlers/THREAD_MEMBERS_UPDATE.ts +4 -0
  112. package/src/client/websocket/handlers/THREAD_MEMBER_UPDATE.ts +25 -0
  113. package/src/client/websocket/handlers/THREAD_UPDATE.ts +16 -0
  114. package/src/client/websocket/handlers/TYPING_START.ts +4 -0
  115. package/src/client/websocket/handlers/USER_UPDATE.ts +4 -0
  116. package/src/client/websocket/handlers/VOICE_CHANNEL_EFFECT_SEND.ts +16 -0
  117. package/src/client/websocket/handlers/VOICE_SERVER_UPDATE.ts +5 -0
  118. package/src/client/websocket/handlers/VOICE_STATE_UPDATE.ts +37 -0
  119. package/src/client/websocket/handlers/WEBHOOKS_UPDATE.ts +16 -0
  120. package/src/client/websocket/handlers/index.ts +74 -0
  121. package/src/errors/DJSError.ts +50 -0
  122. package/src/errors/ErrorCodes.ts +277 -0
  123. package/src/errors/Messages.ts +155 -0
  124. package/src/errors/index.ts +6 -0
  125. package/src/index.ts +241 -0
  126. package/src/managers/ApplicationCommandManager.ts +303 -0
  127. package/src/managers/ApplicationCommandPermissionsManager.ts +453 -0
  128. package/src/managers/ApplicationEmojiManager.ts +149 -0
  129. package/src/managers/AutoModerationRuleManager.ts +307 -0
  130. package/src/managers/BaseManager.ts +13 -0
  131. package/src/managers/CachedManager.ts +56 -0
  132. package/src/managers/CategoryChannelChildManager.ts +81 -0
  133. package/src/managers/ChannelManager.ts +194 -0
  134. package/src/managers/DMMessageManager.ts +15 -0
  135. package/src/managers/DataManager.ts +38 -0
  136. package/src/managers/EntitlementManager.ts +182 -0
  137. package/src/managers/GuildApplicationCommandManager.ts +29 -0
  138. package/src/managers/GuildBanManager.ts +221 -0
  139. package/src/managers/GuildChannelManager.ts +552 -0
  140. package/src/managers/GuildEmojiManager.ts +262 -0
  141. package/src/managers/GuildEmojiRoleManager.ts +134 -0
  142. package/src/managers/GuildForumThreadManager.ts +84 -0
  143. package/src/managers/GuildInviteManager.ts +236 -0
  144. package/src/managers/GuildManager.ts +265 -0
  145. package/src/managers/GuildMemberManager.ts +619 -0
  146. package/src/managers/GuildMemberRoleManager.ts +230 -0
  147. package/src/managers/GuildMessageManager.ts +31 -0
  148. package/src/managers/GuildScheduledEventManager.ts +330 -0
  149. package/src/managers/GuildSoundboardSoundManager.ts +157 -0
  150. package/src/managers/GuildStickerManager.ts +192 -0
  151. package/src/managers/GuildTextThreadManager.ts +91 -0
  152. package/src/managers/MessageManager.ts +352 -0
  153. package/src/managers/PartialGroupDMMessageManager.ts +15 -0
  154. package/src/managers/PermissionOverwriteManager.ts +174 -0
  155. package/src/managers/PollAnswerVoterManager.ts +59 -0
  156. package/src/managers/PresenceManager.ts +60 -0
  157. package/src/managers/ReactionManager.ts +72 -0
  158. package/src/managers/ReactionUserManager.ts +82 -0
  159. package/src/managers/RoleManager.ts +432 -0
  160. package/src/managers/StageInstanceManager.ts +166 -0
  161. package/src/managers/SubscriptionManager.ts +83 -0
  162. package/src/managers/ThreadManager.ts +210 -0
  163. package/src/managers/ThreadMemberManager.ts +194 -0
  164. package/src/managers/UserManager.ts +139 -0
  165. package/src/managers/VoiceStateManager.ts +61 -0
  166. package/src/sharding/Shard.ts +513 -0
  167. package/src/sharding/ShardClientUtil.ts +293 -0
  168. package/src/sharding/ShardingManager.ts +374 -0
  169. package/src/structures/ActionRow.ts +31 -0
  170. package/src/structures/AnnouncementChannel.ts +25 -0
  171. package/src/structures/AnonymousGuild.ts +110 -0
  172. package/src/structures/ApplicationCommand.ts +675 -0
  173. package/src/structures/ApplicationEmoji.ts +189 -0
  174. package/src/structures/ApplicationRoleConnectionMetadata.ts +54 -0
  175. package/src/structures/Attachment.ts +189 -0
  176. package/src/structures/AuthorizingIntegrationOwners.ts +63 -0
  177. package/src/structures/AutoModerationActionExecution.ts +138 -0
  178. package/src/structures/AutoModerationRule.ts +325 -0
  179. package/src/structures/AutocompleteInteraction.ts +115 -0
  180. package/src/structures/Base.ts +37 -0
  181. package/src/structures/BaseChannel.ts +188 -0
  182. package/src/structures/BaseGuild.ts +134 -0
  183. package/src/structures/BaseGuildEmoji.ts +113 -0
  184. package/src/structures/BaseGuildTextChannel.ts +230 -0
  185. package/src/structures/BaseGuildVoiceChannel.ts +270 -0
  186. package/src/structures/BaseInteraction.ts +393 -0
  187. package/src/structures/BaseInvite.ts +192 -0
  188. package/src/structures/BaseSelectMenuComponent.ts +58 -0
  189. package/src/structures/ButtonComponent.ts +68 -0
  190. package/src/structures/ButtonInteraction.ts +8 -0
  191. package/src/structures/CategoryChannel.ts +46 -0
  192. package/src/structures/ChannelSelectMenuComponent.ts +18 -0
  193. package/src/structures/ChannelSelectMenuInteraction.ts +34 -0
  194. package/src/structures/ChatInputCommandInteraction.ts +43 -0
  195. package/src/structures/ClientApplication.ts +470 -0
  196. package/src/structures/ClientPresence.ts +87 -0
  197. package/src/structures/ClientUser.ts +219 -0
  198. package/src/structures/CommandInteraction.ts +193 -0
  199. package/src/structures/CommandInteractionOptionResolver.ts +336 -0
  200. package/src/structures/Component.ts +59 -0
  201. package/src/structures/ContainerComponent.ts +63 -0
  202. package/src/structures/ContextMenuCommandInteraction.ts +68 -0
  203. package/src/structures/DMChannel.ts +148 -0
  204. package/src/structures/DirectoryChannel.ts +40 -0
  205. package/src/structures/Embed.ts +251 -0
  206. package/src/structures/Emoji.ts +61 -0
  207. package/src/structures/Entitlement.ts +206 -0
  208. package/src/structures/FileComponent.ts +41 -0
  209. package/src/structures/ForumChannel.ts +31 -0
  210. package/src/structures/GroupDMInvite.ts +34 -0
  211. package/src/structures/Guild.ts +1605 -0
  212. package/src/structures/GuildAuditLogs.ts +99 -0
  213. package/src/structures/GuildAuditLogsEntry.ts +557 -0
  214. package/src/structures/GuildBan.ts +65 -0
  215. package/src/structures/GuildChannel.ts +515 -0
  216. package/src/structures/GuildEmoji.ts +159 -0
  217. package/src/structures/GuildInvite.ts +233 -0
  218. package/src/structures/GuildMember.ts +643 -0
  219. package/src/structures/GuildOnboarding.ts +73 -0
  220. package/src/structures/GuildOnboardingPrompt.ts +93 -0
  221. package/src/structures/GuildOnboardingPromptOption.ts +100 -0
  222. package/src/structures/GuildPreview.ts +218 -0
  223. package/src/structures/GuildPreviewEmoji.ts +28 -0
  224. package/src/structures/GuildScheduledEvent.ts +593 -0
  225. package/src/structures/GuildTemplate.ts +229 -0
  226. package/src/structures/Integration.ts +257 -0
  227. package/src/structures/IntegrationApplication.ts +84 -0
  228. package/src/structures/InteractionCallback.ts +86 -0
  229. package/src/structures/InteractionCallbackResource.ts +57 -0
  230. package/src/structures/InteractionCallbackResponse.ts +35 -0
  231. package/src/structures/InteractionCollector.ts +260 -0
  232. package/src/structures/InteractionWebhook.ts +65 -0
  233. package/src/structures/InviteGuild.ts +22 -0
  234. package/src/structures/LabelComponent.ts +51 -0
  235. package/src/structures/MediaChannel.ts +8 -0
  236. package/src/structures/MediaGalleryComponent.ts +31 -0
  237. package/src/structures/MediaGalleryItem.ts +54 -0
  238. package/src/structures/MentionableSelectMenuComponent.ts +8 -0
  239. package/src/structures/MentionableSelectMenuInteraction.ts +76 -0
  240. package/src/structures/Message.ts +1202 -0
  241. package/src/structures/MessageCollector.ts +155 -0
  242. package/src/structures/MessageComponentInteraction.ts +132 -0
  243. package/src/structures/MessageContextMenuCommandInteraction.ts +18 -0
  244. package/src/structures/MessageMentions.ts +327 -0
  245. package/src/structures/MessagePayload.ts +325 -0
  246. package/src/structures/MessageReaction.ts +219 -0
  247. package/src/structures/ModalComponentResolver.ts +237 -0
  248. package/src/structures/ModalSubmitInteraction.ts +260 -0
  249. package/src/structures/OAuth2Guild.ts +30 -0
  250. package/src/structures/PartialGroupDMChannel.ts +151 -0
  251. package/src/structures/PermissionOverwrites.ts +222 -0
  252. package/src/structures/Poll.ts +195 -0
  253. package/src/structures/PollAnswer.ts +100 -0
  254. package/src/structures/Presence.ts +448 -0
  255. package/src/structures/PrimaryEntryPointCommandInteraction.ts +8 -0
  256. package/src/structures/ReactionCollector.ts +245 -0
  257. package/src/structures/ReactionEmoji.ts +30 -0
  258. package/src/structures/Role.ts +543 -0
  259. package/src/structures/RoleSelectMenuComponent.ts +8 -0
  260. package/src/structures/RoleSelectMenuInteraction.ts +34 -0
  261. package/src/structures/SKU.ts +62 -0
  262. package/src/structures/SectionComponent.ts +44 -0
  263. package/src/structures/SeparatorComponent.ts +29 -0
  264. package/src/structures/SoundboardSound.ts +176 -0
  265. package/src/structures/StageChannel.ts +118 -0
  266. package/src/structures/StageInstance.ts +173 -0
  267. package/src/structures/Sticker.ts +300 -0
  268. package/src/structures/StickerPack.ts +111 -0
  269. package/src/structures/StringSelectMenuComponent.ts +18 -0
  270. package/src/structures/StringSelectMenuInteraction.ts +21 -0
  271. package/src/structures/Subscription.ts +138 -0
  272. package/src/structures/Team.ts +131 -0
  273. package/src/structures/TeamMember.ts +77 -0
  274. package/src/structures/TextChannel.ts +33 -0
  275. package/src/structures/TextDisplayComponent.ts +18 -0
  276. package/src/structures/TextInputComponent.ts +28 -0
  277. package/src/structures/ThreadChannel.ts +680 -0
  278. package/src/structures/ThreadMember.ts +125 -0
  279. package/src/structures/ThreadOnlyChannel.ts +276 -0
  280. package/src/structures/ThumbnailComponent.ts +51 -0
  281. package/src/structures/Typing.ts +81 -0
  282. package/src/structures/UnfurledMediaItem.ts +33 -0
  283. package/src/structures/User.ts +511 -0
  284. package/src/structures/UserContextMenuCommandInteraction.ts +28 -0
  285. package/src/structures/UserSelectMenuComponent.ts +8 -0
  286. package/src/structures/UserSelectMenuInteraction.ts +54 -0
  287. package/src/structures/VoiceChannel.ts +119 -0
  288. package/src/structures/VoiceChannelEffect.ts +92 -0
  289. package/src/structures/VoiceRegion.ts +52 -0
  290. package/src/structures/VoiceState.ts +346 -0
  291. package/src/structures/Webhook.ts +526 -0
  292. package/src/structures/WelcomeChannel.ts +67 -0
  293. package/src/structures/WelcomeScreen.ts +53 -0
  294. package/src/structures/Widget.ts +110 -0
  295. package/src/structures/WidgetMember.ts +124 -0
  296. package/src/structures/interfaces/Application.ts +179 -0
  297. package/src/structures/interfaces/Collector.ts +372 -0
  298. package/src/structures/interfaces/InteractionResponses.ts +384 -0
  299. package/src/structures/interfaces/TextBasedChannel.ts +430 -0
  300. package/src/util/APITypes.ts +690 -0
  301. package/src/util/ActivityFlagsBitField.ts +26 -0
  302. package/src/util/ApplicationFlagsBitField.ts +43 -0
  303. package/src/util/AttachmentFlagsBitField.ts +26 -0
  304. package/src/util/BitField.ts +178 -0
  305. package/src/util/ChannelFlagsBitField.ts +43 -0
  306. package/src/util/Channels.ts +165 -0
  307. package/src/util/Colors.ts +72 -0
  308. package/src/util/Components.ts +285 -0
  309. package/src/util/Constants.ts +251 -0
  310. package/src/util/DataResolver.ts +146 -0
  311. package/src/util/Enums.ts +10 -0
  312. package/src/util/Events.ts +178 -0
  313. package/src/util/GuildMemberFlagsBitField.ts +43 -0
  314. package/src/util/IntentsBitField.ts +35 -0
  315. package/src/util/InviteFlagsBitField.ts +26 -0
  316. package/src/util/Invites.ts +27 -0
  317. package/src/util/LimitedCollection.ts +73 -0
  318. package/src/util/MessageFlagsBitField.ts +43 -0
  319. package/src/util/Options.ts +215 -0
  320. package/src/util/Partials.ts +50 -0
  321. package/src/util/PermissionsBitField.ts +113 -0
  322. package/src/util/RoleFlagsBitField.ts +26 -0
  323. package/src/util/SKUFlagsBitField.ts +26 -0
  324. package/src/util/ShardEvents.ts +26 -0
  325. package/src/util/Status.ts +16 -0
  326. package/src/util/Sweepers.ts +532 -0
  327. package/src/util/Symbols.ts +1 -0
  328. package/src/util/SystemChannelFlagsBitField.ts +45 -0
  329. package/src/util/ThreadMemberFlagsBitField.ts +33 -0
  330. package/src/util/Transformers.ts +123 -0
  331. package/src/util/UserFlagsBitField.ts +33 -0
  332. package/src/util/Util.ts +519 -0
@@ -0,0 +1,352 @@
1
+ import { Collection } from '@ovencord/collection';
2
+ import { makeURLSearchParams } from '@ovencord/rest';
3
+ import { isFileBodyEncodable, isJSONEncodable } from '@ovencord/util';
4
+ import { Routes } from 'discord-api-types/v10';
5
+ import { DiscordjsTypeError, ErrorCodes } from '../errors/index.js';
6
+ import { Message } from '../structures/Message.js';
7
+ import { MessagePayload } from '../structures/MessagePayload.js';
8
+ import { MakeCacheOverrideSymbol } from '../util/Symbols.js';
9
+ import { resolvePartialEmoji } from '../util/Util.js';
10
+ import { CachedManager } from './CachedManager.js';
11
+
12
+ /**
13
+ * Manages API methods for Messages and holds their cache.
14
+ *
15
+ * @extends {CachedManager}
16
+ * @abstract
17
+ */
18
+ export class MessageManager extends CachedManager {
19
+ public channel: any;
20
+ static [MakeCacheOverrideSymbol] = MessageManager;
21
+
22
+ constructor(channel, iterable) {
23
+ super(channel.client, Message, iterable);
24
+
25
+ /**
26
+ * The channel that the messages belong to
27
+ *
28
+ * @type {TextBasedChannels}
29
+ */
30
+ this.channel = channel;
31
+ }
32
+
33
+ /**
34
+ * The cache of Messages
35
+ *
36
+ * @type {Collection<Snowflake, Message>}
37
+ * @name MessageManager#cache
38
+ */
39
+
40
+ _add(data, cache) {
41
+ return super._add(data, cache);
42
+ }
43
+
44
+ /**
45
+ * Data that can be resolved to a Message object. This can be:
46
+ * - A Message
47
+ * - A Snowflake
48
+ *
49
+ * @typedef {Message|Snowflake} MessageResolvable
50
+ */
51
+
52
+ /**
53
+ * Options used to fetch a message.
54
+ *
55
+ * @typedef {BaseFetchOptions} FetchMessageOptions
56
+ * @property {MessageResolvable} message The message to fetch
57
+ */
58
+
59
+ /**
60
+ * Options used to fetch multiple messages.
61
+ * <info>The `before`, `after`, and `around` parameters are mutually exclusive.</info>
62
+ *
63
+ * @typedef {Object} FetchMessagesOptions
64
+ * @property {number} [limit] The maximum number of messages to return
65
+ * @property {Snowflake} [before] Consider only messages before this id
66
+ * @property {Snowflake} [after] Consider only messages after this id
67
+ * @property {Snowflake} [around] Consider only messages around this id
68
+ * @property {boolean} [cache] Whether to cache the fetched messages
69
+ */
70
+
71
+ /**
72
+ * Fetches message(s) from a channel.
73
+ * <info>The returned Collection does not contain reaction users of the messages if they were not cached.
74
+ * Those need to be fetched separately in such a case.</info>
75
+ *
76
+ * @param {MessageResolvable|FetchMessageOptions|FetchMessagesOptions} [options] Options for fetching message(s)
77
+ * @returns {Promise<Message|Collection<Snowflake, Message>>}
78
+ * @example
79
+ * // Fetch a message
80
+ * channel.messages.fetch('99539446449315840')
81
+ * .then(message => console.log(message.content))
82
+ * .catch(console.error);
83
+ * @example
84
+ * // Fetch a maximum of 10 messages without caching
85
+ * channel.messages.fetch({ limit: 10, cache: false })
86
+ * .then(messages => console.log(`Received ${messages.size} messages`))
87
+ * .catch(console.error);
88
+ * @example
89
+ * // Fetch a maximum of 10 messages without caching around a message id
90
+ * channel.messages.fetch({ limit: 10, cache: false, around: '99539446449315840' })
91
+ * .then(messages => console.log(`Received ${messages.size} messages`))
92
+ * .catch(console.error);
93
+ * @example
94
+ * // Fetch messages and filter by a user id
95
+ * channel.messages.fetch()
96
+ * .then(messages => console.log(`${messages.filter(message =>
97
+ * message.author.id === '84484653687267328').size} messages`))
98
+ * .catch(console.error);
99
+ */
100
+ async fetch(options) {
101
+ if (!options) return this._fetchMany();
102
+ const { message, cache, force } = options;
103
+ const resolvedMessage = this.resolveId(message ?? options);
104
+ if (resolvedMessage) return this._fetchSingle({ message: resolvedMessage, cache, force });
105
+ return this._fetchMany(options);
106
+ }
107
+
108
+ async _fetchSingle({ message, cache, force = false }) {
109
+ if (!force) {
110
+ const existing = this.cache.get(message);
111
+ if (existing && !existing.partial) return existing;
112
+ }
113
+
114
+ const data = await this.client.rest.get(Routes.channelMessage(this.channel.id, message));
115
+ return this._add(data, cache);
116
+ }
117
+
118
+ async _fetchMany({ cache, ...apiOptions } = {}) {
119
+ const data = await this.client.rest.get(Routes.channelMessages(this.channel.id), {
120
+ query: makeURLSearchParams(apiOptions),
121
+ });
122
+
123
+ return data.reduce((_data, message) => _data.set(message.id, this._add(message, cache)), new Collection());
124
+ }
125
+
126
+ /**
127
+ * Options used to fetch pinned messages.
128
+ *
129
+ * @typedef {Object} FetchPinnedMessagesOptions
130
+ * @property {DateResolvable} [before] Consider only pinned messages before this time
131
+ * @property {number} [limit] The maximum number of pinned messages to return
132
+ * @property {boolean} [cache] Whether to cache the pinned messages
133
+ */
134
+
135
+ /**
136
+ * Data returned from fetching pinned messages.
137
+ *
138
+ * @typedef {Object} FetchPinnedMessagesResponse
139
+ * @property {MessagePin[]} items The pinned messages
140
+ * @property {boolean} hasMore Whether there are additional pinned messages that require a subsequent call
141
+ */
142
+
143
+ /**
144
+ * Pinned message data returned from fetching pinned messages.
145
+ *
146
+ * @typedef {Object} MessagePin
147
+ * @property {Date} pinnedAt The time the message was pinned at
148
+ * @property {number} pinnedTimestamp The timestamp the message was pinned at
149
+ * @property {Message} message The pinned message
150
+ */
151
+
152
+ /**
153
+ * Fetches the pinned messages of this channel, returning a paginated result.
154
+ * <info>The returned messages do not contain any reaction data.
155
+ * Those need to be fetched separately.</info>
156
+ *
157
+ * @param {FetchPinnedMessagesOptions} [options={}] Options for fetching pinned messages
158
+ * @returns {Promise<FetchPinnedMessagesResponse>}
159
+ * @example
160
+ * // Get pinned messages
161
+ * channel.messages.fetchPins()
162
+ * .then(messages => console.log(`Received ${messages.items.length} messages`))
163
+ * .catch(console.error);
164
+ */
165
+ async fetchPins({ cache, ...apiOptions } = {}) {
166
+ const data = await this.client.rest.get(Routes.channelMessagesPins(this.channel.id), {
167
+ query: makeURLSearchParams({
168
+ ...apiOptions,
169
+ before: apiOptions.before && new Date(apiOptions.before).toISOString(),
170
+ }),
171
+ });
172
+
173
+ return {
174
+ items: data.items.map(item => ({
175
+ pinnedTimestamp: Date.parse(item.pinned_at),
176
+ get pinnedAt() {
177
+ return new Date(this.pinnedTimestamp);
178
+ },
179
+ message: this._add(item.message, cache),
180
+ })),
181
+ hasMore: data.has_more,
182
+ };
183
+ }
184
+
185
+ /**
186
+ * Resolves a {@link MessageResolvable} to a {@link Message} object.
187
+ *
188
+ * @method resolve
189
+ * @memberof MessageManager
190
+ * @instance
191
+ * @param {MessageResolvable} message The message resolvable to resolve
192
+ * @returns {?Message}
193
+ */
194
+
195
+ /**
196
+ * Resolves a {@link MessageResolvable} to a {@link Message} id.
197
+ *
198
+ * @method resolveId
199
+ * @memberof MessageManager
200
+ * @instance
201
+ * @param {MessageResolvable} message The message resolvable to resolve
202
+ * @returns {?Snowflake}
203
+ */
204
+
205
+ /**
206
+ * Data used to reference an attachment.
207
+ *
208
+ * @typedef {Object} MessageEditAttachmentData
209
+ * @property {Snowflake} id The id of the attachment
210
+ */
211
+
212
+ /**
213
+ * Options that can be passed to edit a message.
214
+ *
215
+ * @typedef {BaseMessageOptions} MessageEditOptions
216
+ * @property {Array<Attachment|MessageEditAttachmentData>} [attachments] An array of attachments to keep.
217
+ * All attachments will be kept if omitted
218
+ * @property {MessageFlags} [flags] Which flags to set for the message
219
+ * <info>Only the {@link MessageFlags.SuppressEmbeds} flag can be modified.</info>
220
+ */
221
+
222
+ /**
223
+ * Edits a message, even if it's not cached.
224
+ *
225
+ * @param {MessageResolvable} message The message to edit
226
+ * @param {string|MessageEditOptions|MessagePayload|FileBodyEncodable<RESTPatchAPIChannelMessageJSONBody>|JSONEncodable<RESTPatchAPIChannelMessageJSONBody>} options The options to edit the message
227
+ * @returns {Promise<Message>}
228
+ */
229
+ async edit(message, options) {
230
+ const messageId = this.resolveId(message);
231
+ if (!messageId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'message', 'MessageResolvable');
232
+
233
+ let payload;
234
+ if (options instanceof MessagePayload) {
235
+ payload = await options.resolveBody().resolveFiles();
236
+ } else if (isFileBodyEncodable(options)) {
237
+ payload = options.toFileBody();
238
+ } else if (isJSONEncodable(options)) {
239
+ payload = { body: options.toJSON() };
240
+ } else {
241
+ payload = await MessagePayload.create(message instanceof Message ? message : this, options)
242
+ .resolveBody()
243
+ .resolveFiles();
244
+ }
245
+
246
+ const data = await this.client.rest.patch(Routes.channelMessage(this.channel.id, messageId), payload);
247
+
248
+ const existing = this.cache.get(messageId);
249
+ if (existing) {
250
+ const clone = existing._clone();
251
+ clone._patch(data);
252
+ return clone;
253
+ }
254
+
255
+ return this._add(data);
256
+ }
257
+
258
+ /**
259
+ * Pins a message to the channel's pinned messages, even if it's not cached.
260
+ *
261
+ * @param {MessageResolvable} message The message to pin
262
+ * @param {string} [reason] Reason for pinning
263
+ * @returns {Promise<void>}
264
+ */
265
+ async pin(message, reason) {
266
+ const messageId = this.resolveId(message);
267
+ if (!messageId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'message', 'MessageResolvable');
268
+
269
+ await this.client.rest.put(Routes.channelMessagesPin(this.channel.id, messageId), { reason });
270
+ }
271
+
272
+ /**
273
+ * Unpins a message from the channel's pinned messages, even if it's not cached.
274
+ *
275
+ * @param {MessageResolvable} message The message to unpin
276
+ * @param {string} [reason] Reason for unpinning
277
+ * @returns {Promise<void>}
278
+ */
279
+ async unpin(message, reason) {
280
+ const messageId = this.resolveId(message);
281
+ if (!messageId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'message', 'MessageResolvable');
282
+
283
+ await this.client.rest.delete(Routes.channelMessagesPin(this.channel.id, messageId), { reason });
284
+ }
285
+
286
+ /**
287
+ * Adds a reaction to a message, even if it's not cached.
288
+ *
289
+ * @param {MessageResolvable} message The message to react to
290
+ * @param {EmojiIdentifierResolvable} emoji The emoji to react with
291
+ * @returns {Promise<void>}
292
+ */
293
+ async react(message, emoji) {
294
+ const messageId = this.resolveId(message);
295
+ if (!messageId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'message', 'MessageResolvable');
296
+
297
+ const resolvedEmoji = resolvePartialEmoji(emoji);
298
+ if (!resolvedEmoji) throw new DiscordjsTypeError(ErrorCodes.EmojiType, 'emoji', 'EmojiIdentifierResolvable');
299
+
300
+ const emojiId = resolvedEmoji.id
301
+ ? `${resolvedEmoji.animated ? 'a:' : ''}${resolvedEmoji.name}:${resolvedEmoji.id}`
302
+ : encodeURIComponent(resolvedEmoji.name);
303
+
304
+ await this.client.rest.put(Routes.channelMessageOwnReaction(this.channel.id, messageId, emojiId));
305
+ }
306
+
307
+ /**
308
+ * Deletes a message, even if it's not cached.
309
+ *
310
+ * @param {MessageResolvable} message The message to delete
311
+ * @returns {Promise<void>}
312
+ */
313
+ async delete(message) {
314
+ const messageId = this.resolveId(message);
315
+ if (!messageId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'message', 'MessageResolvable');
316
+
317
+ await this.client.rest.delete(Routes.channelMessage(this.channel.id, messageId));
318
+ }
319
+
320
+ /**
321
+ * Ends a poll.
322
+ *
323
+ * @param {Snowflake} messageId The id of the message
324
+ * @returns {Promise<Message>}
325
+ */
326
+ async endPoll(messageId) {
327
+ const message = await this.client.rest.post(Routes.expirePoll(this.channel.id, messageId));
328
+ return this._add(message, false);
329
+ }
330
+
331
+ /**
332
+ * Options used for fetching voters of an answer in a poll.
333
+ *
334
+ * @typedef {BaseFetchPollAnswerVotersOptions} FetchPollAnswerVotersOptions
335
+ * @param {Snowflake} messageId The id of the message
336
+ * @param {number} answerId The id of the answer
337
+ */
338
+
339
+ /**
340
+ * Fetches the users that voted for a poll answer.
341
+ *
342
+ * @param {FetchPollAnswerVotersOptions} options The options for fetching the poll answer voters
343
+ * @returns {Promise<Collection<Snowflake, User>>}
344
+ */
345
+ async fetchPollAnswerVoters({ messageId, answerId, after, limit }) {
346
+ const voters = await this.client.rest.get(Routes.pollAnswerVoters(this.channel.id, messageId, answerId), {
347
+ query: makeURLSearchParams({ limit, after }),
348
+ });
349
+
350
+ return voters.users.reduce((acc, user) => acc.set(user.id, this.client.users._add(user, false)), new Collection());
351
+ }
352
+ }
@@ -0,0 +1,15 @@
1
+ import { MessageManager } from './MessageManager.js';
2
+
3
+ /**
4
+ * Manages API methods for messages in group direct message channels and holds their cache.
5
+ *
6
+ * @extends {MessageManager}
7
+ */
8
+ export class PartialGroupDMMessageManager extends MessageManager {
9
+ /**
10
+ * The channel that the messages belong to
11
+ *
12
+ * @name PartialGroupDMMessageManager#channel
13
+ * @type {PartialGroupDMChannel}
14
+ */
15
+ }
@@ -0,0 +1,174 @@
1
+ import process from 'node:process';
2
+ import { Collection } from '@ovencord/collection';
3
+ import { OverwriteType, Routes } from 'discord-api-types/v10';
4
+ import { DiscordjsTypeError, ErrorCodes } from '../errors/index.js';
5
+ import { PermissionOverwrites } from '../structures/PermissionOverwrites.js';
6
+ import { Role } from '../structures/Role.js';
7
+ import { CachedManager } from './CachedManager.js';
8
+
9
+ let cacheWarningEmitted = false;
10
+
11
+ /**
12
+ * Manages API methods for guild channel permission overwrites and stores their cache.
13
+ *
14
+ * @extends {CachedManager}
15
+ */
16
+ export class PermissionOverwriteManager extends CachedManager {
17
+ public channel: any;
18
+ constructor(channel, iterable) {
19
+ super(channel.client, PermissionOverwrites);
20
+ if (!cacheWarningEmitted && this._cache.constructor.name !== 'Collection') {
21
+ cacheWarningEmitted = true;
22
+ process.emitWarning(
23
+ `Overriding the cache handling for ${this.constructor.name} is unsupported and breaks functionality.`,
24
+ 'UnsupportedCacheOverwriteWarning',
25
+ );
26
+ }
27
+
28
+ /**
29
+ * The channel of the permission overwrite this manager belongs to
30
+ *
31
+ * @type {GuildChannel}
32
+ */
33
+ this.channel = channel;
34
+
35
+ if (iterable) {
36
+ for (const item of iterable) {
37
+ this._add(item);
38
+ }
39
+ }
40
+ }
41
+
42
+ /**
43
+ * The cache of this Manager
44
+ *
45
+ * @type {Collection<Snowflake, PermissionOverwrites>}
46
+ * @name PermissionOverwriteManager#cache
47
+ */
48
+
49
+ _add(data, cache) {
50
+ return super._add(data, cache, { extras: [this.channel] });
51
+ }
52
+
53
+ /**
54
+ * Replaces the permission overwrites in this channel.
55
+ *
56
+ * @param {OverwriteResolvable[]|Collection<Snowflake, OverwriteResolvable>} overwrites
57
+ * Permission overwrites the channel gets updated with
58
+ * @param {string} [reason] Reason for updating the channel overwrites
59
+ * @returns {Promise<GuildChannel>}
60
+ * @example
61
+ * message.channel.permissionOverwrites.set([
62
+ * {
63
+ * id: message.author.id,
64
+ * deny: [PermissionFlagsBits.ViewChannel],
65
+ * },
66
+ * ], 'Needed to change permissions');
67
+ */
68
+ async set(overwrites, reason) {
69
+ if (!Array.isArray(overwrites) && !(overwrites instanceof Collection)) {
70
+ throw new DiscordjsTypeError(
71
+ ErrorCodes.InvalidType,
72
+ 'overwrites',
73
+ 'Array or Collection of Permission Overwrites',
74
+ true,
75
+ );
76
+ }
77
+
78
+ return this.channel.edit({ permissionOverwrites: overwrites, reason });
79
+ }
80
+
81
+ /**
82
+ * Extra information about the overwrite.
83
+ *
84
+ * @typedef {Object} GuildChannelOverwriteOptions
85
+ * @property {string} [reason] The reason for creating/editing this overwrite
86
+ * @property {OverwriteType} [type] The type of overwrite. Use this to bypass automatic resolution of `type`
87
+ * that results in an error for an uncached structure
88
+ */
89
+
90
+ /**
91
+ * Creates or edits permission overwrites for a user or role in this channel.
92
+ *
93
+ * @param {RoleResolvable|UserResolvable} userOrRole The user or role to update
94
+ * @param {PermissionOverwriteOptions} options The options for the update
95
+ * @param {GuildChannelOverwriteOptions} [overwriteOptions] The extra information for the update
96
+ * @param {PermissionOverwrites} [existing] The existing overwrites to merge with this update
97
+ * @returns {Promise<GuildChannel>}
98
+ * @private
99
+ */
100
+ async upsert(userOrRole, options, { reason, type } = {}, existing = undefined) {
101
+ const userOrRoleId = this.channel.guild.roles.resolveId(userOrRole) ?? this.client.users.resolveId(userOrRole);
102
+
103
+ let resolvedType = type;
104
+ if (typeof resolvedType !== 'number') {
105
+ const resolvedUserOrRole = this.channel.guild.roles.resolve(userOrRole) ?? this.client.users.resolve(userOrRole);
106
+ if (!resolvedUserOrRole) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'parameter', 'User nor a Role');
107
+ resolvedType = resolvedUserOrRole instanceof Role ? OverwriteType.Role : OverwriteType.Member;
108
+ }
109
+
110
+ const { allow, deny } = PermissionOverwrites.resolveOverwriteOptions(options, existing);
111
+
112
+ await this.client.rest.put(Routes.channelPermission(this.channel.id, userOrRoleId), {
113
+ body: { id: userOrRoleId, type: resolvedType, allow, deny },
114
+ reason,
115
+ });
116
+ return this.channel;
117
+ }
118
+
119
+ /**
120
+ * Creates permission overwrites for a user or role in this channel, or replaces them if already present.
121
+ *
122
+ * @param {RoleResolvable|UserResolvable} userOrRole The user or role to update
123
+ * @param {PermissionOverwriteOptions} options The options for the update
124
+ * @param {GuildChannelOverwriteOptions} [overwriteOptions] The extra information for the update
125
+ * @returns {Promise<GuildChannel>}
126
+ * @example
127
+ * // Create or Replace permission overwrites for a message author
128
+ * message.channel.permissionOverwrites.create(message.author, {
129
+ * SendMessages: false
130
+ * })
131
+ * .then(channel => console.log(channel.permissionOverwrites.cache.get(message.author.id)))
132
+ * .catch(console.error);
133
+ */
134
+ async create(userOrRole, options, overwriteOptions) {
135
+ return this.upsert(userOrRole, options, overwriteOptions);
136
+ }
137
+
138
+ /**
139
+ * Edits permission overwrites for a user or role in this channel, or creates an entry if not already present.
140
+ *
141
+ * @param {RoleResolvable|UserResolvable} userOrRole The user or role to update
142
+ * @param {PermissionOverwriteOptions} options The options for the update
143
+ * @param {GuildChannelOverwriteOptions} [overwriteOptions] The extra information for the update
144
+ * @returns {Promise<GuildChannel>}
145
+ * @example
146
+ * // Edit or Create permission overwrites for a message author
147
+ * message.channel.permissionOverwrites.edit(message.author, {
148
+ * SendMessages: false
149
+ * })
150
+ * .then(channel => console.log(channel.permissionOverwrites.cache.get(message.author.id)))
151
+ * .catch(console.error);
152
+ */
153
+ async edit(userOrRole, options, overwriteOptions) {
154
+ const existing = this.cache.get(
155
+ this.channel.guild.roles.resolveId(userOrRole) ?? this.client.users.resolveId(userOrRole),
156
+ );
157
+ return this.upsert(userOrRole, options, overwriteOptions, existing);
158
+ }
159
+
160
+ /**
161
+ * Deletes permission overwrites for a user or role in this channel.
162
+ *
163
+ * @param {UserResolvable|RoleResolvable} userOrRole The user or role to delete
164
+ * @param {string} [reason] The reason for deleting the overwrite
165
+ * @returns {Promise<GuildChannel>}
166
+ */
167
+ async delete(userOrRole, reason) {
168
+ const userOrRoleId = this.channel.guild.roles.resolveId(userOrRole) ?? this.client.users.resolveId(userOrRole);
169
+ if (!userOrRoleId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'parameter', 'User nor a Role');
170
+
171
+ await this.client.rest.delete(Routes.channelPermission(this.channel.id, userOrRoleId), { reason });
172
+ return this.channel;
173
+ }
174
+ }
@@ -0,0 +1,59 @@
1
+ import { Collection } from '@ovencord/collection';
2
+ import { makeURLSearchParams } from '@ovencord/rest';
3
+ import { Routes } from 'discord-api-types/v10';
4
+ import { User } from '../structures/User.js';
5
+ import { CachedManager } from './CachedManager.js';
6
+
7
+ /**
8
+ * Manages API methods for users who voted on a poll and stores their cache.
9
+ *
10
+ * @extends {CachedManager}
11
+ */
12
+ export class PollAnswerVoterManager extends CachedManager {
13
+ public answer: any;
14
+ constructor(answer) {
15
+ super(answer.client, User);
16
+
17
+ /**
18
+ * The poll answer that this manager belongs to
19
+ *
20
+ * @type {PollAnswer}
21
+ */
22
+ this.answer = answer;
23
+ }
24
+
25
+ /**
26
+ * The cache of this manager
27
+ *
28
+ * @type {Collection<Snowflake, User>}
29
+ * @name PollAnswerVoterManager#cache
30
+ */
31
+
32
+ /**
33
+ * Options used for fetching voters of a poll answer.
34
+ *
35
+ * @typedef {Object} BaseFetchPollAnswerVotersOptions
36
+ * @property {number} [limit] The maximum number of voters to fetch
37
+ * @property {Snowflake} [after] The user id to fetch voters after
38
+ */
39
+
40
+ /**
41
+ * Fetches the users that voted on this poll answer. Resolves with a collection of users, mapped by their ids.
42
+ *
43
+ * @param {BaseFetchPollAnswerVotersOptions} [options={}] Options for fetching the users
44
+ * @returns {Promise<Collection<Snowflake, User>>}
45
+ */
46
+ async fetch({ after, limit } = {}) {
47
+ const poll = this.answer.poll;
48
+ const query = makeURLSearchParams({ limit, after });
49
+ const data = await this.client.rest.get(Routes.pollAnswerVoters(poll.channelId, poll.messageId, this.answer.id), {
50
+ query,
51
+ });
52
+
53
+ return data.users.reduce((coll, rawUser) => {
54
+ const user = this.client.users._add(rawUser);
55
+ this.cache.set(user.id, user);
56
+ return coll.set(user.id, user);
57
+ }, new Collection());
58
+ }
59
+ }
@@ -0,0 +1,60 @@
1
+ import { Presence } from '../structures/Presence.js';
2
+ import { CachedManager } from './CachedManager.js';
3
+
4
+ /**
5
+ * Manages API methods for Presences and holds their cache.
6
+ *
7
+ * @extends {CachedManager}
8
+ */
9
+ export class PresenceManager extends CachedManager {
10
+ public client: any;
11
+ constructor(client, iterable) {
12
+ super(client, Presence, iterable);
13
+ }
14
+
15
+ /**
16
+ * The cache of Presences
17
+ *
18
+ * @type {Collection<Snowflake, Presence>}
19
+ * @name PresenceManager#cache
20
+ */
21
+
22
+ _add(data, cache) {
23
+ return super._add(data, cache, { id: data.user.id });
24
+ }
25
+
26
+ /**
27
+ * Data that can be resolved to a Presence object. This can be:
28
+ * - A Presence
29
+ * - A UserResolvable
30
+ * - A Snowflake
31
+ *
32
+ * @typedef {Presence|UserResolvable|Snowflake} PresenceResolvable
33
+ */
34
+
35
+ /**
36
+ * Resolves a {@link PresenceResolvable} to a {@link Presence} object.
37
+ *
38
+ * @param {PresenceResolvable} presence The presence resolvable to resolve
39
+ * @returns {?Presence}
40
+ */
41
+ resolve(presence) {
42
+ const presenceResolvable = super.resolve(presence);
43
+ if (presenceResolvable) return presenceResolvable;
44
+ const userId = this.client.users.resolveId(presence);
45
+ return super.cache.get(userId) ?? null;
46
+ }
47
+
48
+ /**
49
+ * Resolves a {@link PresenceResolvable} to a {@link Presence} id.
50
+ *
51
+ * @param {PresenceResolvable} presence The presence resolvable to resolve
52
+ * @returns {?Snowflake}
53
+ */
54
+ resolveId(presence) {
55
+ const presenceResolvable = super.resolveId(presence);
56
+ if (presenceResolvable) return presenceResolvable;
57
+ const userId = this.client.users.resolveId(presence);
58
+ return this.cache.has(userId) ? userId : null;
59
+ }
60
+ }