@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,532 @@
1
+ import { setInterval, clearInterval } from 'node:timers';
2
+ import { DiscordjsTypeError, ErrorCodes } from '../errors/index.js';
3
+ import { ThreadChannelTypes, SweeperKeys } from './Constants.js';
4
+ import { Events } from './Events.js';
5
+
6
+ /**
7
+ * @typedef {Function} GlobalSweepFilter
8
+ * @returns {?Function} Return `null` to skip sweeping, otherwise a function passed to `sweep()`,
9
+ * See {@link https://discord.js.org/docs/packages/collection/stable/Collection:Class#sweep Collection#sweep}
10
+ * for the definition of this function.
11
+ */
12
+
13
+ /**
14
+ * A container for all cache sweeping intervals and their associated sweep methods.
15
+ */
16
+ export class Sweepers {
17
+ public client: any;
18
+ public options: any;
19
+ public intervals: any;
20
+ constructor(client, options) {
21
+ /**
22
+ * The client that instantiated this
23
+ *
24
+ * @type {Client}
25
+ * @readonly
26
+ */
27
+ Object.defineProperty(this, 'client', { value: client });
28
+
29
+ /**
30
+ * The options the sweepers were instantiated with
31
+ *
32
+ * @type {SweeperOptions}
33
+ */
34
+ this.options = options;
35
+
36
+ /**
37
+ * A record of interval timeout that is used to sweep the indicated items, or null if not being swept
38
+ *
39
+ * @type {Object<SweeperKey, ?Timeout>}
40
+ */
41
+ this.intervals = Object.fromEntries(SweeperKeys.map(key => [key, null]));
42
+
43
+ for (const key of SweeperKeys) {
44
+ if (!(key in options)) continue;
45
+
46
+ this._validateProperties(key);
47
+
48
+ const clonedOptions = { ...this.options[key] };
49
+
50
+ // Handle cases that have a "lifetime"
51
+ if (!('filter' in clonedOptions)) {
52
+ switch (key) {
53
+ case 'invites':
54
+ clonedOptions.filter = this.constructor.expiredInviteSweepFilter(clonedOptions.lifetime);
55
+ break;
56
+ case 'messages':
57
+ clonedOptions.filter = this.constructor.outdatedMessageSweepFilter(clonedOptions.lifetime);
58
+ break;
59
+ case 'threads':
60
+ clonedOptions.filter = this.constructor.archivedThreadSweepFilter(clonedOptions.lifetime);
61
+ break;
62
+ default:
63
+ break;
64
+ }
65
+ }
66
+
67
+ this._initInterval(key, `sweep${key[0].toUpperCase()}${key.slice(1)}`, clonedOptions);
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Sweeps all guild and global application commands and removes the ones which are indicated by the filter.
73
+ *
74
+ * @param {Function} filter The function used to determine which commands will be removed from the caches.
75
+ * @returns {number} Amount of commands that were removed from the caches
76
+ */
77
+ sweepApplicationCommands(filter) {
78
+ const { guilds, items: guildCommands } = this._sweepGuildDirectProp('commands', filter, { emit: false });
79
+
80
+ const globalCommands = this.client.application?.commands.cache.sweep(filter) ?? 0;
81
+
82
+ this.client.emit(
83
+ Events.CacheSweep,
84
+ `Swept ${globalCommands} global application commands and ${guildCommands} guild commands in ${guilds} guilds.`,
85
+ );
86
+ return guildCommands + globalCommands;
87
+ }
88
+
89
+ /**
90
+ * Sweeps all auto moderation rules and removes the ones which are indicated by the filter.
91
+ *
92
+ * @param {Function} filter The function used to determine
93
+ * which auto moderation rules will be removed from the caches
94
+ * @returns {number} Amount of auto moderation rules that were removed from the caches
95
+ */
96
+ sweepAutoModerationRules(filter) {
97
+ return this._sweepGuildDirectProp('autoModerationRules', filter).items;
98
+ }
99
+
100
+ /**
101
+ * Sweeps all guild bans and removes the ones which are indicated by the filter.
102
+ *
103
+ * @param {Function} filter The function used to determine which bans will be removed from the caches.
104
+ * @returns {number} Amount of bans that were removed from the caches
105
+ */
106
+ sweepBans(filter) {
107
+ return this._sweepGuildDirectProp('bans', filter).items;
108
+ }
109
+
110
+ /**
111
+ * Sweeps all guild emojis and removes the ones which are indicated by the filter.
112
+ *
113
+ * @param {Function} filter The function used to determine which emojis will be removed from the caches.
114
+ * @returns {number} Amount of emojis that were removed from the caches
115
+ */
116
+ sweepEmojis(filter) {
117
+ return this._sweepGuildDirectProp('emojis', filter).items;
118
+ }
119
+
120
+ /**
121
+ * Sweeps all client application entitlements and removes the ones which are indicated by the filter.
122
+ *
123
+ * @param {Function} filter The function used to determine which entitlements will be removed from the caches.
124
+ * @returns {number} Amount of entitlements that were removed from the caches
125
+ */
126
+ sweepEntitlements(filter) {
127
+ if (typeof filter !== 'function') {
128
+ throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'filter', 'function');
129
+ }
130
+
131
+ const entitlements = this.client.application.entitlements.cache.sweep(filter);
132
+
133
+ this.client.emit(Events.CacheSweep, `Swept ${entitlements} entitlements.`);
134
+
135
+ return entitlements;
136
+ }
137
+
138
+ /**
139
+ * Sweeps all guild invites and removes the ones which are indicated by the filter.
140
+ *
141
+ * @param {Function} filter The function used to determine which invites will be removed from the caches.
142
+ * @returns {number} Amount of invites that were removed from the caches
143
+ */
144
+ sweepInvites(filter) {
145
+ return this._sweepGuildDirectProp('invites', filter).items;
146
+ }
147
+
148
+ /**
149
+ * Sweeps all guild members and removes the ones which are indicated by the filter.
150
+ * <info>It is highly recommended to keep the client guild member cached</info>
151
+ *
152
+ * @param {Function} filter The function used to determine which guild members will be removed from the caches.
153
+ * @returns {number} Amount of guild members that were removed from the caches
154
+ */
155
+ sweepGuildMembers(filter) {
156
+ return this._sweepGuildDirectProp('members', filter, { outputName: 'guild members' }).items;
157
+ }
158
+
159
+ /**
160
+ * Sweeps all text-based channels' messages and removes the ones which are indicated by the filter.
161
+ *
162
+ * @param {Function} filter The function used to determine which messages will be removed from the caches.
163
+ * @returns {number} Amount of messages that were removed from the caches
164
+ * @example
165
+ * // Remove all messages older than 1800 seconds from the messages cache
166
+ * const amount = sweepers.sweepMessages(
167
+ * Sweepers.filterByLifetime({
168
+ * lifetime: 1800,
169
+ * getComparisonTimestamp: m => m.editedTimestamp ?? m.createdTimestamp,
170
+ * })(),
171
+ * );
172
+ * console.log(`Successfully removed ${amount} messages from the cache.`);
173
+ */
174
+ sweepMessages(filter) {
175
+ if (typeof filter !== 'function') {
176
+ throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'filter', 'function');
177
+ }
178
+
179
+ let channels = 0;
180
+ let messages = 0;
181
+
182
+ for (const channel of this.client.channels.cache.values()) {
183
+ if (!channel.isTextBased()) continue;
184
+
185
+ channels++;
186
+ messages += channel.messages.cache.sweep(filter);
187
+ }
188
+
189
+ this.client.emit(Events.CacheSweep, `Swept ${messages} messages in ${channels} text-based channels.`);
190
+ return messages;
191
+ }
192
+
193
+ /**
194
+ * Sweeps all presences and removes the ones which are indicated by the filter.
195
+ *
196
+ * @param {Function} filter The function used to determine which presences will be removed from the caches.
197
+ * @returns {number} Amount of presences that were removed from the caches
198
+ */
199
+ sweepPresences(filter) {
200
+ return this._sweepGuildDirectProp('presences', filter).items;
201
+ }
202
+
203
+ /**
204
+ * Sweeps all message reactions and removes the ones which are indicated by the filter.
205
+ *
206
+ * @param {Function} filter The function used to determine which reactions will be removed from the caches.
207
+ * @returns {number} Amount of reactions that were removed from the caches
208
+ */
209
+ sweepReactions(filter) {
210
+ if (typeof filter !== 'function') {
211
+ throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'filter', 'function');
212
+ }
213
+
214
+ let channels = 0;
215
+ let messages = 0;
216
+ let reactions = 0;
217
+
218
+ for (const channel of this.client.channels.cache.values()) {
219
+ if (!channel.isTextBased()) continue;
220
+ channels++;
221
+
222
+ for (const message of channel.messages.cache.values()) {
223
+ messages++;
224
+ reactions += message.reactions.cache.sweep(filter);
225
+ }
226
+ }
227
+
228
+ this.client.emit(
229
+ Events.CacheSweep,
230
+ `Swept ${reactions} reactions on ${messages} messages in ${channels} text-based channels.`,
231
+ );
232
+ return reactions;
233
+ }
234
+
235
+ /**
236
+ * Sweeps all guild stage instances and removes the ones which are indicated by the filter.
237
+ *
238
+ * @param {Function} filter The function used to determine which stage instances will be removed from the caches.
239
+ * @returns {number} Amount of stage instances that were removed from the caches
240
+ */
241
+ sweepStageInstances(filter) {
242
+ return this._sweepGuildDirectProp('stageInstances', filter, { outputName: 'stage instances' }).items;
243
+ }
244
+
245
+ /**
246
+ * Sweeps all guild stickers and removes the ones which are indicated by the filter.
247
+ *
248
+ * @param {Function} filter The function used to determine which stickers will be removed from the caches.
249
+ * @returns {number} Amount of stickers that were removed from the caches
250
+ */
251
+ sweepStickers(filter) {
252
+ return this._sweepGuildDirectProp('stickers', filter).items;
253
+ }
254
+
255
+ /**
256
+ * Sweeps all thread members and removes the ones which are indicated by the filter.
257
+ * <info>It is highly recommended to keep the client thread member cached</info>
258
+ *
259
+ * @param {Function} filter The function used to determine which thread members will be removed from the caches.
260
+ * @returns {number} Amount of thread members that were removed from the caches
261
+ */
262
+ sweepThreadMembers(filter) {
263
+ if (typeof filter !== 'function') {
264
+ throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'filter', 'function');
265
+ }
266
+
267
+ let threads = 0;
268
+ let members = 0;
269
+ for (const channel of this.client.channels.cache.values()) {
270
+ if (!ThreadChannelTypes.includes(channel.type)) continue;
271
+ threads++;
272
+ members += channel.members.cache.sweep(filter);
273
+ }
274
+
275
+ this.client.emit(Events.CacheSweep, `Swept ${members} thread members in ${threads} threads.`);
276
+ return members;
277
+ }
278
+
279
+ /**
280
+ * Sweeps all threads and removes the ones which are indicated by the filter.
281
+ *
282
+ * @param {Function} filter The function used to determine which threads will be removed from the caches.
283
+ * @returns {number} filter Amount of threads that were removed from the caches
284
+ * @example
285
+ * // Remove all threads archived greater than 1 day ago from all the channel caches
286
+ * const amount = sweepers.sweepThreads(
287
+ * Sweepers.filterByLifetime({
288
+ * getComparisonTimestamp: t => t.archivedTimestamp,
289
+ * excludeFromSweep: t => !t.archived,
290
+ * })(),
291
+ * );
292
+ * console.log(`Successfully removed ${amount} threads from the cache.`);
293
+ */
294
+ sweepThreads(filter) {
295
+ if (typeof filter !== 'function') {
296
+ throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'filter', 'function');
297
+ }
298
+
299
+ let threads = 0;
300
+ for (const [key, val] of this.client.channels.cache.entries()) {
301
+ if (!ThreadChannelTypes.includes(val.type)) continue;
302
+ if (filter(val, key, this.client.channels.cache)) {
303
+ threads++;
304
+ this.client.channels._remove(key);
305
+ }
306
+ }
307
+
308
+ this.client.emit(Events.CacheSweep, `Swept ${threads} threads.`);
309
+ return threads;
310
+ }
311
+
312
+ /**
313
+ * Sweeps all users and removes the ones which are indicated by the filter.
314
+ *
315
+ * @param {Function} filter The function used to determine which users will be removed from the caches.
316
+ * @returns {number} Amount of users that were removed from the caches
317
+ */
318
+ sweepUsers(filter) {
319
+ if (typeof filter !== 'function') {
320
+ throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'filter', 'function');
321
+ }
322
+
323
+ const users = this.client.users.cache.sweep(filter);
324
+
325
+ this.client.emit(Events.CacheSweep, `Swept ${users} users.`);
326
+
327
+ return users;
328
+ }
329
+
330
+ /**
331
+ * Sweeps all guild voice states and removes the ones which are indicated by the filter.
332
+ *
333
+ * @param {Function} filter The function used to determine which voice states will be removed from the caches.
334
+ * @returns {number} Amount of voice states that were removed from the caches
335
+ */
336
+ sweepVoiceStates(filter) {
337
+ return this._sweepGuildDirectProp('voiceStates', filter, { outputName: 'voice states' }).items;
338
+ }
339
+
340
+ /**
341
+ * Cancels all sweeping intervals
342
+ *
343
+ * @returns {void}
344
+ */
345
+ destroy() {
346
+ for (const key of SweeperKeys) {
347
+ if (this.intervals[key]) clearInterval(this.intervals[key]);
348
+ }
349
+ }
350
+
351
+ /**
352
+ * Options for generating a filter function based on lifetime
353
+ *
354
+ * @typedef {Object} LifetimeFilterOptions
355
+ * @property {number} [lifetime=14400] How long, in seconds, an entry should stay in the collection
356
+ * before it is considered sweepable.
357
+ * @property {Function} [getComparisonTimestamp=e => e?.createdTimestamp] A function that takes an entry, key,
358
+ * and the collection and returns a timestamp to compare against in order to determine the lifetime of the entry.
359
+ * @property {Function} [excludeFromSweep=() => false] A function that takes an entry, key, and the collection
360
+ * and returns a boolean, `true` when the entry should not be checked for sweepability.
361
+ */
362
+
363
+ /**
364
+ * Create a sweepFilter function that uses a lifetime to determine sweepability.
365
+ *
366
+ * @param {LifetimeFilterOptions} [options={}] The options used to generate the filter function
367
+ * @returns {GlobalSweepFilter}
368
+ */
369
+ static filterByLifetime({
370
+ lifetime = 14_400,
371
+ getComparisonTimestamp = item => item?.createdTimestamp,
372
+ excludeFromSweep = () => false,
373
+ } = {}) {
374
+ if (typeof lifetime !== 'number') {
375
+ throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'lifetime', 'number');
376
+ }
377
+
378
+ if (typeof getComparisonTimestamp !== 'function') {
379
+ throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'getComparisonTimestamp', 'function');
380
+ }
381
+
382
+ if (typeof excludeFromSweep !== 'function') {
383
+ throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'excludeFromSweep', 'function');
384
+ }
385
+
386
+ return () => {
387
+ if (lifetime <= 0) return null;
388
+ const lifetimeMs = lifetime * 1_000;
389
+ const now = Date.now();
390
+ return (entry, key, coll) => {
391
+ if (excludeFromSweep(entry, key, coll)) {
392
+ return false;
393
+ }
394
+
395
+ const comparisonTimestamp = getComparisonTimestamp(entry, key, coll);
396
+ if (!comparisonTimestamp || typeof comparisonTimestamp !== 'number') return false;
397
+ return now - comparisonTimestamp > lifetimeMs;
398
+ };
399
+ };
400
+ }
401
+
402
+ /**
403
+ * Creates a sweep filter that sweeps archived threads
404
+ *
405
+ * @param {number} [lifetime=14400] How long a thread has to be archived to be valid for sweeping
406
+ * @returns {GlobalSweepFilter}
407
+ */
408
+ static archivedThreadSweepFilter(lifetime = 14_400) {
409
+ return this.filterByLifetime({
410
+ lifetime,
411
+ getComparisonTimestamp: thread => thread.archiveTimestamp,
412
+ excludeFromSweep: thread => !thread.archived,
413
+ });
414
+ }
415
+
416
+ /**
417
+ * Creates a sweep filter that sweeps expired invites
418
+ *
419
+ * @param {number} [lifetime=14400] How long ago an invite has to have expired to be valid for sweeping
420
+ * @returns {GlobalSweepFilter}
421
+ */
422
+ static expiredInviteSweepFilter(lifetime = 14_400) {
423
+ return this.filterByLifetime({
424
+ lifetime,
425
+ getComparisonTimestamp: invite => invite.expiresTimestamp,
426
+ });
427
+ }
428
+
429
+ /**
430
+ * Creates a sweep filter that sweeps outdated messages (edits taken into account)
431
+ *
432
+ * @param {number} [lifetime=3600] How long ago a message has to have been sent or edited to be valid for sweeping
433
+ * @returns {GlobalSweepFilter}
434
+ */
435
+ static outdatedMessageSweepFilter(lifetime = 3_600) {
436
+ return this.filterByLifetime({
437
+ lifetime,
438
+ getComparisonTimestamp: message => message.editedTimestamp ?? message.createdTimestamp,
439
+ });
440
+ }
441
+
442
+ /**
443
+ * Configuration options for emitting the cache sweep client event
444
+ *
445
+ * @typedef {Object} SweepEventOptions
446
+ * @property {boolean} [emit=true] Whether to emit the client event in this method
447
+ * @property {string} [outputName] A name to output in the client event if it should differ from the key
448
+ * @private
449
+ */
450
+
451
+ /**
452
+ * Sweep a direct sub property of all guilds
453
+ *
454
+ * @param {string} key The name of the property
455
+ * @param {Function} filter Filter function passed to sweep
456
+ * @param {SweepEventOptions} [eventOptions={}] Options for the Client event emitted here
457
+ * @returns {Object} Object containing the number of guilds swept and the number of items swept
458
+ * @private
459
+ */
460
+ _sweepGuildDirectProp(key, filter, { emit = true, outputName } = {}) {
461
+ if (typeof filter !== 'function') {
462
+ throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'filter', 'function');
463
+ }
464
+
465
+ let guilds = 0;
466
+ let items = 0;
467
+
468
+ for (const guild of this.client.guilds.cache.values()) {
469
+ // We may be unable to sweep the cache if the guild is unavailable and was never patched
470
+ if (!guild.available) continue;
471
+
472
+ const { cache } = guild[key];
473
+
474
+ guilds++;
475
+ items += cache.sweep(filter);
476
+ }
477
+
478
+ if (emit) {
479
+ this.client.emit(Events.CacheSweep, `Swept ${items} ${outputName ?? key} in ${guilds} guilds.`);
480
+ }
481
+
482
+ return { guilds, items };
483
+ }
484
+
485
+ /**
486
+ * Validates a set of properties
487
+ *
488
+ * @param {string} key Key of the options object to check
489
+ * @private
490
+ */
491
+ _validateProperties(key) {
492
+ const props = this.options[key];
493
+ if (typeof props !== 'object') {
494
+ throw new DiscordjsTypeError(ErrorCodes.InvalidType, `sweepers.${key}`, 'object', true);
495
+ }
496
+
497
+ if (typeof props.interval !== 'number') {
498
+ throw new DiscordjsTypeError(ErrorCodes.InvalidType, `sweepers.${key}.interval`, 'number');
499
+ }
500
+
501
+ // Invites, Messages, and Threads can be provided a lifetime parameter, which we use to generate the filter
502
+ if (['invites', 'messages', 'threads'].includes(key) && !('filter' in props)) {
503
+ if (typeof props.lifetime !== 'number') {
504
+ throw new DiscordjsTypeError(ErrorCodes.InvalidType, `sweepers.${key}.lifetime`, 'number');
505
+ }
506
+
507
+ return;
508
+ }
509
+
510
+ if (typeof props.filter !== 'function') {
511
+ throw new DiscordjsTypeError(ErrorCodes.InvalidType, `sweepers.${key}.filter`, 'function');
512
+ }
513
+ }
514
+
515
+ /**
516
+ * Initialize an interval for sweeping
517
+ *
518
+ * @param {string} intervalKey The name of the property that stores the interval for this sweeper
519
+ * @param {string} sweepKey The name of the function that sweeps the desired caches
520
+ * @param {Object} opts Validated options for a sweep
521
+ * @private
522
+ */
523
+ _initInterval(intervalKey, sweepKey, opts) {
524
+ if (opts.interval <= 0 || opts.interval === Infinity) return;
525
+ this.intervals[intervalKey] = setInterval(() => {
526
+ const sweepFn = opts.filter();
527
+ if (sweepFn === null) return;
528
+ if (typeof sweepFn !== 'function') throw new DiscordjsTypeError(ErrorCodes.SweepFilterReturn);
529
+ this[sweepKey](sweepFn);
530
+ }, opts.interval * 1_000).unref();
531
+ }
532
+ }
@@ -0,0 +1 @@
1
+ export const MakeCacheOverrideSymbol = Symbol('djs.managers.makeCacheOverride');
@@ -0,0 +1,45 @@
1
+ /* eslint-disable jsdoc/check-values */
2
+
3
+ import { GuildSystemChannelFlags } from 'discord-api-types/v10';
4
+ import { BitField } from './BitField.js';
5
+
6
+ /**
7
+ * Data structure that makes it easy to interact with a {@link Guild#systemChannelFlags} bitfield.
8
+ * <info>Note that all event message types are enabled by default,
9
+ * and by setting their corresponding flags you are disabling them</info>
10
+ *
11
+ * @extends {BitField}
12
+ */
13
+ export class SystemChannelFlagsBitField extends BitField {
14
+ /**
15
+ * Numeric system channel flags.
16
+ *
17
+ * @type {GuildSystemChannelFlags}
18
+ * @memberof SystemChannelFlagsBitField
19
+ */
20
+ static Flags = GuildSystemChannelFlags;
21
+ }
22
+
23
+ /**
24
+ * @name SystemChannelFlagsBitField
25
+ * @kind constructor
26
+ * @memberof SystemChannelFlagsBitField
27
+ * @param {SystemChannelFlagsResolvable} [bits=0] Bit(s) to read from
28
+ */
29
+
30
+ /**
31
+ * Bitfield of the packed bits
32
+ *
33
+ * @type {number}
34
+ * @name SystemChannelFlagsBitField#bitfield
35
+ */
36
+
37
+ /**
38
+ * Data that can be resolved to give a system channel flag bitfield. This can be:
39
+ * - A string (see {@link SystemChannelFlagsBitField.Flags})
40
+ * - A system channel flag
41
+ * - An instance of SystemChannelFlagsBitField
42
+ * - An Array of SystemChannelFlagsResolvable
43
+ *
44
+ * @typedef {string|number|SystemChannelFlagsBitField|SystemChannelFlagsResolvable[]} SystemChannelFlagsResolvable
45
+ */
@@ -0,0 +1,33 @@
1
+ /* eslint-disable jsdoc/check-values */
2
+
3
+ import { ThreadMemberFlags } from 'discord-api-types/v10';
4
+ import { BitField } from './BitField.js';
5
+
6
+ /**
7
+ * Data structure that makes it easy to interact with a {@link ThreadMember#flags} bitfield.
8
+ *
9
+ * @extends {BitField}
10
+ */
11
+ export class ThreadMemberFlagsBitField extends BitField {
12
+ /**
13
+ * Numeric thread member flags. There are currently no bitflags relevant to bots for this.
14
+ *
15
+ * @type {ThreadMemberFlags}
16
+ * @memberof ThreadMemberFlagsBitField
17
+ */
18
+ static Flags = ThreadMemberFlags;
19
+ }
20
+
21
+ /**
22
+ * @name ThreadMemberFlagsBitField
23
+ * @kind constructor
24
+ * @memberof ThreadMemberFlagsBitField
25
+ * @param {BitFieldResolvable} [bits=0] Bit(s) to read from
26
+ */
27
+
28
+ /**
29
+ * Bitfield of the packed bits
30
+ *
31
+ * @type {number}
32
+ * @name ThreadMemberFlagsBitField#bitfield
33
+ */