@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,72 @@
1
+ import { Routes } from 'discord-api-types/v10';
2
+ import { MessageReaction } from '../structures/MessageReaction.js';
3
+ import { CachedManager } from './CachedManager.js';
4
+
5
+ /**
6
+ * Manages API methods for reactions and holds their cache.
7
+ *
8
+ * @extends {CachedManager}
9
+ */
10
+ export class ReactionManager extends CachedManager {
11
+ public message: any;
12
+ constructor(message, iterable) {
13
+ super(message.client, MessageReaction, iterable);
14
+
15
+ /**
16
+ * The message that this manager belongs to
17
+ *
18
+ * @type {Message}
19
+ */
20
+ this.message = message;
21
+ }
22
+
23
+ _add(data, cache) {
24
+ return super._add(data, cache, { id: data.emoji.id ?? data.emoji.name, extras: [this.message] });
25
+ }
26
+
27
+ /**
28
+ * The reaction cache of this manager
29
+ *
30
+ * @type {Collection<string|Snowflake, MessageReaction>}
31
+ * @name ReactionManager#cache
32
+ */
33
+
34
+ /**
35
+ * Data that can be resolved to a MessageReaction object. This can be:
36
+ * - A MessageReaction
37
+ * - A Snowflake
38
+ * - The Unicode representation of an emoji
39
+ *
40
+ * @typedef {MessageReaction|Snowflake} MessageReactionResolvable
41
+ */
42
+
43
+ /**
44
+ * Resolves a {@link MessageReactionResolvable} to a {@link MessageReaction} object.
45
+ *
46
+ * @method resolve
47
+ * @memberof ReactionManager
48
+ * @instance
49
+ * @param {MessageReactionResolvable} reaction The MessageReaction to resolve
50
+ * @returns {?MessageReaction}
51
+ */
52
+
53
+ /**
54
+ * Resolves a {@link MessageReactionResolvable} to a {@link MessageReaction} id.
55
+ *
56
+ * @method resolveId
57
+ * @memberof ReactionManager
58
+ * @instance
59
+ * @param {MessageReactionResolvable} reaction The MessageReaction to resolve
60
+ * @returns {?Snowflake}
61
+ */
62
+
63
+ /**
64
+ * Removes all reactions from a message.
65
+ *
66
+ * @returns {Promise<Message>}
67
+ */
68
+ async removeAll() {
69
+ await this.client.rest.delete(Routes.channelMessageAllReactions(this.message.channelId, this.message.id));
70
+ return this.message;
71
+ }
72
+ }
@@ -0,0 +1,82 @@
1
+ import { Collection } from '@ovencord/collection';
2
+ import { makeURLSearchParams } from '@ovencord/rest';
3
+ import { ReactionType, Routes } from 'discord-api-types/v10';
4
+ import { DiscordjsError, ErrorCodes } from '../errors/index.js';
5
+ import { User } from '../structures/User.js';
6
+ import { CachedManager } from './CachedManager.js';
7
+
8
+ /**
9
+ * Manages API methods for users who reacted to a reaction and stores their cache.
10
+ *
11
+ * @extends {CachedManager}
12
+ */
13
+ export class ReactionUserManager extends CachedManager {
14
+ public reaction: any;
15
+ constructor(reaction, iterable) {
16
+ super(reaction.client, User, iterable);
17
+
18
+ /**
19
+ * The reaction that this manager belongs to
20
+ *
21
+ * @type {MessageReaction}
22
+ */
23
+ this.reaction = reaction;
24
+ }
25
+
26
+ /**
27
+ * The cache of this manager
28
+ *
29
+ * @type {Collection<Snowflake, User>}
30
+ * @name ReactionUserManager#cache
31
+ */
32
+
33
+ /**
34
+ * Options used to fetch users who gave a reaction.
35
+ *
36
+ * @typedef {Object} FetchReactionUsersOptions
37
+ * @property {ReactionType} [type=ReactionType.Normal] The reaction type to fetch
38
+ * @property {number} [limit=100] The maximum amount of users to fetch, defaults to `100`
39
+ * @property {Snowflake} [after] Limit fetching users to those with an id greater than the supplied id
40
+ */
41
+
42
+ /**
43
+ * Fetches all the users that gave this reaction. Resolves with a collection of users, mapped by their ids.
44
+ *
45
+ * @param {FetchReactionUsersOptions} [options] Options for fetching the users
46
+ * @returns {Promise<Collection<Snowflake, User>>}
47
+ */
48
+ async fetch({ type = ReactionType.Normal, limit = 100, after } = {}) {
49
+ const message = this.reaction.message;
50
+ const query = makeURLSearchParams({ limit, after, type });
51
+ const data = await this.client.rest.get(
52
+ Routes.channelMessageReaction(message.channelId, message.id, this.reaction.emoji.identifier),
53
+ { query },
54
+ );
55
+ const users = new Collection();
56
+ for (const rawUser of data) {
57
+ const user = this.client.users._add(rawUser);
58
+ this.cache.set(user.id, user);
59
+ users.set(user.id, user);
60
+ }
61
+
62
+ return users;
63
+ }
64
+
65
+ /**
66
+ * Removes a user from this reaction.
67
+ *
68
+ * @param {UserResolvable} [user=this.client.user] The user to remove the reaction of
69
+ * @returns {Promise<MessageReaction>}
70
+ */
71
+ async remove(user = this.client.user) {
72
+ const userId = this.client.users.resolveId(user);
73
+ if (!userId) throw new DiscordjsError(ErrorCodes.ReactionResolveUser);
74
+ const message = this.reaction.message;
75
+ const route =
76
+ userId === this.client.user.id
77
+ ? Routes.channelMessageOwnReaction(message.channelId, message.id, this.reaction.emoji.identifier)
78
+ : Routes.channelMessageUserReaction(message.channelId, message.id, this.reaction.emoji.identifier, userId);
79
+ await this.client.rest.delete(route);
80
+ return this.reaction;
81
+ }
82
+ }
@@ -0,0 +1,432 @@
1
+ import process from 'node:process';
2
+ import { Collection } from '@ovencord/collection';
3
+ import { Routes } from 'discord-api-types/v10';
4
+ import { DiscordjsTypeError, ErrorCodes } from '../errors/index.js';
5
+ import { Role } from '../structures/Role.js';
6
+ import { resolveImage } from '../util/DataResolver.js';
7
+ import { PermissionsBitField } from '../util/PermissionsBitField.js';
8
+ import { setPosition, resolveColor } from '../util/Util.js';
9
+ import { CachedManager } from './CachedManager.js';
10
+
11
+ let cacheWarningEmitted = false;
12
+
13
+ /**
14
+ * Manages API methods for roles and stores their cache.
15
+ *
16
+ * @extends {CachedManager}
17
+ */
18
+ export class RoleManager extends CachedManager {
19
+ public guild: any;
20
+ constructor(guild, iterable) {
21
+ super(guild.client, Role, iterable);
22
+ if (!cacheWarningEmitted && this._cache.constructor.name !== 'Collection') {
23
+ cacheWarningEmitted = true;
24
+ process.emitWarning(
25
+ `Overriding the cache handling for ${this.constructor.name} is unsupported and breaks functionality.`,
26
+ 'UnsupportedCacheOverwriteWarning',
27
+ );
28
+ }
29
+
30
+ /**
31
+ * The guild belonging to this manager
32
+ *
33
+ * @type {Guild}
34
+ */
35
+ this.guild = guild;
36
+ }
37
+
38
+ /**
39
+ * The role cache of this manager
40
+ *
41
+ * @type {Collection<Snowflake, Role>}
42
+ * @name RoleManager#cache
43
+ */
44
+
45
+ _add(data, cache) {
46
+ return super._add(data, cache, { extras: [this.guild] });
47
+ }
48
+
49
+ /**
50
+ * Obtains a role from Discord, or the role cache if they're already available.
51
+ *
52
+ * @param {Snowflake} [id] The role's id
53
+ * @param {BaseFetchOptions} [options] Additional options for this fetch
54
+ * @returns {Promise<Role|Collection<Snowflake, Role>>}
55
+ * @example
56
+ * // Fetch all roles from the guild
57
+ * message.guild.roles.fetch()
58
+ * .then(roles => console.log(`There are ${roles.size} roles.`))
59
+ * .catch(console.error);
60
+ * @example
61
+ * // Fetch a single role
62
+ * message.guild.roles.fetch('222078108977594368')
63
+ * .then(role => console.log(`The role color is: ${role.colors.primaryColor}`))
64
+ * .catch(console.error);
65
+ */
66
+ async fetch(id, { cache = true, force = false } = {}) {
67
+ if (!id) {
68
+ const innerData = await this.client.rest.get(Routes.guildRoles(this.guild.id));
69
+ const roles = new Collection();
70
+ for (const role of innerData) roles.set(role.id, this._add(role, cache));
71
+ return roles;
72
+ }
73
+
74
+ if (!force) {
75
+ const existing = this.cache.get(id);
76
+ if (existing) return existing;
77
+ }
78
+
79
+ const data = await this.client.rest.get(Routes.guildRole(this.guild.id, id));
80
+ return this._add(data, cache);
81
+ }
82
+
83
+ /**
84
+ * Fetches the member count of each role in the guild.
85
+ * <info>This does not include the `@everyone` role.</info>
86
+ *
87
+ * @returns {Promise<Collection<Snowflake, number>>} A collection mapping role ids to their respective member counts.
88
+ */
89
+ async fetchMemberCounts() {
90
+ const data = await this.client.rest.get(Routes.guildRoleMemberCounts(this.guild.id));
91
+ return new Collection(Object.entries(data));
92
+ }
93
+
94
+ /**
95
+ * Data that can be resolved to a Role object. This can be:
96
+ * - A Role
97
+ * - A Snowflake
98
+ *
99
+ * @typedef {Role|Snowflake} RoleResolvable
100
+ */
101
+
102
+ /**
103
+ * Resolves a {@link RoleResolvable} to a {@link Role} object.
104
+ *
105
+ * @method resolve
106
+ * @memberof RoleManager
107
+ * @instance
108
+ * @param {RoleResolvable} role The role resolvable to resolve
109
+ * @returns {?Role}
110
+ */
111
+
112
+ /**
113
+ * Resolves a {@link RoleResolvable} to a {@link Role} id.
114
+ *
115
+ * @method resolveId
116
+ * @memberof RoleManager
117
+ * @instance
118
+ * @param {RoleResolvable} role The role resolvable to resolve
119
+ * @returns {?Snowflake}
120
+ */
121
+
122
+ /**
123
+ * @typedef {Object} RoleColorsResolvable
124
+ * @property {ColorResolvable} primaryColor The primary color of the role
125
+ * @property {ColorResolvable} [secondaryColor] The secondary color of the role.
126
+ * This will make the role a gradient between the other provided colors
127
+ * @property {ColorResolvable} [tertiaryColor] The tertiary color of the role.
128
+ * When sending `tertiaryColor` the API enforces the role color to be a holographic style with values of `primaryColor = 11127295`, `secondaryColor = 16759788`, and `tertiaryColor = 16761760`.
129
+ * These values are available as a constant: `Constants.HolographicStyle`
130
+ */
131
+
132
+ /**
133
+ * Options used to create a new role.
134
+ *
135
+ * @typedef {Object} RoleCreateOptions
136
+ * @property {string} [name] The name of the new role
137
+ * @property {RoleColorsResolvable} [colors] The colors to create the role with
138
+ * @property {boolean} [hoist] Whether or not the new role should be hoisted
139
+ * @property {PermissionResolvable} [permissions] The permissions for the new role
140
+ * @property {number} [position] The position of the new role
141
+ * @property {boolean} [mentionable] Whether or not the new role should be mentionable
142
+ * @property {?(BufferResolvable|Base64Resolvable|EmojiResolvable)} [icon] The icon for the role
143
+ * <warn>The `EmojiResolvable` should belong to the same guild as the role.
144
+ * If not, pass the emoji's URL directly</warn>
145
+ * @property {?string} [unicodeEmoji] The unicode emoji for the role
146
+ * @property {string} [reason] The reason for creating this role
147
+ */
148
+
149
+ /**
150
+ * Creates a new role in the guild with given information.
151
+ * <warn>The position will silently reset to 1 if an invalid one is provided, or none.</warn>
152
+ *
153
+ * @param {RoleCreateOptions} [options] Options for creating the new role
154
+ * @returns {Promise<Role>}
155
+ * @example
156
+ * // Create a new role
157
+ * guild.roles.create()
158
+ * .then(console.log)
159
+ * .catch(console.error);
160
+ * @example
161
+ * // Create a new role with data and a reason
162
+ * guild.roles.create({
163
+ * name: 'Super Cool Blue People',
164
+ * reason: 'we needed a role for Super Cool People',
165
+ * colors: {
166
+ * primaryColor: Colors.Blue,
167
+ * },
168
+ * })
169
+ * .then(console.log)
170
+ * .catch(console.error);
171
+ * @example
172
+ * // Create a role with holographic colors
173
+ * guild.roles.create({
174
+ * name: 'Holographic Role',
175
+ * reason: 'Creating a role with holographic effect',
176
+ * colors: {
177
+ * primaryColor: Constants.HolographicStyle.Primary,
178
+ * secondaryColor: Constants.HolographicStyle.Secondary,
179
+ * tertiaryColor: Constants.HolographicStyle.Tertiary,
180
+ * },
181
+ * })
182
+ * .then(console.log)
183
+ * .catch(console.error);
184
+ */
185
+ async create(options = {}) {
186
+ let { permissions, icon } = options;
187
+ const { name, hoist, position, mentionable, reason, unicodeEmoji } = options;
188
+ if (permissions !== undefined) permissions = new PermissionsBitField(permissions);
189
+ if (icon) {
190
+ const guildEmojiURL = this.guild.emojis.resolve(icon)?.imageURL();
191
+ icon = guildEmojiURL ? await resolveImage(guildEmojiURL) : await resolveImage(icon);
192
+ if (typeof icon !== 'string') icon = undefined;
193
+ }
194
+
195
+ const colors = options.colors && {
196
+ primary_color: resolveColor(options.colors.primaryColor),
197
+ secondary_color: options.colors.secondaryColor && resolveColor(options.colors.secondaryColor),
198
+ tertiary_color: options.colors.tertiaryColor && resolveColor(options.colors.tertiaryColor),
199
+ };
200
+
201
+ const data = await this.client.rest.post(Routes.guildRoles(this.guild.id), {
202
+ body: {
203
+ name,
204
+ colors,
205
+ hoist,
206
+ permissions,
207
+ mentionable,
208
+ icon,
209
+ unicode_emoji: unicodeEmoji,
210
+ },
211
+ reason,
212
+ });
213
+ const { role } = this.client.actions.GuildRoleCreate.handle({
214
+ guild_id: this.guild.id,
215
+ role: data,
216
+ });
217
+ if (position) return this.setPosition(role, position, { reason });
218
+ return role;
219
+ }
220
+
221
+ /**
222
+ * Options for editing a role
223
+ *
224
+ * @typedef {RoleData} RoleEditOptions
225
+ * @property {string} [reason] The reason for editing this role
226
+ */
227
+
228
+ /**
229
+ * Edits a role of the guild.
230
+ *
231
+ * @param {RoleResolvable} role The role to edit
232
+ * @param {RoleEditOptions} options The options to provide
233
+ * @returns {Promise<Role>}
234
+ * @example
235
+ * // Edit a role
236
+ * guild.roles.edit('222079219327434752', { name: 'buddies' })
237
+ * .then(updated => console.log(`Edited role name to ${updated.name}`))
238
+ * .catch(console.error);
239
+ */
240
+ async edit(role, options) {
241
+ const resolvedRole = this.resolve(role);
242
+ if (!resolvedRole) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'role', 'RoleResolvable');
243
+
244
+ if (typeof options.position === 'number') {
245
+ await this.setPosition(resolvedRole, options.position, { reason: options.reason });
246
+ }
247
+
248
+ let icon = options.icon;
249
+ if (icon) {
250
+ const guildEmojiURL = this.guild.emojis.resolve(icon)?.imageURL();
251
+ icon = guildEmojiURL ? await resolveImage(guildEmojiURL) : await resolveImage(icon);
252
+ if (typeof icon !== 'string') icon = undefined;
253
+ }
254
+
255
+ const colors = options.colors && {
256
+ primary_color: resolveColor(options.colors.primaryColor),
257
+ secondary_color: options.colors.secondaryColor && resolveColor(options.colors.secondaryColor),
258
+ tertiary_color: options.colors.tertiaryColor && resolveColor(options.colors.tertiaryColor),
259
+ };
260
+
261
+ const body = {
262
+ name: options.name,
263
+ colors,
264
+ hoist: options.hoist,
265
+ permissions: options.permissions === undefined ? undefined : new PermissionsBitField(options.permissions),
266
+ mentionable: options.mentionable,
267
+ icon,
268
+ unicode_emoji: options.unicodeEmoji,
269
+ };
270
+
271
+ const data = await this.client.rest.patch(Routes.guildRole(this.guild.id, resolvedRole.id), {
272
+ body,
273
+ reason: options.reason,
274
+ });
275
+
276
+ const clone = resolvedRole._clone();
277
+ clone._patch(data);
278
+ return clone;
279
+ }
280
+
281
+ /**
282
+ * Deletes a role.
283
+ *
284
+ * @param {RoleResolvable} role The role to delete
285
+ * @param {string} [reason] Reason for deleting the role
286
+ * @returns {Promise<void>}
287
+ * @example
288
+ * // Delete a role
289
+ * guild.roles.delete('222079219327434752', 'The role needed to go')
290
+ * .then(() => console.log('Deleted the role'))
291
+ * .catch(console.error);
292
+ */
293
+ async delete(role, reason) {
294
+ const id = this.resolveId(role);
295
+ await this.client.rest.delete(Routes.guildRole(this.guild.id, id), { reason });
296
+ this.client.actions.GuildRoleDelete.handle({ guild_id: this.guild.id, role_id: id });
297
+ }
298
+
299
+ /**
300
+ * Sets the new position of the role.
301
+ *
302
+ * @param {RoleResolvable} role The role to change the position of
303
+ * @param {number} position The new position for the role
304
+ * @param {SetRolePositionOptions} [options] Options for setting the position
305
+ * @returns {Promise<Role>}
306
+ * @example
307
+ * // Set the position of the role
308
+ * guild.roles.setPosition('222197033908436994', 1)
309
+ * .then(updated => console.log(`Role position: ${updated.position}`))
310
+ * .catch(console.error);
311
+ */
312
+ async setPosition(role, position, { relative, reason } = {}) {
313
+ const resolvedRole = this.resolve(role);
314
+ if (!resolvedRole) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'role', 'RoleResolvable');
315
+ const updatedRoles = await setPosition(
316
+ resolvedRole,
317
+ position,
318
+ relative,
319
+ this.guild._sortedRoles(),
320
+ this.client,
321
+ Routes.guildRoles(this.guild.id),
322
+ reason,
323
+ );
324
+
325
+ this.client.actions.GuildRolesPositionUpdate.handle({
326
+ guild_id: this.guild.id,
327
+ roles: updatedRoles,
328
+ });
329
+ return resolvedRole;
330
+ }
331
+
332
+ /**
333
+ * The data needed for updating a guild role's position
334
+ *
335
+ * @typedef {Object} GuildRolePosition
336
+ * @property {RoleResolvable} role The role's id
337
+ * @property {number} position The position to update
338
+ */
339
+
340
+ /**
341
+ * Batch-updates the guild's role positions
342
+ *
343
+ * @param {GuildRolePosition[]} rolePositions Role positions to update
344
+ * @returns {Promise<Guild>}
345
+ * @example
346
+ * guild.roles.setPositions([{ role: roleId, position: updatedRoleIndex }])
347
+ * .then(guild => console.log(`Role positions updated for ${guild}`))
348
+ * .catch(console.error);
349
+ */
350
+ async setPositions(rolePositions) {
351
+ // Make sure rolePositions are prepared for API
352
+ const resolvedRolePositions = rolePositions.map(rolePosition => ({
353
+ id: this.resolveId(rolePosition.role),
354
+ position: rolePosition.position,
355
+ }));
356
+
357
+ // Call the API to update role positions
358
+ await this.client.rest.patch(Routes.guildRoles(this.guild.id), { body: resolvedRolePositions });
359
+ return this.client.actions.GuildRolesPositionUpdate.handle({
360
+ guild_id: this.guild.id,
361
+ roles: resolvedRolePositions,
362
+ }).guild;
363
+ }
364
+
365
+ /**
366
+ * Compares the positions of two roles.
367
+ *
368
+ * @param {RoleResolvable} role1 First role to compare
369
+ * @param {RoleResolvable} role2 Second role to compare
370
+ * @returns {number} Negative number if the first role's position is lower (second role's is higher),
371
+ * positive number if the first's is higher (second's is lower), 0 if equal
372
+ */
373
+ comparePositions(role1, role2) {
374
+ const resolvedRole1 = this.resolve(role1);
375
+ const resolvedRole2 = this.resolve(role2);
376
+ if (!resolvedRole1 || !resolvedRole2) {
377
+ throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'role', 'Role nor a Snowflake');
378
+ }
379
+
380
+ const role1Position = resolvedRole1.position;
381
+ const role2Position = resolvedRole2.position;
382
+
383
+ if (role1Position === role2Position) {
384
+ return Number(BigInt(resolvedRole2.id) - BigInt(resolvedRole1.id));
385
+ }
386
+
387
+ return role1Position - role2Position;
388
+ }
389
+
390
+ /**
391
+ * Gets the managed role a user created when joining the guild, if any
392
+ * <info>Only ever available for bots</info>
393
+ *
394
+ * @param {UserResolvable} user The user to access the bot role for
395
+ * @returns {?Role}
396
+ */
397
+ botRoleFor(user) {
398
+ const userId = this.client.users.resolveId(user);
399
+ if (!userId) return null;
400
+ return this.cache.find(role => role.tags?.botId === userId) ?? null;
401
+ }
402
+
403
+ /**
404
+ * The `@everyone` role of the guild
405
+ *
406
+ * @type {Role}
407
+ * @readonly
408
+ */
409
+ get everyone() {
410
+ return this.cache.get(this.guild.id);
411
+ }
412
+
413
+ /**
414
+ * The premium subscriber role of the guild, if any
415
+ *
416
+ * @type {?Role}
417
+ * @readonly
418
+ */
419
+ get premiumSubscriberRole() {
420
+ return this.cache.find(role => role.tags?.premiumSubscriberRole) ?? null;
421
+ }
422
+
423
+ /**
424
+ * The role with the highest position in the cache
425
+ *
426
+ * @type {Role}
427
+ * @readonly
428
+ */
429
+ get highest() {
430
+ return this.cache.reduce((prev, role) => (role.comparePositionTo(prev) > 0 ? role : prev), this.cache.first());
431
+ }
432
+ }