djs-selfbot-v13 3.1.8 → 3.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (364) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +48 -37
  3. package/package.json +44 -26
  4. package/src/WebSocket.js +39 -39
  5. package/src/client/BaseClient.js +86 -86
  6. package/src/client/Client.js +934 -765
  7. package/src/client/WebhookClient.js +61 -61
  8. package/src/client/actions/Action.js +116 -120
  9. package/src/client/actions/ActionsManager.js +80 -78
  10. package/src/client/actions/ApplicationCommandPermissionsUpdate.js +34 -34
  11. package/src/client/actions/AutoModerationActionExecution.js +27 -27
  12. package/src/client/actions/AutoModerationRuleCreate.js +28 -28
  13. package/src/client/actions/AutoModerationRuleDelete.js +32 -32
  14. package/src/client/actions/AutoModerationRuleUpdate.js +30 -30
  15. package/src/client/actions/ChannelCreate.js +23 -23
  16. package/src/client/actions/ChannelDelete.js +39 -39
  17. package/src/client/actions/ChannelUpdate.js +43 -43
  18. package/src/client/actions/GuildAuditLogEntryCreate.js +29 -29
  19. package/src/client/actions/GuildBanAdd.js +20 -20
  20. package/src/client/actions/GuildBanRemove.js +25 -25
  21. package/src/client/actions/GuildChannelsPositionUpdate.js +21 -21
  22. package/src/client/actions/GuildDelete.js +65 -65
  23. package/src/client/actions/GuildEmojiCreate.js +20 -20
  24. package/src/client/actions/GuildEmojiDelete.js +21 -21
  25. package/src/client/actions/GuildEmojiUpdate.js +20 -20
  26. package/src/client/actions/GuildEmojisUpdate.js +34 -34
  27. package/src/client/actions/GuildIntegrationsUpdate.js +19 -19
  28. package/src/client/actions/GuildMemberRemove.js +33 -33
  29. package/src/client/actions/GuildMemberUpdate.js +44 -44
  30. package/src/client/actions/GuildRoleCreate.js +25 -25
  31. package/src/client/actions/GuildRoleDelete.js +31 -31
  32. package/src/client/actions/GuildRoleUpdate.js +39 -39
  33. package/src/client/actions/GuildRolesPositionUpdate.js +21 -21
  34. package/src/client/actions/GuildScheduledEventCreate.js +27 -27
  35. package/src/client/actions/GuildScheduledEventDelete.js +31 -31
  36. package/src/client/actions/GuildScheduledEventUpdate.js +30 -30
  37. package/src/client/actions/GuildScheduledEventUserAdd.js +32 -32
  38. package/src/client/actions/GuildScheduledEventUserRemove.js +32 -32
  39. package/src/client/actions/GuildStickerCreate.js +20 -20
  40. package/src/client/actions/GuildStickerDelete.js +21 -21
  41. package/src/client/actions/GuildStickerUpdate.js +20 -20
  42. package/src/client/actions/GuildStickersUpdate.js +34 -34
  43. package/src/client/actions/GuildUpdate.js +33 -33
  44. package/src/client/actions/InviteCreate.js +28 -28
  45. package/src/client/actions/InviteDelete.js +30 -30
  46. package/src/client/actions/MessageCreate.js +50 -46
  47. package/src/client/actions/MessageDelete.js +32 -32
  48. package/src/client/actions/MessageDeleteBulk.js +46 -46
  49. package/src/client/actions/MessagePollVoteAdd.js +33 -0
  50. package/src/client/actions/MessagePollVoteRemove.js +33 -0
  51. package/src/client/actions/MessageReactionAdd.js +68 -56
  52. package/src/client/actions/MessageReactionRemove.js +50 -45
  53. package/src/client/actions/MessageReactionRemoveAll.js +33 -33
  54. package/src/client/actions/MessageReactionRemoveEmoji.js +28 -28
  55. package/src/client/actions/MessageUpdate.js +26 -26
  56. package/src/client/actions/PresenceUpdate.js +50 -46
  57. package/src/client/actions/StageInstanceCreate.js +28 -28
  58. package/src/client/actions/StageInstanceDelete.js +33 -33
  59. package/src/client/actions/StageInstanceUpdate.js +30 -30
  60. package/src/client/actions/ThreadCreate.js +24 -24
  61. package/src/client/actions/ThreadDelete.js +32 -32
  62. package/src/client/actions/ThreadListSync.js +59 -59
  63. package/src/client/actions/ThreadMemberUpdate.js +30 -30
  64. package/src/client/actions/ThreadMembersUpdate.js +34 -34
  65. package/src/client/actions/TypingStart.js +29 -29
  66. package/src/client/actions/UserUpdate.js +35 -35
  67. package/src/client/actions/VoiceStateUpdate.js +50 -57
  68. package/src/client/actions/WebhooksUpdate.js +20 -20
  69. package/src/client/voice/ClientVoiceManager.js +151 -51
  70. package/src/client/voice/VoiceConnection.js +1249 -0
  71. package/src/client/voice/dispatcher/AnnexBDispatcher.js +120 -0
  72. package/src/client/voice/dispatcher/AudioDispatcher.js +145 -0
  73. package/src/client/voice/dispatcher/BaseDispatcher.js +459 -0
  74. package/src/client/voice/dispatcher/VPxDispatcher.js +54 -0
  75. package/src/client/voice/dispatcher/VideoDispatcher.js +68 -0
  76. package/src/client/voice/networking/VoiceUDPClient.js +173 -0
  77. package/src/client/voice/networking/VoiceWebSocket.js +286 -0
  78. package/src/client/voice/player/MediaPlayer.js +321 -0
  79. package/src/client/voice/player/processing/AnnexBNalSplitter.js +244 -0
  80. package/src/client/voice/player/processing/IvfSplitter.js +106 -0
  81. package/src/client/voice/player/processing/PCMInsertSilence.js +37 -0
  82. package/src/client/voice/receiver/PacketHandler.js +260 -0
  83. package/src/client/voice/receiver/Receiver.js +96 -0
  84. package/src/client/voice/receiver/Recorder.js +173 -0
  85. package/src/client/voice/util/Function.js +116 -0
  86. package/src/client/voice/util/PlayInterface.js +122 -0
  87. package/src/client/voice/util/Secretbox.js +64 -0
  88. package/src/client/voice/util/Silence.js +16 -0
  89. package/src/client/voice/util/Socket.js +62 -0
  90. package/src/client/voice/util/VolumeInterface.js +104 -0
  91. package/src/client/websocket/WebSocketManager.js +392 -392
  92. package/src/client/websocket/WebSocketShard.js +907 -906
  93. package/src/client/websocket/handlers/APPLICATION_COMMAND_CREATE.js +18 -18
  94. package/src/client/websocket/handlers/APPLICATION_COMMAND_DELETE.js +20 -20
  95. package/src/client/websocket/handlers/APPLICATION_COMMAND_PERMISSIONS_UPDATE.js +5 -5
  96. package/src/client/websocket/handlers/APPLICATION_COMMAND_UPDATE.js +20 -20
  97. package/src/client/websocket/handlers/AUTO_MODERATION_ACTION_EXECUTION.js +5 -5
  98. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_CREATE.js +5 -5
  99. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_DELETE.js +5 -5
  100. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_UPDATE.js +5 -5
  101. package/src/client/websocket/handlers/CALL_CREATE.js +14 -14
  102. package/src/client/websocket/handlers/CALL_DELETE.js +11 -11
  103. package/src/client/websocket/handlers/CALL_UPDATE.js +11 -11
  104. package/src/client/websocket/handlers/CHANNEL_CREATE.js +5 -5
  105. package/src/client/websocket/handlers/CHANNEL_DELETE.js +5 -5
  106. package/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.js +22 -22
  107. package/src/client/websocket/handlers/CHANNEL_RECIPIENT_ADD.js +19 -19
  108. package/src/client/websocket/handlers/CHANNEL_RECIPIENT_REMOVE.js +16 -16
  109. package/src/client/websocket/handlers/CHANNEL_UPDATE.js +16 -16
  110. package/src/client/websocket/handlers/GUILD_AUDIT_LOG_ENTRY_CREATE.js +5 -5
  111. package/src/client/websocket/handlers/GUILD_BAN_ADD.js +5 -5
  112. package/src/client/websocket/handlers/GUILD_BAN_REMOVE.js +5 -5
  113. package/src/client/websocket/handlers/GUILD_CREATE.js +52 -53
  114. package/src/client/websocket/handlers/GUILD_DELETE.js +5 -5
  115. package/src/client/websocket/handlers/GUILD_EMOJIS_UPDATE.js +5 -5
  116. package/src/client/websocket/handlers/GUILD_INTEGRATIONS_UPDATE.js +5 -5
  117. package/src/client/websocket/handlers/GUILD_MEMBERS_CHUNK.js +39 -39
  118. package/src/client/websocket/handlers/GUILD_MEMBER_ADD.js +20 -20
  119. package/src/client/websocket/handlers/GUILD_MEMBER_REMOVE.js +5 -5
  120. package/src/client/websocket/handlers/GUILD_MEMBER_UPDATE.js +5 -5
  121. package/src/client/websocket/handlers/GUILD_ROLE_CREATE.js +5 -5
  122. package/src/client/websocket/handlers/GUILD_ROLE_DELETE.js +5 -5
  123. package/src/client/websocket/handlers/GUILD_ROLE_UPDATE.js +5 -5
  124. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_CREATE.js +5 -5
  125. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_DELETE.js +5 -5
  126. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_UPDATE.js +5 -5
  127. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_ADD.js +5 -5
  128. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_REMOVE.js +5 -5
  129. package/src/client/websocket/handlers/GUILD_STICKERS_UPDATE.js +5 -5
  130. package/src/client/websocket/handlers/GUILD_UPDATE.js +5 -5
  131. package/src/client/websocket/handlers/INTERACTION_MODAL_CREATE.js +12 -12
  132. package/src/client/websocket/handlers/INVITE_CREATE.js +5 -5
  133. package/src/client/websocket/handlers/INVITE_DELETE.js +5 -5
  134. package/src/client/websocket/handlers/MESSAGE_CREATE.js +5 -5
  135. package/src/client/websocket/handlers/MESSAGE_DELETE.js +5 -5
  136. package/src/client/websocket/handlers/MESSAGE_DELETE_BULK.js +5 -5
  137. package/src/client/websocket/handlers/MESSAGE_POLL_VOTE_ADD.js +5 -0
  138. package/src/client/websocket/handlers/MESSAGE_POLL_VOTE_REMOVE.js +5 -0
  139. package/src/client/websocket/handlers/MESSAGE_REACTION_ADD.js +5 -5
  140. package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE.js +5 -5
  141. package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_ALL.js +5 -5
  142. package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_EMOJI.js +5 -5
  143. package/src/client/websocket/handlers/MESSAGE_UPDATE.js +16 -16
  144. package/src/client/websocket/handlers/PRESENCE_UPDATE.js +5 -5
  145. package/src/client/websocket/handlers/READY.js +121 -80
  146. package/src/client/websocket/handlers/RELATIONSHIP_ADD.js +19 -19
  147. package/src/client/websocket/handlers/RELATIONSHIP_REMOVE.js +17 -17
  148. package/src/client/websocket/handlers/RELATIONSHIP_UPDATE.js +41 -41
  149. package/src/client/websocket/handlers/RESUMED.js +14 -14
  150. package/src/client/websocket/handlers/STAGE_INSTANCE_CREATE.js +5 -5
  151. package/src/client/websocket/handlers/STAGE_INSTANCE_DELETE.js +5 -5
  152. package/src/client/websocket/handlers/STAGE_INSTANCE_UPDATE.js +5 -5
  153. package/src/client/websocket/handlers/THREAD_CREATE.js +5 -5
  154. package/src/client/websocket/handlers/THREAD_DELETE.js +5 -5
  155. package/src/client/websocket/handlers/THREAD_LIST_SYNC.js +5 -5
  156. package/src/client/websocket/handlers/THREAD_MEMBERS_UPDATE.js +5 -5
  157. package/src/client/websocket/handlers/THREAD_MEMBER_UPDATE.js +5 -5
  158. package/src/client/websocket/handlers/THREAD_UPDATE.js +16 -16
  159. package/src/client/websocket/handlers/TYPING_START.js +5 -5
  160. package/src/client/websocket/handlers/USER_GUILD_SETTINGS_UPDATE.js +6 -6
  161. package/src/client/websocket/handlers/USER_NOTE_UPDATE.js +5 -5
  162. package/src/client/websocket/handlers/USER_REQUIRED_ACTION_UPDATE.js +78 -78
  163. package/src/client/websocket/handlers/USER_SETTINGS_UPDATE.js +5 -5
  164. package/src/client/websocket/handlers/USER_UPDATE.js +5 -5
  165. package/src/client/websocket/handlers/VOICE_CHANNEL_EFFECT_SEND.js +16 -0
  166. package/src/client/websocket/handlers/VOICE_CHANNEL_STATUS_UPDATE.js +12 -12
  167. package/src/client/websocket/handlers/VOICE_SERVER_UPDATE.js +6 -6
  168. package/src/client/websocket/handlers/VOICE_STATE_UPDATE.js +5 -5
  169. package/src/client/websocket/handlers/WEBHOOKS_UPDATE.js +5 -5
  170. package/src/client/websocket/handlers/index.js +84 -81
  171. package/src/errors/DJSError.js +61 -61
  172. package/src/errors/Messages.js +217 -182
  173. package/src/errors/index.js +4 -4
  174. package/src/index.js +172 -158
  175. package/src/managers/ApplicationCommandManager.js +264 -264
  176. package/src/managers/ApplicationCommandPermissionsManager.js +417 -417
  177. package/src/managers/AutoModerationRuleManager.js +296 -296
  178. package/src/managers/BaseGuildEmojiManager.js +80 -80
  179. package/src/managers/BaseManager.js +19 -19
  180. package/src/managers/BillingManager.js +66 -66
  181. package/src/managers/CachedManager.js +71 -71
  182. package/src/managers/ChannelManager.js +148 -138
  183. package/src/managers/ClientUserSettingManager.js +372 -372
  184. package/src/managers/DataManager.js +61 -61
  185. package/src/managers/GuildBanManager.js +250 -204
  186. package/src/managers/GuildChannelManager.js +488 -504
  187. package/src/managers/GuildEmojiManager.js +171 -171
  188. package/src/managers/GuildEmojiRoleManager.js +118 -118
  189. package/src/managers/GuildForumThreadManager.js +108 -108
  190. package/src/managers/GuildInviteManager.js +213 -213
  191. package/src/managers/GuildManager.js +338 -304
  192. package/src/managers/GuildMemberManager.js +599 -593
  193. package/src/managers/GuildMemberRoleManager.js +195 -191
  194. package/src/managers/GuildScheduledEventManager.js +314 -296
  195. package/src/managers/GuildSettingManager.js +155 -155
  196. package/src/managers/GuildStickerManager.js +179 -179
  197. package/src/managers/GuildTextThreadManager.js +98 -98
  198. package/src/managers/InteractionManager.js +39 -39
  199. package/src/managers/MessageManager.js +423 -391
  200. package/src/managers/PermissionOverwriteManager.js +164 -166
  201. package/src/managers/PresenceManager.js +71 -58
  202. package/src/managers/ReactionManager.js +67 -67
  203. package/src/managers/ReactionUserManager.js +73 -71
  204. package/src/managers/RelationshipManager.js +278 -265
  205. package/src/managers/RoleManager.js +448 -352
  206. package/src/managers/SessionManager.js +66 -0
  207. package/src/managers/StageInstanceManager.js +162 -162
  208. package/src/managers/ThreadManager.js +175 -174
  209. package/src/managers/ThreadMemberManager.js +186 -186
  210. package/src/managers/UserManager.js +136 -146
  211. package/src/managers/UserNoteManager.js +53 -53
  212. package/src/managers/VoiceStateManager.js +59 -37
  213. package/src/rest/APIRequest.js +154 -154
  214. package/src/rest/APIRouter.js +53 -53
  215. package/src/rest/DiscordAPIError.js +119 -104
  216. package/src/rest/HTTPError.js +62 -62
  217. package/src/rest/RESTManager.js +67 -62
  218. package/src/rest/RateLimitError.js +55 -55
  219. package/src/rest/RequestHandler.js +466 -444
  220. package/src/sharding/Shard.js +444 -443
  221. package/src/sharding/ShardClientUtil.js +279 -275
  222. package/src/sharding/ShardingManager.js +319 -318
  223. package/src/structures/AnonymousGuild.js +98 -98
  224. package/src/structures/ApplicationCommand.js +593 -593
  225. package/src/structures/ApplicationRoleConnectionMetadata.js +48 -48
  226. package/src/structures/AutoModerationActionExecution.js +89 -89
  227. package/src/structures/AutoModerationRule.js +294 -294
  228. package/src/structures/AutocompleteInteraction.js +107 -107
  229. package/src/structures/Base.js +43 -43
  230. package/src/structures/BaseCommandInteraction.js +211 -211
  231. package/src/structures/BaseGuild.js +116 -116
  232. package/src/structures/BaseGuildEmoji.js +56 -56
  233. package/src/structures/BaseGuildTextChannel.js +191 -191
  234. package/src/structures/BaseGuildVoiceChannel.js +241 -241
  235. package/src/structures/BaseMessageComponent.js +181 -114
  236. package/src/structures/ButtonInteraction.js +11 -11
  237. package/src/structures/CallState.js +63 -63
  238. package/src/structures/CategoryChannel.js +85 -85
  239. package/src/structures/Channel.js +284 -270
  240. package/src/structures/ClientPresence.js +77 -88
  241. package/src/structures/ClientUser.js +479 -450
  242. package/src/structures/CommandInteraction.js +41 -41
  243. package/src/structures/CommandInteractionOptionResolver.js +276 -276
  244. package/src/structures/ContainerComponent.js +68 -0
  245. package/src/structures/ContextMenuInteraction.js +65 -65
  246. package/src/structures/DMChannel.js +219 -217
  247. package/src/structures/DirectoryChannel.js +20 -20
  248. package/src/structures/Emoji.js +148 -148
  249. package/src/structures/FileComponent.js +49 -0
  250. package/src/structures/ForumChannel.js +31 -261
  251. package/src/structures/GroupDMChannel.js +394 -387
  252. package/src/structures/Guild.js +1643 -1608
  253. package/src/structures/GuildAuditLogs.js +746 -729
  254. package/src/structures/GuildBan.js +59 -59
  255. package/src/structures/GuildBoost.js +108 -108
  256. package/src/structures/GuildChannel.js +470 -468
  257. package/src/structures/GuildEmoji.js +161 -161
  258. package/src/structures/GuildMember.js +636 -568
  259. package/src/structures/GuildPreview.js +191 -191
  260. package/src/structures/GuildPreviewEmoji.js +27 -27
  261. package/src/structures/GuildScheduledEvent.js +536 -441
  262. package/src/structures/GuildTemplate.js +236 -236
  263. package/src/structures/Integration.js +188 -188
  264. package/src/structures/IntegrationApplication.js +96 -96
  265. package/src/structures/Interaction.js +290 -290
  266. package/src/structures/InteractionCollector.js +248 -248
  267. package/src/structures/InteractionWebhook.js +43 -43
  268. package/src/structures/Invite.js +358 -358
  269. package/src/structures/InviteGuild.js +23 -23
  270. package/src/structures/InviteStageInstance.js +86 -86
  271. package/src/structures/MediaChannel.js +11 -0
  272. package/src/structures/MediaGalleryComponent.js +41 -0
  273. package/src/structures/MediaGalleryItem.js +47 -0
  274. package/src/structures/Message.js +1252 -1236
  275. package/src/structures/MessageActionRow.js +105 -103
  276. package/src/structures/MessageAttachment.js +216 -204
  277. package/src/structures/MessageButton.js +166 -165
  278. package/src/structures/MessageCollector.js +146 -146
  279. package/src/structures/MessageComponentInteraction.js +120 -120
  280. package/src/structures/MessageContextMenuInteraction.js +20 -20
  281. package/src/structures/MessageEmbed.js +596 -586
  282. package/src/structures/MessageMentions.js +273 -273
  283. package/src/structures/MessagePayload.js +354 -316
  284. package/src/structures/MessageReaction.js +181 -171
  285. package/src/structures/MessageSelectMenu.js +141 -140
  286. package/src/structures/Modal.js +161 -174
  287. package/src/structures/ModalSubmitFieldsResolver.js +53 -53
  288. package/src/structures/ModalSubmitInteraction.js +119 -119
  289. package/src/structures/NewsChannel.js +32 -32
  290. package/src/structures/OAuth2Guild.js +28 -28
  291. package/src/structures/PermissionOverwrites.js +198 -196
  292. package/src/structures/Poll.js +108 -0
  293. package/src/structures/PollAnswer.js +88 -0
  294. package/src/structures/Presence.js +1105 -443
  295. package/src/structures/ReactionCollector.js +229 -229
  296. package/src/structures/ReactionEmoji.js +31 -31
  297. package/src/structures/Role.js +590 -531
  298. package/src/structures/SectionComponent.js +48 -0
  299. package/src/structures/SelectMenuInteraction.js +21 -21
  300. package/src/structures/SeparatorComponent.js +48 -0
  301. package/src/structures/Session.js +81 -0
  302. package/src/structures/StageChannel.js +104 -104
  303. package/src/structures/StageInstance.js +208 -208
  304. package/src/structures/Sticker.js +310 -310
  305. package/src/structures/StickerPack.js +95 -95
  306. package/src/structures/StoreChannel.js +56 -56
  307. package/src/structures/Team.js +118 -118
  308. package/src/structures/TeamMember.js +80 -71
  309. package/src/structures/TextChannel.js +33 -33
  310. package/src/structures/TextDisplayComponent.js +40 -0
  311. package/src/structures/TextInputComponent.js +132 -131
  312. package/src/structures/ThreadChannel.js +605 -607
  313. package/src/structures/ThreadMember.js +105 -105
  314. package/src/structures/ThreadOnlyChannel.js +249 -0
  315. package/src/structures/ThumbnailComponent.js +57 -0
  316. package/src/structures/Typing.js +74 -74
  317. package/src/structures/UnfurledMediaItem.js +29 -0
  318. package/src/structures/User.js +640 -509
  319. package/src/structures/UserContextMenuInteraction.js +29 -29
  320. package/src/structures/VoiceChannel.js +110 -110
  321. package/src/structures/VoiceChannelEffect.js +69 -0
  322. package/src/structures/VoiceRegion.js +53 -53
  323. package/src/structures/VoiceState.js +354 -341
  324. package/src/structures/WebEmbed.js +373 -373
  325. package/src/structures/Webhook.js +478 -467
  326. package/src/structures/WelcomeChannel.js +60 -60
  327. package/src/structures/WelcomeScreen.js +48 -48
  328. package/src/structures/Widget.js +87 -87
  329. package/src/structures/WidgetMember.js +99 -99
  330. package/src/structures/interfaces/Application.js +825 -313
  331. package/src/structures/interfaces/Collector.js +300 -300
  332. package/src/structures/interfaces/InteractionResponses.js +313 -313
  333. package/src/structures/interfaces/TextBasedChannel.js +759 -721
  334. package/src/util/APITypes.js +59 -0
  335. package/src/util/ActivityFlags.js +44 -44
  336. package/src/util/ApplicationFlags.js +76 -76
  337. package/src/util/AttachmentFlags.js +38 -38
  338. package/src/util/BitField.js +170 -170
  339. package/src/util/ChannelFlags.js +45 -45
  340. package/src/util/Constants.js +1914 -1760
  341. package/src/util/DataResolver.js +146 -145
  342. package/src/util/Formatters.js +228 -228
  343. package/src/util/GuildMemberFlags.js +43 -43
  344. package/src/util/Intents.js +74 -74
  345. package/src/util/InviteFlags.js +34 -29
  346. package/src/util/LimitedCollection.js +131 -131
  347. package/src/util/MessageFlags.js +63 -54
  348. package/src/util/Options.js +358 -342
  349. package/src/util/Permissions.js +202 -192
  350. package/src/util/PremiumUsageFlags.js +31 -31
  351. package/src/util/PurchasedFlags.js +33 -33
  352. package/src/util/RemoteAuth.js +382 -379
  353. package/src/util/RoleFlags.js +37 -37
  354. package/src/util/SnowflakeUtil.js +92 -92
  355. package/src/util/Speaking.js +33 -0
  356. package/src/util/Sweepers.js +466 -466
  357. package/src/util/SystemChannelFlags.js +55 -55
  358. package/src/util/ThreadMemberFlags.js +30 -30
  359. package/src/util/UserFlags.js +104 -104
  360. package/src/util/Util.js +1048 -803
  361. package/typings/enums.d.ts +439 -291
  362. package/typings/index.d.ts +8247 -7390
  363. package/typings/rawDataTypes.d.ts +403 -342
  364. package/src/structures/RichPresence.js +0 -702
package/src/util/Util.js CHANGED
@@ -1,803 +1,1048 @@
1
- 'use strict';
2
-
3
- const { parse } = require('node:path');
4
- const process = require('node:process');
5
- const { Collection } = require('@discordjs/collection');
6
- const fetch = require('node-fetch');
7
- const { Colors } = require('./Constants');
8
- const { Error: DiscordError, RangeError, TypeError } = require('../errors');
9
- const has = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
10
- const isObject = d => typeof d === 'object' && d !== null;
11
-
12
- let deprecationEmittedForSplitMessage = false;
13
- let deprecationEmittedForRemoveMentions = false;
14
- let deprecationEmittedForResolveAutoArchiveMaxLimit = false;
15
-
16
- const TextSortableGroupTypes = ['GUILD_TEXT', 'GUILD_ANNOUCMENT', 'GUILD_FORUM'];
17
- const VoiceSortableGroupTypes = ['GUILD_VOICE', 'GUILD_STAGE_VOICE'];
18
- const CategorySortableGroupTypes = ['GUILD_CATEGORY'];
19
-
20
- /**
21
- * Contains various general-purpose utility methods.
22
- */
23
- class Util extends null {
24
- /**
25
- * Flatten an object. Any properties that are collections will get converted to an array of keys.
26
- * @param {Object} obj The object to flatten.
27
- * @param {...Object<string, boolean|string>} [props] Specific properties to include/exclude.
28
- * @returns {Object}
29
- */
30
- static flatten(obj, ...props) {
31
- if (!isObject(obj)) return obj;
32
-
33
- const objProps = Object.keys(obj)
34
- .filter(k => !k.startsWith('_'))
35
- .map(k => ({ [k]: true }));
36
-
37
- props = objProps.length ? Object.assign(...objProps, ...props) : Object.assign({}, ...props);
38
-
39
- const out = {};
40
-
41
- for (let [prop, newProp] of Object.entries(props)) {
42
- if (!newProp) continue;
43
- newProp = newProp === true ? prop : newProp;
44
-
45
- const element = obj[prop];
46
- const elemIsObj = isObject(element);
47
- const valueOf = elemIsObj && typeof element.valueOf === 'function' ? element.valueOf() : null;
48
- const hasToJSON = elemIsObj && typeof element.toJSON === 'function';
49
-
50
- // If it's a Collection, make the array of keys
51
- if (element instanceof Collection) out[newProp] = Array.from(element.keys());
52
- // If the valueOf is a Collection, use its array of keys
53
- else if (valueOf instanceof Collection) out[newProp] = Array.from(valueOf.keys());
54
- // If it's an array, call toJSON function on each element if present, otherwise flatten each element
55
- else if (Array.isArray(element)) out[newProp] = element.map(e => e.toJSON?.() ?? Util.flatten(e));
56
- // If it's an object with a primitive `valueOf`, use that value
57
- else if (typeof valueOf !== 'object') out[newProp] = valueOf;
58
- // If it's an object with a toJSON function, use the return value of it
59
- else if (hasToJSON) out[newProp] = element.toJSON();
60
- // If element is an object, use the flattened version of it
61
- else if (typeof element === 'object') out[newProp] = Util.flatten(element);
62
- // If it's a primitive
63
- else if (!elemIsObj) out[newProp] = element;
64
- }
65
-
66
- return out;
67
- }
68
-
69
- /**
70
- * Options for splitting a message.
71
- * @typedef {Object} SplitOptions
72
- * @property {number} [maxLength=2000] Maximum character length per message piece
73
- * @property {string|string[]|RegExp|RegExp[]} [char='\n'] Character(s) or Regex(es) to split the message with,
74
- * an array can be used to split multiple times
75
- * @property {string} [prepend=''] Text to prepend to every piece except the first
76
- * @property {string} [append=''] Text to append to every piece except the last
77
- */
78
-
79
- /**
80
- * Splits a string into multiple chunks at a designated character that do not exceed a specific length.
81
- * @param {string} text Content to split
82
- * @param {SplitOptions} [options] Options controlling the behavior of the split
83
- * @deprecated This will be removed in the next major version.
84
- * @returns {string[]}
85
- */
86
- static splitMessage(text, { maxLength = 2_000, char = '\n', prepend = '', append = '' } = {}) {
87
- if (!deprecationEmittedForSplitMessage) {
88
- process.emitWarning(
89
- 'The Util.splitMessage method is deprecated and will be removed in the next major version.',
90
- 'DeprecationWarning',
91
- );
92
-
93
- deprecationEmittedForSplitMessage = true;
94
- }
95
-
96
- text = Util.verifyString(text);
97
- if (text.length <= maxLength) return [text];
98
- let splitText = [text];
99
- if (Array.isArray(char)) {
100
- while (char.length > 0 && splitText.some(elem => elem.length > maxLength)) {
101
- const currentChar = char.shift();
102
- if (currentChar instanceof RegExp) {
103
- splitText = splitText.flatMap(chunk => chunk.match(currentChar));
104
- } else {
105
- splitText = splitText.flatMap(chunk => chunk.split(currentChar));
106
- }
107
- }
108
- } else {
109
- splitText = text.split(char);
110
- }
111
- if (splitText.some(elem => elem.length > maxLength)) throw new RangeError('SPLIT_MAX_LEN');
112
- const messages = [];
113
- let msg = '';
114
- for (const chunk of splitText) {
115
- if (msg && (msg + char + chunk + append).length > maxLength) {
116
- messages.push(msg + append);
117
- msg = prepend;
118
- }
119
- msg += (msg && msg !== prepend ? char : '') + chunk;
120
- }
121
- return messages.concat(msg).filter(m => m);
122
- }
123
-
124
- /**
125
- * Options used to escape markdown.
126
- * @typedef {Object} EscapeMarkdownOptions
127
- * @property {boolean} [codeBlock=true] Whether to escape code blocks
128
- * @property {boolean} [inlineCode=true] Whether to escape inline code
129
- * @property {boolean} [bold=true] Whether to escape bolds
130
- * @property {boolean} [italic=true] Whether to escape italics
131
- * @property {boolean} [underline=true] Whether to escape underlines
132
- * @property {boolean} [strikethrough=true] Whether to escape strikethroughs
133
- * @property {boolean} [spoiler=true] Whether to escape spoilers
134
- * @property {boolean} [codeBlockContent=true] Whether to escape text inside code blocks
135
- * @property {boolean} [inlineCodeContent=true] Whether to escape text inside inline code
136
- * @property {boolean} [escape=true] Whether to escape escape characters
137
- * @property {boolean} [heading=false] Whether to escape headings
138
- * @property {boolean} [bulletedList=false] Whether to escape bulleted lists
139
- * @property {boolean} [numberedList=false] Whether to escape numbered lists
140
- * @property {boolean} [maskedLink=false] Whether to escape masked links
141
- */
142
-
143
- /**
144
- * Escapes any Discord-flavour markdown in a string.
145
- * @param {string} text Content to escape
146
- * @param {EscapeMarkdownOptions} [options={}] Options for escaping the markdown
147
- * @returns {string}
148
- */
149
- static escapeMarkdown(
150
- text,
151
- {
152
- codeBlock = true,
153
- inlineCode = true,
154
- bold = true,
155
- italic = true,
156
- underline = true,
157
- strikethrough = true,
158
- spoiler = true,
159
- codeBlockContent = true,
160
- inlineCodeContent = true,
161
- escape = true,
162
- heading = false,
163
- bulletedList = false,
164
- numberedList = false,
165
- maskedLink = false,
166
- } = {},
167
- ) {
168
- if (!codeBlockContent) {
169
- return text
170
- .split('```')
171
- .map((subString, index, array) => {
172
- if (index % 2 && index !== array.length - 1) return subString;
173
- return Util.escapeMarkdown(subString, {
174
- inlineCode,
175
- bold,
176
- italic,
177
- underline,
178
- strikethrough,
179
- spoiler,
180
- inlineCodeContent,
181
- escape,
182
- heading,
183
- bulletedList,
184
- numberedList,
185
- maskedLink,
186
- });
187
- })
188
- .join(codeBlock ? '\\`\\`\\`' : '```');
189
- }
190
- if (!inlineCodeContent) {
191
- return text
192
- .split(/(?<=^|[^`])`(?=[^`]|$)/g)
193
- .map((subString, index, array) => {
194
- if (index % 2 && index !== array.length - 1) return subString;
195
- return Util.escapeMarkdown(subString, {
196
- codeBlock,
197
- bold,
198
- italic,
199
- underline,
200
- strikethrough,
201
- spoiler,
202
- escape,
203
- heading,
204
- bulletedList,
205
- numberedList,
206
- maskedLink,
207
- });
208
- })
209
- .join(inlineCode ? '\\`' : '`');
210
- }
211
- if (escape) text = Util.escapeEscape(text);
212
- if (inlineCode) text = Util.escapeInlineCode(text);
213
- if (codeBlock) text = Util.escapeCodeBlock(text);
214
- if (italic) text = Util.escapeItalic(text);
215
- if (bold) text = Util.escapeBold(text);
216
- if (underline) text = Util.escapeUnderline(text);
217
- if (strikethrough) text = Util.escapeStrikethrough(text);
218
- if (spoiler) text = Util.escapeSpoiler(text);
219
- if (heading) text = Util.escapeHeading(text);
220
- if (bulletedList) text = Util.escapeBulletedList(text);
221
- if (numberedList) text = Util.escapeNumberedList(text);
222
- if (maskedLink) text = Util.escapeMaskedLink(text);
223
- return text;
224
- }
225
-
226
- /**
227
- * Escapes code block markdown in a string.
228
- * @param {string} text Content to escape
229
- * @returns {string}
230
- */
231
- static escapeCodeBlock(text) {
232
- return text.replaceAll('```', '\\`\\`\\`');
233
- }
234
-
235
- /**
236
- * Escapes inline code markdown in a string.
237
- * @param {string} text Content to escape
238
- * @returns {string}
239
- */
240
- static escapeInlineCode(text) {
241
- return text.replace(/(?<=^|[^`])``?(?=[^`]|$)/g, match => (match.length === 2 ? '\\`\\`' : '\\`'));
242
- }
243
-
244
- /**
245
- * Escapes italic markdown in a string.
246
- * @param {string} text Content to escape
247
- * @returns {string}
248
- */
249
- static escapeItalic(text) {
250
- let i = 0;
251
- text = text.replace(/(?<=^|[^*])\*([^*]|\*\*|$)/g, (_, match) => {
252
- if (match === '**') return ++i % 2 ? `\\*${match}` : `${match}\\*`;
253
- return `\\*${match}`;
254
- });
255
- i = 0;
256
- return text.replace(/(?<=^|[^_])_([^_]|__|$)/g, (_, match) => {
257
- if (match === '__') return ++i % 2 ? `\\_${match}` : `${match}\\_`;
258
- return `\\_${match}`;
259
- });
260
- }
261
-
262
- /**
263
- * Escapes bold markdown in a string.
264
- * @param {string} text Content to escape
265
- * @returns {string}
266
- */
267
- static escapeBold(text) {
268
- let i = 0;
269
- return text.replace(/\*\*(\*)?/g, (_, match) => {
270
- if (match) return ++i % 2 ? `${match}\\*\\*` : `\\*\\*${match}`;
271
- return '\\*\\*';
272
- });
273
- }
274
-
275
- /**
276
- * Escapes underline markdown in a string.
277
- * @param {string} text Content to escape
278
- * @returns {string}
279
- */
280
- static escapeUnderline(text) {
281
- let i = 0;
282
- return text.replace(/__(_)?/g, (_, match) => {
283
- if (match) return ++i % 2 ? `${match}\\_\\_` : `\\_\\_${match}`;
284
- return '\\_\\_';
285
- });
286
- }
287
-
288
- /**
289
- * Escapes strikethrough markdown in a string.
290
- * @param {string} text Content to escape
291
- * @returns {string}
292
- */
293
- static escapeStrikethrough(text) {
294
- return text.replaceAll('~~', '\\~\\~');
295
- }
296
-
297
- /**
298
- * Escapes spoiler markdown in a string.
299
- * @param {string} text Content to escape
300
- * @returns {string}
301
- */
302
- static escapeSpoiler(text) {
303
- return text.replaceAll('||', '\\|\\|');
304
- }
305
-
306
- /**
307
- * Escapes escape characters in a string.
308
- * @param {string} text Content to escape
309
- * @returns {string}
310
- */
311
- static escapeEscape(text) {
312
- return text.replaceAll('\\', '\\\\');
313
- }
314
-
315
- /**
316
- * Escapes heading characters in a string.
317
- * @param {string} text Content to escape
318
- * @returns {string}
319
- */
320
- static escapeHeading(text) {
321
- return text.replaceAll(/^( {0,2}[*-] +)?(#{1,3} )/gm, '$1\\$2');
322
- }
323
-
324
- /**
325
- * Escapes bulleted list characters in a string.
326
- * @param {string} text Content to escape
327
- * @returns {string}
328
- */
329
- static escapeBulletedList(text) {
330
- return text.replaceAll(/^( *)[*-]( +)/gm, '$1\\-$2');
331
- }
332
-
333
- /**
334
- * Escapes numbered list characters in a string.
335
- * @param {string} text Content to escape
336
- * @returns {string}
337
- */
338
- static escapeNumberedList(text) {
339
- return text.replaceAll(/^( *\d+)\./gm, '$1\\.');
340
- }
341
-
342
- /**
343
- * Escapes masked link characters in a string.
344
- * @param {string} text Content to escape
345
- * @returns {string}
346
- */
347
- static escapeMaskedLink(text) {
348
- return text.replaceAll(/\[.+\]\(.+\)/gm, '\\$&');
349
- }
350
-
351
- /**
352
- * @typedef {Object} FetchRecommendedShardsOptions
353
- * @property {number} [guildsPerShard=1000] Number of guilds assigned per shard
354
- * @property {number} [multipleOf=1] The multiple the shard count should round up to. (16 for large bot sharding)
355
- */
356
-
357
- static fetchRecommendedShards() {
358
- throw new DiscordError('INVALID_USER_API');
359
- }
360
-
361
- /**
362
- * Parses emoji info out of a string. The string must be one of:
363
- * * A UTF-8 emoji (no id)
364
- * * A URL-encoded UTF-8 emoji (no id)
365
- * * A Discord custom emoji (`<:name:id>` or `<a:name:id>`)
366
- * @param {string} text Emoji string to parse
367
- * @returns {APIEmoji} Object with `animated`, `name`, and `id` properties
368
- * @private
369
- */
370
- static parseEmoji(text) {
371
- if (text.includes('%')) text = decodeURIComponent(text);
372
- if (!text.includes(':')) return { animated: false, name: text, id: null };
373
- const match = text.match(/<?(?:(a):)?(\w{2,32}):(\d{17,19})?>?/);
374
- return match && { animated: Boolean(match[1]), name: match[2], id: match[3] ?? null };
375
- }
376
-
377
- /**
378
- * Resolves a partial emoji object from an {@link EmojiIdentifierResolvable}, without checking a Client.
379
- * @param {EmojiIdentifierResolvable} emoji Emoji identifier to resolve
380
- * @returns {?RawEmoji}
381
- * @private
382
- */
383
- static resolvePartialEmoji(emoji) {
384
- if (!emoji) return null;
385
- if (typeof emoji === 'string') return /^\d{17,19}$/.test(emoji) ? { id: emoji } : Util.parseEmoji(emoji);
386
- const { id, name, animated } = emoji;
387
- if (!id && !name) return null;
388
- return { id, name, animated: Boolean(animated) };
389
- }
390
-
391
- /**
392
- * Shallow-copies an object with its class/prototype intact.
393
- * @param {Object} obj Object to clone
394
- * @returns {Object}
395
- * @private
396
- */
397
- static cloneObject(obj) {
398
- return Object.assign(Object.create(obj), obj);
399
- }
400
-
401
- /**
402
- * Sets default properties on an object that aren't already specified.
403
- * @param {Object} def Default properties
404
- * @param {Object} given Object to assign defaults to
405
- * @returns {Object}
406
- * @private
407
- */
408
- static mergeDefault(def, given) {
409
- if (!given) return def;
410
- for (const key in def) {
411
- if (!has(given, key) || given[key] === undefined) {
412
- given[key] = def[key];
413
- } else if (given[key] === Object(given[key])) {
414
- given[key] = Util.mergeDefault(def[key], given[key]);
415
- }
416
- }
417
-
418
- return given;
419
- }
420
-
421
- /**
422
- * Options used to make an error object.
423
- * @typedef {Object} MakeErrorOptions
424
- * @property {string} name Error type
425
- * @property {string} message Message for the error
426
- * @property {string} stack Stack for the error
427
- */
428
-
429
- /**
430
- * Makes an Error from a plain info object.
431
- * @param {MakeErrorOptions} obj Error info
432
- * @returns {Error}
433
- * @private
434
- */
435
- static makeError(obj) {
436
- const err = new Error(obj.message);
437
- err.name = obj.name;
438
- err.stack = obj.stack;
439
- return err;
440
- }
441
-
442
- /**
443
- * Makes a plain error info object from an Error.
444
- * @param {Error} err Error to get info from
445
- * @returns {MakeErrorOptions}
446
- * @private
447
- */
448
- static makePlainError(err) {
449
- return {
450
- name: err.name,
451
- message: err.message,
452
- stack: err.stack,
453
- };
454
- }
455
-
456
- /**
457
- * Moves an element in an array *in place*.
458
- * @param {Array<*>} array Array to modify
459
- * @param {*} element Element to move
460
- * @param {number} newIndex Index or offset to move the element to
461
- * @param {boolean} [offset=false] Move the element by an offset amount rather than to a set index
462
- * @returns {number}
463
- * @private
464
- */
465
- static moveElementInArray(array, element, newIndex, offset = false) {
466
- const index = array.indexOf(element);
467
- newIndex = (offset ? index : 0) + newIndex;
468
- if (newIndex > -1 && newIndex < array.length) {
469
- const removedElement = array.splice(index, 1)[0];
470
- array.splice(newIndex, 0, removedElement);
471
- }
472
- return array.indexOf(element);
473
- }
474
-
475
- /**
476
- * Verifies the provided data is a string, otherwise throws provided error.
477
- * @param {string} data The string resolvable to resolve
478
- * @param {Function} [error] The Error constructor to instantiate. Defaults to Error
479
- * @param {string} [errorMessage] The error message to throw with. Defaults to "Expected string, got <data> instead."
480
- * @param {boolean} [allowEmpty=true] Whether an empty string should be allowed
481
- * @returns {string}
482
- */
483
- static verifyString(
484
- data,
485
- error = Error,
486
- errorMessage = `Expected a string, got ${data} instead.`,
487
- allowEmpty = true,
488
- ) {
489
- if (typeof data !== 'string') throw new error(errorMessage);
490
- if (!allowEmpty && data.length === 0) throw new error(errorMessage);
491
- return data;
492
- }
493
-
494
- /**
495
- * Can be a number, hex string, a {@link Color}, or an RGB array like:
496
- * ```js
497
- * [255, 0, 255] // purple
498
- * ```
499
- * @typedef {string|Color|number|number[]} ColorResolvable
500
- */
501
-
502
- /**
503
- * Resolves a ColorResolvable into a color number.
504
- * @param {ColorResolvable} color Color to resolve
505
- * @returns {number} A color
506
- */
507
- static resolveColor(color) {
508
- if (typeof color === 'string') {
509
- if (color === 'RANDOM') return Math.floor(Math.random() * (0xffffff + 1));
510
- if (color === 'DEFAULT') return 0;
511
- color = Colors[color] ?? parseInt(color.replace('#', ''), 16);
512
- } else if (Array.isArray(color)) {
513
- color = (color[0] << 16) + (color[1] << 8) + color[2];
514
- }
515
-
516
- if (color < 0 || color > 0xffffff) throw new RangeError('COLOR_RANGE');
517
- else if (Number.isNaN(color)) throw new TypeError('COLOR_CONVERT');
518
-
519
- return color;
520
- }
521
-
522
- /**
523
- * Sorts by Discord's position and id.
524
- * @param {Collection} collection Collection of objects to sort
525
- * @returns {Collection}
526
- */
527
- static discordSort(collection) {
528
- const isGuildChannel = collection.first() instanceof GuildChannel;
529
- return collection.sorted(
530
- isGuildChannel
531
- ? (a, b) => a.rawPosition - b.rawPosition || Number(BigInt(a.id) - BigInt(b.id))
532
- : (a, b) => a.rawPosition - b.rawPosition || Number(BigInt(b.id) - BigInt(a.id)),
533
- );
534
- }
535
-
536
- /**
537
- * Sets the position of a Channel or Role.
538
- * @param {Channel|Role} item Object to set the position of
539
- * @param {number} position New position for the object
540
- * @param {boolean} relative Whether `position` is relative to its current position
541
- * @param {Collection<string, Channel|Role>} sorted A collection of the objects sorted properly
542
- * @param {APIRouter} route Route to call PATCH on
543
- * @param {string} [reason] Reason for the change
544
- * @returns {Promise<Channel[]|Role[]>} Updated item list, with `id` and `position` properties
545
- * @private
546
- */
547
- static async setPosition(item, position, relative, sorted, route, reason) {
548
- let updatedItems = [...sorted.values()];
549
- Util.moveElementInArray(updatedItems, item, position, relative);
550
- updatedItems = updatedItems.map((r, i) => ({ id: r.id, position: i }));
551
- await route.patch({ data: updatedItems, reason });
552
- return updatedItems;
553
- }
554
-
555
- /**
556
- * Alternative to Node's `path.basename`, removing query string after the extension if it exists.
557
- * @param {string} path Path to get the basename of
558
- * @param {string} [ext] File extension to remove
559
- * @returns {string} Basename of the path
560
- * @private
561
- */
562
- static basename(path, ext) {
563
- const res = parse(path);
564
- return ext && res.ext.startsWith(ext) ? res.name : res.base.split('?')[0];
565
- }
566
-
567
- /**
568
- * Breaks user, role and everyone/here mentions by adding a zero width space after every @ character
569
- * @param {string} str The string to sanitize
570
- * @returns {string}
571
- * @deprecated Use {@link BaseMessageOptions#allowedMentions} instead.
572
- */
573
- static removeMentions(str) {
574
- if (!deprecationEmittedForRemoveMentions) {
575
- process.emitWarning(
576
- 'The Util.removeMentions method is deprecated. Use MessageOptions#allowedMentions instead.',
577
- 'DeprecationWarning',
578
- );
579
-
580
- deprecationEmittedForRemoveMentions = true;
581
- }
582
-
583
- return Util._removeMentions(str);
584
- }
585
-
586
- static _removeMentions(str) {
587
- return str.replaceAll('@', '@\u200b');
588
- }
589
-
590
- /**
591
- * The content to have all mentions replaced by the equivalent text.
592
- * <warn>When {@link Util.removeMentions} is removed, this method will no longer sanitize mentions.
593
- * Use {@link BaseMessageOptions#allowedMentions} instead to prevent mentions when sending a message.</warn>
594
- * @param {string} str The string to be converted
595
- * @param {TextBasedChannels} channel The channel the string was sent in
596
- * @returns {string}
597
- */
598
- static cleanContent(str, channel) {
599
- str = str
600
- .replace(/<@!?[0-9]+>/g, input => {
601
- const id = input.replace(/<|!|>|@/g, '');
602
- if (channel.type === 'DM') {
603
- const user = channel.client.users.cache.get(id);
604
- return user ? Util._removeMentions(`@${user.username}`) : input;
605
- }
606
-
607
- const member = channel.guild.members.cache.get(id);
608
- if (member) {
609
- return Util._removeMentions(`@${member.displayName}`);
610
- } else {
611
- const user = channel.client.users.cache.get(id);
612
- return user ? Util._removeMentions(`@${user.username}`) : input;
613
- }
614
- })
615
- .replace(/<#[0-9]+>/g, input => {
616
- const mentionedChannel = channel.client.channels.cache.get(input.replace(/<|#|>/g, ''));
617
- return mentionedChannel ? `#${mentionedChannel.name}` : input;
618
- })
619
- .replace(/<@&[0-9]+>/g, input => {
620
- if (channel.type === 'DM') return input;
621
- const role = channel.guild.roles.cache.get(input.replace(/<|@|>|&/g, ''));
622
- return role ? `@${role.name}` : input;
623
- });
624
- return str;
625
- }
626
-
627
- /**
628
- * The content to put in a code block with all code block fences replaced by the equivalent backticks.
629
- * @param {string} text The string to be converted
630
- * @returns {string}
631
- */
632
- static cleanCodeBlockContent(text) {
633
- return text.replaceAll('```', '`\u200b``');
634
- }
635
-
636
- /**
637
- * Creates a sweep filter that sweeps archived threads
638
- * @param {number} [lifetime=14400] How long a thread has to be archived to be valid for sweeping
639
- * @deprecated When not using with `makeCache` use `Sweepers.archivedThreadSweepFilter` instead
640
- * @returns {SweepFilter}
641
- */
642
- static archivedThreadSweepFilter(lifetime = 14400) {
643
- const filter = require('./Sweepers').archivedThreadSweepFilter(lifetime);
644
- filter.isDefault = true;
645
- return filter;
646
- }
647
-
648
- /**
649
- * Resolves the maximum time a guild's thread channels should automatically archive in case of no recent activity.
650
- * @param {Guild} guild The guild to resolve this limit from.
651
- * @deprecated This will be removed in the next major version.
652
- * @returns {number}
653
- */
654
- static resolveAutoArchiveMaxLimit() {
655
- if (!deprecationEmittedForResolveAutoArchiveMaxLimit) {
656
- process.emitWarning(
657
- // eslint-disable-next-line max-len
658
- "The Util.resolveAutoArchiveMaxLimit method and the 'MAX' option are deprecated and will be removed in the next major version.",
659
- 'DeprecationWarning',
660
- );
661
- deprecationEmittedForResolveAutoArchiveMaxLimit = true;
662
- }
663
- return 10080;
664
- }
665
-
666
- /**
667
- * Transforms an API guild forum tag to camel-cased guild forum tag.
668
- * @param {APIGuildForumTag} tag The tag to transform
669
- * @returns {GuildForumTag}
670
- * @ignore
671
- */
672
- static transformAPIGuildForumTag(tag) {
673
- return {
674
- id: tag.id,
675
- name: tag.name,
676
- moderated: tag.moderated,
677
- emoji:
678
- tag.emoji_id ?? tag.emoji_name
679
- ? {
680
- id: tag.emoji_id,
681
- name: tag.emoji_name,
682
- }
683
- : null,
684
- };
685
- }
686
-
687
- /**
688
- * Transforms a camel-cased guild forum tag to an API guild forum tag.
689
- * @param {GuildForumTag} tag The tag to transform
690
- * @returns {APIGuildForumTag}
691
- * @ignore
692
- */
693
- static transformGuildForumTag(tag) {
694
- return {
695
- id: tag.id,
696
- name: tag.name,
697
- moderated: tag.moderated,
698
- emoji_id: tag.emoji?.id ?? null,
699
- emoji_name: tag.emoji?.name ?? null,
700
- };
701
- }
702
-
703
- /**
704
- * Transforms an API guild forum default reaction object to a
705
- * camel-cased guild forum default reaction object.
706
- * @param {APIGuildForumDefaultReactionEmoji} defaultReaction The default reaction to transform
707
- * @returns {DefaultReactionEmoji}
708
- * @ignore
709
- */
710
- static transformAPIGuildDefaultReaction(defaultReaction) {
711
- return {
712
- id: defaultReaction.emoji_id,
713
- name: defaultReaction.emoji_name,
714
- };
715
- }
716
-
717
- /**
718
- * Transforms a camel-cased guild forum default reaction object to an
719
- * API guild forum default reaction object.
720
- * @param {DefaultReactionEmoji} defaultReaction The default reaction to transform
721
- * @returns {APIGuildForumDefaultReactionEmoji}
722
- * @ignore
723
- */
724
- static transformGuildDefaultReaction(defaultReaction) {
725
- return {
726
- emoji_id: defaultReaction.id,
727
- emoji_name: defaultReaction.name,
728
- };
729
- }
730
-
731
- /**
732
- * Gets an array of the channel types that can be moved in the channel group. For example, a GuildText channel would
733
- * return an array containing the types that can be ordered within the text channels (always at the top), and a voice
734
- * channel would return an array containing the types that can be ordered within the voice channels (always at the
735
- * bottom).
736
- * @param {ChannelType} type The type of the channel
737
- * @returns {ChannelType[]}
738
- * @ignore
739
- */
740
- static getSortableGroupTypes(type) {
741
- switch (type) {
742
- case 'GUILD_TEXT':
743
- case 'GUILD_ANNOUNCEMENT':
744
- case 'GUILD_FORUM':
745
- return TextSortableGroupTypes;
746
- case 'GUILD_VOICE':
747
- case 'GUILD_STAGE_VOICE':
748
- return VoiceSortableGroupTypes;
749
- case 'GUILD_CATEGORY':
750
- return CategorySortableGroupTypes;
751
- default:
752
- return [type];
753
- }
754
- }
755
-
756
- /**
757
- * Calculates the default avatar index for a given user id.
758
- * @param {Snowflake} userId - The user id to calculate the default avatar index for
759
- * @returns {number}
760
- */
761
- static calculateUserDefaultAvatarIndex(userId) {
762
- return Number(BigInt(userId) >> 22n) % 6;
763
- }
764
-
765
- static async getUploadURL(client, channelId, files) {
766
- if (!files.length) return [];
767
- files = files.map((file, i) => ({
768
- filename: file.name,
769
- // 25MB = 26_214_400bytes
770
- file_size: Math.floor((26_214_400 / 10) * Math.random()),
771
- id: `${i}`,
772
- }));
773
- const { attachments } = await client.api.channels[channelId].attachments.post({
774
- data: {
775
- files,
776
- },
777
- });
778
- return attachments;
779
- }
780
-
781
- static uploadFile(data, url) {
782
- return new Promise((resolve, reject) => {
783
- fetch(url, {
784
- method: 'PUT',
785
- body: data,
786
- duplex: 'half', // Node.js v20
787
- })
788
- .then(res => {
789
- if (res.ok) {
790
- resolve(res);
791
- } else {
792
- reject(res);
793
- }
794
- })
795
- .catch(reject);
796
- });
797
- }
798
- }
799
-
800
- module.exports = Util;
801
-
802
- // Fixes Circular
803
- const GuildChannel = require('../structures/GuildChannel');
1
+ 'use strict';
2
+
3
+ const { Agent } = require('node:http');
4
+ const { parse } = require('node:path');
5
+ const process = require('node:process');
6
+ const { setTimeout } = require('node:timers');
7
+ const { Collection } = require('@discordjs/collection');
8
+ const { fetch } = require('undici');
9
+ const { Colors, Events } = require('./Constants');
10
+ const { Error: DiscordError, RangeError, TypeError } = require('../errors');
11
+ const has = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
12
+ const isObject = d => typeof d === 'object' && d !== null;
13
+
14
+ let deprecationEmittedForSplitMessage = false;
15
+ let deprecationEmittedForRemoveMentions = false;
16
+ let deprecationEmittedForResolveAutoArchiveMaxLimit = false;
17
+
18
+ const TextSortableGroupTypes = ['GUILD_TEXT', 'GUILD_ANNOUCMENT', 'GUILD_FORUM'];
19
+ const VoiceSortableGroupTypes = ['GUILD_VOICE', 'GUILD_STAGE_VOICE'];
20
+ const CategorySortableGroupTypes = ['GUILD_CATEGORY'];
21
+
22
+ const payloadTypes = [
23
+ {
24
+ name: 'opus',
25
+ type: 'audio',
26
+ priority: 1000,
27
+ payload_type: 120,
28
+ },
29
+ {
30
+ name: 'AV1',
31
+ type: 'video',
32
+ priority: 1000,
33
+ payload_type: 101,
34
+ rtx_payload_type: 102,
35
+ encode: false,
36
+ decode: false,
37
+ },
38
+ {
39
+ name: 'H265',
40
+ type: 'video',
41
+ priority: 2000,
42
+ payload_type: 103,
43
+ rtx_payload_type: 104,
44
+ encode: false,
45
+ decode: false,
46
+ },
47
+ {
48
+ name: 'H264',
49
+ type: 'video',
50
+ priority: 3000,
51
+ payload_type: 105,
52
+ rtx_payload_type: 106,
53
+ encode: true,
54
+ decode: true,
55
+ },
56
+ {
57
+ name: 'VP8',
58
+ type: 'video',
59
+ priority: 4000,
60
+ payload_type: 107,
61
+ rtx_payload_type: 108,
62
+ encode: true,
63
+ decode: false,
64
+ },
65
+ {
66
+ name: 'VP9',
67
+ type: 'video',
68
+ priority: 5000,
69
+ payload_type: 109,
70
+ rtx_payload_type: 110,
71
+ encode: false,
72
+ decode: false,
73
+ },
74
+ ];
75
+
76
+ /**
77
+ * Contains various general-purpose utility methods.
78
+ */
79
+ class Util extends null {
80
+ /**
81
+ * Flatten an object. Any properties that are collections will get converted to an array of keys.
82
+ * @param {Object} obj The object to flatten.
83
+ * @param {...Object<string, boolean|string>} [props] Specific properties to include/exclude.
84
+ * @returns {Object}
85
+ */
86
+ static flatten(obj, ...props) {
87
+ if (!isObject(obj)) return obj;
88
+
89
+ const objProps = Object.keys(obj)
90
+ .filter(k => !k.startsWith('_'))
91
+ .map(k => ({ [k]: true }));
92
+
93
+ props = objProps.length ? Object.assign(...objProps, ...props) : Object.assign({}, ...props);
94
+
95
+ const out = {};
96
+
97
+ for (let [prop, newProp] of Object.entries(props)) {
98
+ if (!newProp) continue;
99
+ newProp = newProp === true ? prop : newProp;
100
+
101
+ const element = obj[prop];
102
+ const elemIsObj = isObject(element);
103
+ const valueOf = elemIsObj && typeof element.valueOf === 'function' ? element.valueOf() : null;
104
+ const hasToJSON = elemIsObj && typeof element.toJSON === 'function';
105
+
106
+ // If it's a Collection, make the array of keys
107
+ if (element instanceof Collection) out[newProp] = Array.from(element.keys());
108
+ // If the valueOf is a Collection, use its array of keys
109
+ else if (valueOf instanceof Collection) out[newProp] = Array.from(valueOf.keys());
110
+ // If it's an array, call toJSON function on each element if present, otherwise flatten each element
111
+ else if (Array.isArray(element)) out[newProp] = element.map(e => e.toJSON?.() ?? Util.flatten(e));
112
+ // If it's an object with a primitive `valueOf`, use that value
113
+ else if (typeof valueOf !== 'object') out[newProp] = valueOf;
114
+ // If it's an object with a toJSON function, use the return value of it
115
+ else if (hasToJSON) out[newProp] = element.toJSON();
116
+ // If element is an object, use the flattened version of it
117
+ else if (typeof element === 'object') out[newProp] = Util.flatten(element);
118
+ // If it's a primitive
119
+ else if (!elemIsObj) out[newProp] = element;
120
+ }
121
+
122
+ return out;
123
+ }
124
+
125
+ /**
126
+ * Options for splitting a message.
127
+ * @typedef {Object} SplitOptions
128
+ * @property {number} [maxLength=2000] Maximum character length per message piece
129
+ * @property {string|string[]|RegExp|RegExp[]} [char='\n'] Character(s) or Regex(es) to split the message with,
130
+ * an array can be used to split multiple times
131
+ * @property {string} [prepend=''] Text to prepend to every piece except the first
132
+ * @property {string} [append=''] Text to append to every piece except the last
133
+ */
134
+
135
+ /**
136
+ * Splits a string into multiple chunks at a designated character that do not exceed a specific length.
137
+ * @param {string} text Content to split
138
+ * @param {SplitOptions} [options] Options controlling the behavior of the split
139
+ * @deprecated This will be removed in the next major version.
140
+ * @returns {string[]}
141
+ */
142
+ static splitMessage(text, { maxLength = 2_000, char = '\n', prepend = '', append = '' } = {}) {
143
+ if (!deprecationEmittedForSplitMessage) {
144
+ process.emitWarning(
145
+ 'The Util.splitMessage method is deprecated and will be removed in the next major version.',
146
+ 'DeprecationWarning',
147
+ );
148
+
149
+ deprecationEmittedForSplitMessage = true;
150
+ }
151
+
152
+ text = Util.verifyString(text);
153
+ if (text.length <= maxLength) return [text];
154
+ let splitText = [text];
155
+ if (Array.isArray(char)) {
156
+ while (char.length > 0 && splitText.some(elem => elem.length > maxLength)) {
157
+ const currentChar = char.shift();
158
+ if (currentChar instanceof RegExp) {
159
+ splitText = splitText.flatMap(chunk => chunk.match(currentChar));
160
+ } else {
161
+ splitText = splitText.flatMap(chunk => chunk.split(currentChar));
162
+ }
163
+ }
164
+ } else {
165
+ splitText = text.split(char);
166
+ }
167
+ if (splitText.some(elem => elem.length > maxLength)) throw new RangeError('SPLIT_MAX_LEN');
168
+ const messages = [];
169
+ let msg = '';
170
+ for (const chunk of splitText) {
171
+ if (msg && (msg + char + chunk + append).length > maxLength) {
172
+ messages.push(msg + append);
173
+ msg = prepend;
174
+ }
175
+ msg += (msg && msg !== prepend ? char : '') + chunk;
176
+ }
177
+ return messages.concat(msg).filter(m => m);
178
+ }
179
+
180
+ /**
181
+ * Options used to escape markdown.
182
+ * @typedef {Object} EscapeMarkdownOptions
183
+ * @property {boolean} [codeBlock=true] Whether to escape code blocks
184
+ * @property {boolean} [inlineCode=true] Whether to escape inline code
185
+ * @property {boolean} [bold=true] Whether to escape bolds
186
+ * @property {boolean} [italic=true] Whether to escape italics
187
+ * @property {boolean} [underline=true] Whether to escape underlines
188
+ * @property {boolean} [strikethrough=true] Whether to escape strikethroughs
189
+ * @property {boolean} [spoiler=true] Whether to escape spoilers
190
+ * @property {boolean} [codeBlockContent=true] Whether to escape text inside code blocks
191
+ * @property {boolean} [inlineCodeContent=true] Whether to escape text inside inline code
192
+ * @property {boolean} [escape=true] Whether to escape escape characters
193
+ * @property {boolean} [heading=false] Whether to escape headings
194
+ * @property {boolean} [bulletedList=false] Whether to escape bulleted lists
195
+ * @property {boolean} [numberedList=false] Whether to escape numbered lists
196
+ * @property {boolean} [maskedLink=false] Whether to escape masked links
197
+ */
198
+
199
+ /**
200
+ * Escapes any Discord-flavour markdown in a string.
201
+ * @param {string} text Content to escape
202
+ * @param {EscapeMarkdownOptions} [options={}] Options for escaping the markdown
203
+ * @returns {string}
204
+ */
205
+ static escapeMarkdown(
206
+ text,
207
+ {
208
+ codeBlock = true,
209
+ inlineCode = true,
210
+ bold = true,
211
+ italic = true,
212
+ underline = true,
213
+ strikethrough = true,
214
+ spoiler = true,
215
+ codeBlockContent = true,
216
+ inlineCodeContent = true,
217
+ escape = true,
218
+ heading = false,
219
+ bulletedList = false,
220
+ numberedList = false,
221
+ maskedLink = false,
222
+ } = {},
223
+ ) {
224
+ if (!codeBlockContent) {
225
+ return text
226
+ .split('```')
227
+ .map((subString, index, array) => {
228
+ if (index % 2 && index !== array.length - 1) return subString;
229
+ return Util.escapeMarkdown(subString, {
230
+ inlineCode,
231
+ bold,
232
+ italic,
233
+ underline,
234
+ strikethrough,
235
+ spoiler,
236
+ inlineCodeContent,
237
+ escape,
238
+ heading,
239
+ bulletedList,
240
+ numberedList,
241
+ maskedLink,
242
+ });
243
+ })
244
+ .join(codeBlock ? '\\`\\`\\`' : '```');
245
+ }
246
+ if (!inlineCodeContent) {
247
+ return text
248
+ .split(/(?<=^|[^`])`(?=[^`]|$)/g)
249
+ .map((subString, index, array) => {
250
+ if (index % 2 && index !== array.length - 1) return subString;
251
+ return Util.escapeMarkdown(subString, {
252
+ codeBlock,
253
+ bold,
254
+ italic,
255
+ underline,
256
+ strikethrough,
257
+ spoiler,
258
+ escape,
259
+ heading,
260
+ bulletedList,
261
+ numberedList,
262
+ maskedLink,
263
+ });
264
+ })
265
+ .join(inlineCode ? '\\`' : '`');
266
+ }
267
+ if (escape) text = Util.escapeEscape(text);
268
+ if (inlineCode) text = Util.escapeInlineCode(text);
269
+ if (codeBlock) text = Util.escapeCodeBlock(text);
270
+ if (italic) text = Util.escapeItalic(text);
271
+ if (bold) text = Util.escapeBold(text);
272
+ if (underline) text = Util.escapeUnderline(text);
273
+ if (strikethrough) text = Util.escapeStrikethrough(text);
274
+ if (spoiler) text = Util.escapeSpoiler(text);
275
+ if (heading) text = Util.escapeHeading(text);
276
+ if (bulletedList) text = Util.escapeBulletedList(text);
277
+ if (numberedList) text = Util.escapeNumberedList(text);
278
+ if (maskedLink) text = Util.escapeMaskedLink(text);
279
+ return text;
280
+ }
281
+
282
+ /**
283
+ * Escapes code block markdown in a string.
284
+ * @param {string} text Content to escape
285
+ * @returns {string}
286
+ */
287
+ static escapeCodeBlock(text) {
288
+ return text.replaceAll('```', '\\`\\`\\`');
289
+ }
290
+
291
+ /**
292
+ * Escapes inline code markdown in a string.
293
+ * @param {string} text Content to escape
294
+ * @returns {string}
295
+ */
296
+ static escapeInlineCode(text) {
297
+ return text.replace(/(?<=^|[^`])``?(?=[^`]|$)/g, match => (match.length === 2 ? '\\`\\`' : '\\`'));
298
+ }
299
+
300
+ /**
301
+ * Escapes italic markdown in a string.
302
+ * @param {string} text Content to escape
303
+ * @returns {string}
304
+ */
305
+ static escapeItalic(text) {
306
+ let i = 0;
307
+ text = text.replace(/(?<=^|[^*])\*([^*]|\*\*|$)/g, (_, match) => {
308
+ if (match === '**') return ++i % 2 ? `\\*${match}` : `${match}\\*`;
309
+ return `\\*${match}`;
310
+ });
311
+ i = 0;
312
+ return text.replace(/(?<=^|[^_])_([^_]|__|$)/g, (_, match) => {
313
+ if (match === '__') return ++i % 2 ? `\\_${match}` : `${match}\\_`;
314
+ return `\\_${match}`;
315
+ });
316
+ }
317
+
318
+ /**
319
+ * Escapes bold markdown in a string.
320
+ * @param {string} text Content to escape
321
+ * @returns {string}
322
+ */
323
+ static escapeBold(text) {
324
+ let i = 0;
325
+ return text.replace(/\*\*(\*)?/g, (_, match) => {
326
+ if (match) return ++i % 2 ? `${match}\\*\\*` : `\\*\\*${match}`;
327
+ return '\\*\\*';
328
+ });
329
+ }
330
+
331
+ /**
332
+ * Escapes underline markdown in a string.
333
+ * @param {string} text Content to escape
334
+ * @returns {string}
335
+ */
336
+ static escapeUnderline(text) {
337
+ let i = 0;
338
+ return text.replace(/__(_)?/g, (_, match) => {
339
+ if (match) return ++i % 2 ? `${match}\\_\\_` : `\\_\\_${match}`;
340
+ return '\\_\\_';
341
+ });
342
+ }
343
+
344
+ /**
345
+ * Escapes strikethrough markdown in a string.
346
+ * @param {string} text Content to escape
347
+ * @returns {string}
348
+ */
349
+ static escapeStrikethrough(text) {
350
+ return text.replaceAll('~~', '\\~\\~');
351
+ }
352
+
353
+ /**
354
+ * Escapes spoiler markdown in a string.
355
+ * @param {string} text Content to escape
356
+ * @returns {string}
357
+ */
358
+ static escapeSpoiler(text) {
359
+ return text.replaceAll('||', '\\|\\|');
360
+ }
361
+
362
+ /**
363
+ * Escapes escape characters in a string.
364
+ * @param {string} text Content to escape
365
+ * @returns {string}
366
+ */
367
+ static escapeEscape(text) {
368
+ return text.replaceAll('\\', '\\\\');
369
+ }
370
+
371
+ /**
372
+ * Escapes heading characters in a string.
373
+ * @param {string} text Content to escape
374
+ * @returns {string}
375
+ */
376
+ static escapeHeading(text) {
377
+ return text.replaceAll(/^( {0,2}[*-] +)?(#{1,3} )/gm, '$1\\$2');
378
+ }
379
+
380
+ /**
381
+ * Escapes bulleted list characters in a string.
382
+ * @param {string} text Content to escape
383
+ * @returns {string}
384
+ */
385
+ static escapeBulletedList(text) {
386
+ return text.replaceAll(/^( *)[*-]( +)/gm, '$1\\-$2');
387
+ }
388
+
389
+ /**
390
+ * Escapes numbered list characters in a string.
391
+ * @param {string} text Content to escape
392
+ * @returns {string}
393
+ */
394
+ static escapeNumberedList(text) {
395
+ return text.replaceAll(/^( *\d+)\./gm, '$1\\.');
396
+ }
397
+
398
+ /**
399
+ * Escapes masked link characters in a string.
400
+ * @param {string} text Content to escape
401
+ * @returns {string}
402
+ */
403
+ static escapeMaskedLink(text) {
404
+ return text.replaceAll(/\[.+\]\(.+\)/gm, '\\$&');
405
+ }
406
+
407
+ /**
408
+ * @typedef {Object} FetchRecommendedShardsOptions
409
+ * @property {number} [guildsPerShard=1000] Number of guilds assigned per shard
410
+ * @property {number} [multipleOf=1] The multiple the shard count should round up to. (16 for large bot sharding)
411
+ */
412
+
413
+ static fetchRecommendedShards() {
414
+ throw new DiscordError('INVALID_USER_API');
415
+ }
416
+
417
+ /**
418
+ * Parses emoji info out of a string. The string must be one of:
419
+ * * A UTF-8 emoji (no id)
420
+ * * A URL-encoded UTF-8 emoji (no id)
421
+ * * A Discord custom emoji (`<:name:id>` or `<a:name:id>`)
422
+ * @param {string} text Emoji string to parse
423
+ * @returns {APIEmoji} Object with `animated`, `name`, and `id` properties
424
+ * @private
425
+ */
426
+ static parseEmoji(text) {
427
+ if (text.includes('%')) text = decodeURIComponent(text);
428
+ if (!text.includes(':')) return { animated: false, name: text, id: null };
429
+ const match = text.match(/<?(?:(a):)?(\w{2,32}):(\d{17,19})?>?/);
430
+ return match && { animated: Boolean(match[1]), name: match[2], id: match[3] ?? null };
431
+ }
432
+
433
+ /**
434
+ * Resolves a partial emoji object from an {@link EmojiIdentifierResolvable}, without checking a Client.
435
+ * @param {EmojiIdentifierResolvable} emoji Emoji identifier to resolve
436
+ * @returns {?RawEmoji}
437
+ * @private
438
+ */
439
+ static resolvePartialEmoji(emoji) {
440
+ if (!emoji) return null;
441
+ if (typeof emoji === 'string') return /^\d{17,19}$/.test(emoji) ? { id: emoji } : Util.parseEmoji(emoji);
442
+ const { id, name, animated } = emoji;
443
+ if (!id && !name) return null;
444
+ return { id, name, animated: Boolean(animated) };
445
+ }
446
+
447
+ /**
448
+ * Shallow-copies an object with its class/prototype intact.
449
+ * @param {Object} obj Object to clone
450
+ * @returns {Object}
451
+ * @private
452
+ */
453
+ static cloneObject(obj) {
454
+ return Object.assign(Object.create(obj), obj);
455
+ }
456
+
457
+ /**
458
+ * Sets default properties on an object that aren't already specified.
459
+ * @param {Object} def Default properties
460
+ * @param {Object} given Object to assign defaults to
461
+ * @returns {Object}
462
+ * @private
463
+ */
464
+ static mergeDefault(def, given) {
465
+ if (!given) return def;
466
+ for (const key in def) {
467
+ if (!has(given, key) || given[key] === undefined) {
468
+ given[key] = def[key];
469
+ } else if (given[key] === Object(given[key])) {
470
+ given[key] = Util.mergeDefault(def[key], given[key]);
471
+ }
472
+ }
473
+
474
+ return given;
475
+ }
476
+
477
+ /**
478
+ * Options used to make an error object.
479
+ * @typedef {Object} MakeErrorOptions
480
+ * @property {string} name Error type
481
+ * @property {string} message Message for the error
482
+ * @property {string} stack Stack for the error
483
+ */
484
+
485
+ /**
486
+ * Makes an Error from a plain info object.
487
+ * @param {MakeErrorOptions} obj Error info
488
+ * @returns {Error}
489
+ * @private
490
+ */
491
+ static makeError(obj) {
492
+ const err = new Error(obj.message);
493
+ err.name = obj.name;
494
+ err.stack = obj.stack;
495
+ return err;
496
+ }
497
+
498
+ /**
499
+ * Makes a plain error info object from an Error.
500
+ * @param {Error} err Error to get info from
501
+ * @returns {MakeErrorOptions}
502
+ * @private
503
+ */
504
+ static makePlainError(err) {
505
+ return {
506
+ name: err.name,
507
+ message: err.message,
508
+ stack: err.stack,
509
+ };
510
+ }
511
+
512
+ /**
513
+ * Moves an element in an array *in place*.
514
+ * @param {Array<*>} array Array to modify
515
+ * @param {*} element Element to move
516
+ * @param {number} newIndex Index or offset to move the element to
517
+ * @param {boolean} [offset=false] Move the element by an offset amount rather than to a set index
518
+ * @returns {number}
519
+ * @private
520
+ */
521
+ static moveElementInArray(array, element, newIndex, offset = false) {
522
+ const index = array.indexOf(element);
523
+ newIndex = (offset ? index : 0) + newIndex;
524
+ if (newIndex > -1 && newIndex < array.length) {
525
+ const removedElement = array.splice(index, 1)[0];
526
+ array.splice(newIndex, 0, removedElement);
527
+ }
528
+ return array.indexOf(element);
529
+ }
530
+
531
+ /**
532
+ * Verifies the provided data is a string, otherwise throws provided error.
533
+ * @param {string} data The string resolvable to resolve
534
+ * @param {Function} [error] The Error constructor to instantiate. Defaults to Error
535
+ * @param {string} [errorMessage] The error message to throw with. Defaults to "Expected string, got <data> instead."
536
+ * @param {boolean} [allowEmpty=true] Whether an empty string should be allowed
537
+ * @returns {string}
538
+ */
539
+ static verifyString(
540
+ data,
541
+ error = Error,
542
+ errorMessage = `Expected a string, got ${data} instead.`,
543
+ allowEmpty = true,
544
+ ) {
545
+ if (typeof data !== 'string') throw new error(errorMessage);
546
+ if (!allowEmpty && data.length === 0) throw new error(errorMessage);
547
+ return data;
548
+ }
549
+
550
+ /**
551
+ * Can be a number, hex string, a {@link Color}, or an RGB array like:
552
+ * ```js
553
+ * [255, 0, 255] // purple
554
+ * ```
555
+ * @typedef {string|Color|number|number[]} ColorResolvable
556
+ */
557
+
558
+ /**
559
+ * Resolves a ColorResolvable into a color number.
560
+ * @param {ColorResolvable} color Color to resolve
561
+ * @returns {number} A color
562
+ */
563
+ static resolveColor(color) {
564
+ if (typeof color === 'string') {
565
+ if (color === 'RANDOM') return Math.floor(Math.random() * (0xffffff + 1));
566
+ if (color === 'DEFAULT') return 0;
567
+ color = Colors[color] ?? parseInt(color.replace('#', ''), 16);
568
+ } else if (Array.isArray(color)) {
569
+ color = (color[0] << 16) + (color[1] << 8) + color[2];
570
+ }
571
+
572
+ if (color < 0 || color > 0xffffff) throw new RangeError('COLOR_RANGE');
573
+ else if (Number.isNaN(color)) throw new TypeError('COLOR_CONVERT');
574
+
575
+ return color;
576
+ }
577
+
578
+ /**
579
+ * Sorts by Discord's position and id.
580
+ * @param {Collection} collection Collection of objects to sort
581
+ * @returns {Collection}
582
+ */
583
+ static discordSort(collection) {
584
+ const isGuildChannel = collection.first() instanceof GuildChannel;
585
+ return collection.toSorted(
586
+ isGuildChannel
587
+ ? (a, b) => a.rawPosition - b.rawPosition || Number(BigInt(a.id) - BigInt(b.id))
588
+ : (a, b) => a.rawPosition - b.rawPosition || Number(BigInt(b.id) - BigInt(a.id)),
589
+ );
590
+ }
591
+
592
+ /**
593
+ * Sets the position of a Channel or Role.
594
+ * @param {Channel|Role} item Object to set the position of
595
+ * @param {number} position New position for the object
596
+ * @param {boolean} relative Whether `position` is relative to its current position
597
+ * @param {Collection<string, Channel|Role>} sorted A collection of the objects sorted properly
598
+ * @param {APIRouter} route Route to call PATCH on
599
+ * @param {string} [reason] Reason for the change
600
+ * @returns {Promise<Channel[]|Role[]>} Updated item list, with `id` and `position` properties
601
+ * @private
602
+ */
603
+ static async setPosition(item, position, relative, sorted, route, reason) {
604
+ let updatedItems = [...sorted.values()];
605
+ Util.moveElementInArray(updatedItems, item, position, relative);
606
+ updatedItems = updatedItems.map((r, i) => ({ id: r.id, position: i }));
607
+ await route.patch({ data: updatedItems, reason });
608
+ return updatedItems;
609
+ }
610
+
611
+ /**
612
+ * Alternative to Node's `path.basename`, removing query string after the extension if it exists.
613
+ * @param {string} path Path to get the basename of
614
+ * @param {string} [ext] File extension to remove
615
+ * @returns {string} Basename of the path
616
+ * @private
617
+ */
618
+ static basename(path, ext) {
619
+ const res = parse(path);
620
+ return ext && res.ext.startsWith(ext) ? res.name : res.base.split('?')[0];
621
+ }
622
+
623
+ /**
624
+ * Breaks user, role and everyone/here mentions by adding a zero width space after every @ character
625
+ * @param {string} str The string to sanitize
626
+ * @returns {string}
627
+ * @deprecated Use {@link BaseMessageOptions#allowedMentions} instead.
628
+ */
629
+ static removeMentions(str) {
630
+ if (!deprecationEmittedForRemoveMentions) {
631
+ process.emitWarning(
632
+ 'The Util.removeMentions method is deprecated. Use MessageOptions#allowedMentions instead.',
633
+ 'DeprecationWarning',
634
+ );
635
+
636
+ deprecationEmittedForRemoveMentions = true;
637
+ }
638
+
639
+ return Util._removeMentions(str);
640
+ }
641
+
642
+ static _removeMentions(str) {
643
+ return str.replaceAll('@', '@\u200b');
644
+ }
645
+
646
+ /**
647
+ * The content to have all mentions replaced by the equivalent text.
648
+ * <warn>When {@link Util.removeMentions} is removed, this method will no longer sanitize mentions.
649
+ * Use {@link BaseMessageOptions#allowedMentions} instead to prevent mentions when sending a message.</warn>
650
+ * @param {string} str The string to be converted
651
+ * @param {TextBasedChannels} channel The channel the string was sent in
652
+ * @returns {string}
653
+ */
654
+ static cleanContent(str, channel) {
655
+ str = str
656
+ .replace(/<@!?[0-9]+>/g, input => {
657
+ const id = input.replace(/<|!|>|@/g, '');
658
+ if (channel.type === 'DM') {
659
+ const user = channel.client.users.cache.get(id);
660
+ return user ? Util._removeMentions(`@${user.username}`) : input;
661
+ }
662
+
663
+ const member = channel.guild?.members.cache.get(id);
664
+ if (member) {
665
+ return Util._removeMentions(`@${member.displayName}`);
666
+ } else {
667
+ const user = channel.client.users.cache.get(id);
668
+ return user ? Util._removeMentions(`@${user.username}`) : input;
669
+ }
670
+ })
671
+ .replace(/<#[0-9]+>/g, input => {
672
+ const mentionedChannel = channel.client.channels.cache.get(input.replace(/<|#|>/g, ''));
673
+ return mentionedChannel ? `#${mentionedChannel.name}` : input;
674
+ })
675
+ .replace(/<@&[0-9]+>/g, input => {
676
+ if (channel.type === 'DM') return input;
677
+ const role = channel.guild.roles.cache.get(input.replace(/<|@|>|&/g, ''));
678
+ return role ? `@${role.name}` : input;
679
+ });
680
+ return str;
681
+ }
682
+
683
+ /**
684
+ * The content to put in a code block with all code block fences replaced by the equivalent backticks.
685
+ * @param {string} text The string to be converted
686
+ * @returns {string}
687
+ */
688
+ static cleanCodeBlockContent(text) {
689
+ return text.replaceAll('```', '`\u200b``');
690
+ }
691
+
692
+ /**
693
+ * Creates a sweep filter that sweeps archived threads
694
+ * @param {number} [lifetime=14400] How long a thread has to be archived to be valid for sweeping
695
+ * @deprecated When not using with `makeCache` use `Sweepers.archivedThreadSweepFilter` instead
696
+ * @returns {SweepFilter}
697
+ */
698
+ static archivedThreadSweepFilter(lifetime = 14400) {
699
+ const filter = require('./Sweepers').archivedThreadSweepFilter(lifetime);
700
+ filter.isDefault = true;
701
+ return filter;
702
+ }
703
+
704
+ /**
705
+ * Resolves the maximum time a guild's thread channels should automatically archive in case of no recent activity.
706
+ * @param {Guild} guild The guild to resolve this limit from.
707
+ * @deprecated This will be removed in the next major version.
708
+ * @returns {number}
709
+ */
710
+ static resolveAutoArchiveMaxLimit() {
711
+ if (!deprecationEmittedForResolveAutoArchiveMaxLimit) {
712
+ process.emitWarning(
713
+ // eslint-disable-next-line max-len
714
+ "The Util.resolveAutoArchiveMaxLimit method and the 'MAX' option are deprecated and will be removed in the next major version.",
715
+ 'DeprecationWarning',
716
+ );
717
+ deprecationEmittedForResolveAutoArchiveMaxLimit = true;
718
+ }
719
+ return 10080;
720
+ }
721
+
722
+ /**
723
+ * Transforms an API guild forum tag to camel-cased guild forum tag.
724
+ * @param {APIGuildForumTag} tag The tag to transform
725
+ * @returns {GuildForumTag}
726
+ * @ignore
727
+ */
728
+ static transformAPIGuildForumTag(tag) {
729
+ return {
730
+ id: tag.id,
731
+ name: tag.name,
732
+ moderated: tag.moderated,
733
+ emoji:
734
+ tag.emoji_id ?? tag.emoji_name
735
+ ? {
736
+ id: tag.emoji_id,
737
+ name: tag.emoji_name,
738
+ }
739
+ : null,
740
+ };
741
+ }
742
+
743
+ /**
744
+ * Transforms a camel-cased guild forum tag to an API guild forum tag.
745
+ * @param {GuildForumTag} tag The tag to transform
746
+ * @returns {APIGuildForumTag}
747
+ * @ignore
748
+ */
749
+ static transformGuildForumTag(tag) {
750
+ return {
751
+ id: tag.id,
752
+ name: tag.name,
753
+ moderated: tag.moderated,
754
+ emoji_id: tag.emoji?.id ?? null,
755
+ emoji_name: tag.emoji?.name ?? null,
756
+ };
757
+ }
758
+
759
+ /**
760
+ * Transforms an API guild forum default reaction object to a
761
+ * camel-cased guild forum default reaction object.
762
+ * @param {APIGuildForumDefaultReactionEmoji} defaultReaction The default reaction to transform
763
+ * @returns {DefaultReactionEmoji}
764
+ * @ignore
765
+ */
766
+ static transformAPIGuildDefaultReaction(defaultReaction) {
767
+ return {
768
+ id: defaultReaction.emoji_id,
769
+ name: defaultReaction.emoji_name,
770
+ };
771
+ }
772
+
773
+ /**
774
+ * Transforms a camel-cased guild forum default reaction object to an
775
+ * API guild forum default reaction object.
776
+ * @param {DefaultReactionEmoji} defaultReaction The default reaction to transform
777
+ * @returns {APIGuildForumDefaultReactionEmoji}
778
+ * @ignore
779
+ */
780
+ static transformGuildDefaultReaction(defaultReaction) {
781
+ return {
782
+ emoji_id: defaultReaction.id,
783
+ emoji_name: defaultReaction.name,
784
+ };
785
+ }
786
+
787
+ /**
788
+ * Transforms a guild scheduled event recurrence rule object to a snake-cased variant.
789
+ * @param {GuildScheduledEventRecurrenceRuleOptions} recurrenceRule The recurrence rule to transform
790
+ * @returns {APIGuildScheduledEventRecurrenceRule}
791
+ * @ignore
792
+ */
793
+ static transformGuildScheduledEventRecurrenceRule(recurrenceRule) {
794
+ return {
795
+ start: new Date(recurrenceRule.startAt).toISOString(),
796
+ frequency: recurrenceRule.frequency,
797
+ interval: recurrenceRule.interval,
798
+ by_weekday: recurrenceRule.byWeekday,
799
+ by_n_weekday: recurrenceRule.byNWeekday,
800
+ by_month: recurrenceRule.byMonth,
801
+ by_month_day: recurrenceRule.byMonthDay,
802
+ };
803
+ }
804
+
805
+ /**
806
+ * Transforms API incidents data to a camel-cased variant.
807
+ * @param {APIIncidentsData} data The incidents data to transform
808
+ * @returns {IncidentActions}
809
+ * @ignore
810
+ */
811
+ static transformAPIIncidentsData(data) {
812
+ return {
813
+ invitesDisabledUntil: data.invites_disabled_until ? new Date(data.invites_disabled_until) : null,
814
+ dmsDisabledUntil: data.dms_disabled_until ? new Date(data.dms_disabled_until) : null,
815
+ dmSpamDetectedAt: data.dm_spam_detected_at ? new Date(data.dm_spam_detected_at) : null,
816
+ raidDetectedAt: data.raid_detected_at ? new Date(data.raid_detected_at) : null,
817
+ };
818
+ }
819
+
820
+ /**
821
+ * Gets an array of the channel types that can be moved in the channel group. For example, a GuildText channel would
822
+ * return an array containing the types that can be ordered within the text channels (always at the top), and a voice
823
+ * channel would return an array containing the types that can be ordered within the voice channels (always at the
824
+ * bottom).
825
+ * @param {ChannelType} type The type of the channel
826
+ * @returns {ChannelType[]}
827
+ * @ignore
828
+ */
829
+ static getSortableGroupTypes(type) {
830
+ switch (type) {
831
+ case 'GUILD_TEXT':
832
+ case 'GUILD_ANNOUNCEMENT':
833
+ case 'GUILD_FORUM':
834
+ return TextSortableGroupTypes;
835
+ case 'GUILD_VOICE':
836
+ case 'GUILD_STAGE_VOICE':
837
+ return VoiceSortableGroupTypes;
838
+ case 'GUILD_CATEGORY':
839
+ return CategorySortableGroupTypes;
840
+ default:
841
+ return [type];
842
+ }
843
+ }
844
+
845
+ /**
846
+ * Calculates the default avatar index for a given user id.
847
+ * @param {Snowflake} userId - The user id to calculate the default avatar index for
848
+ * @returns {number}
849
+ */
850
+ static calculateUserDefaultAvatarIndex(userId) {
851
+ return Number(BigInt(userId) >> 22n) % 6;
852
+ }
853
+
854
+ static async getUploadURL(client, channelId, files) {
855
+ if (!files.length) return [];
856
+ files = files.map((file, i) => ({
857
+ filename: file.name,
858
+ // 25MB = 26_214_400bytes
859
+ file_size: Math.floor((26_214_400 / 10) * Math.random()),
860
+ id: `${i}`,
861
+ }));
862
+ const { attachments } = await client.api.channels[channelId].attachments.post({
863
+ data: {
864
+ files,
865
+ },
866
+ });
867
+ return attachments;
868
+ }
869
+
870
+ static uploadFile(data, url) {
871
+ return new Promise((resolve, reject) => {
872
+ fetch(url, {
873
+ method: 'PUT',
874
+ body: data,
875
+ duplex: 'half', // Node.js v20
876
+ })
877
+ .then(res => {
878
+ if (res.ok) {
879
+ resolve(res);
880
+ } else {
881
+ reject(res);
882
+ }
883
+ })
884
+ .catch(reject);
885
+ });
886
+ }
887
+
888
+ /**
889
+ * Lazily evaluates a callback function (yea it's v14 :yay:)
890
+ * @param {Function} cb The callback to lazily evaluate
891
+ * @returns {Function}
892
+ * @example
893
+ * const User = lazy(() => require('./User'));
894
+ * const user = new (User())(client, data);
895
+ */
896
+ static lazy(cb) {
897
+ let defaultValue;
898
+ return () => (defaultValue ??= cb());
899
+ }
900
+
901
+ /**
902
+ * Hacking check object instanceof Proxy-agent
903
+ * @param {Object} object any
904
+ * @returns {boolean}
905
+ */
906
+ static verifyProxyAgent(object) {
907
+ return typeof object == 'object' && object.httpAgent instanceof Agent && object.httpsAgent instanceof Agent;
908
+ }
909
+
910
+ static checkUndiciProxyAgent(data) {
911
+ if (typeof data === 'string') {
912
+ return {
913
+ uri: data,
914
+ };
915
+ }
916
+ if (data instanceof URL) {
917
+ return {
918
+ uri: data.toString(),
919
+ };
920
+ }
921
+ if (typeof data === 'object' && typeof data.uri === 'string') return data;
922
+ return false;
923
+ }
924
+
925
+ static createPromiseInteraction(client, nonce, timeoutMs = 5_000, isHandlerDeferUpdate = false, parent) {
926
+ return new Promise((resolve, reject) => {
927
+ // Waiting for MsgCreate / ModalCreate
928
+ let dataFromInteractionSuccess;
929
+ let dataFromNormalEvent;
930
+ const handler = data => {
931
+ // UnhandledPacket
932
+ if (isHandlerDeferUpdate && data.d?.nonce == nonce && data.t == 'INTERACTION_SUCCESS') {
933
+ // Interaction#deferUpdate
934
+ client.removeListener(Events.MESSAGE_CREATE, handler);
935
+ client.removeListener(Events.UNHANDLED_PACKET, handler);
936
+ client.removeListener(Events.INTERACTION_MODAL_CREATE, handler);
937
+ dataFromInteractionSuccess = parent;
938
+ }
939
+ if (data.nonce !== nonce) return;
940
+ clearTimeout(timeout);
941
+ client.removeListener(Events.MESSAGE_CREATE, handler);
942
+ client.removeListener(Events.INTERACTION_MODAL_CREATE, handler);
943
+ if (isHandlerDeferUpdate) client.removeListener(Events.UNHANDLED_PACKET, handler);
944
+ client.decrementMaxListeners();
945
+ dataFromNormalEvent = data;
946
+ resolve(data);
947
+ };
948
+ const timeout = setTimeout(() => {
949
+ if (dataFromInteractionSuccess || dataFromNormalEvent) {
950
+ resolve(dataFromNormalEvent || dataFromInteractionSuccess);
951
+ return;
952
+ }
953
+ client.removeListener(Events.MESSAGE_CREATE, handler);
954
+ client.removeListener(Events.INTERACTION_MODAL_CREATE, handler);
955
+ if (isHandlerDeferUpdate) client.removeListener(Events.UNHANDLED_PACKET, handler);
956
+ client.decrementMaxListeners();
957
+ reject(new DiscordError('INTERACTION_FAILED'));
958
+ }, timeoutMs).unref();
959
+ client.incrementMaxListeners();
960
+ client.on(Events.MESSAGE_CREATE, handler);
961
+ client.on(Events.INTERACTION_MODAL_CREATE, handler);
962
+ if (isHandlerDeferUpdate) client.on(Events.UNHANDLED_PACKET, handler);
963
+ });
964
+ }
965
+
966
+ static clearNullOrUndefinedObject(object) {
967
+ const data = {};
968
+ const keys = Object.keys(object);
969
+
970
+ for (const key of keys) {
971
+ const value = object[key];
972
+ if (value === undefined || value === null || (Array.isArray(value) && value.length === 0)) {
973
+ continue;
974
+ } else if (!Array.isArray(value) && typeof value === 'object') {
975
+ const cleanedValue = Util.clearNullOrUndefinedObject(value);
976
+ if (cleanedValue !== undefined) {
977
+ data[key] = cleanedValue;
978
+ }
979
+ } else {
980
+ data[key] = value;
981
+ }
982
+ }
983
+
984
+ return Object.keys(data).length > 0 ? data : undefined;
985
+ }
986
+
987
+ static getAllPayloadType() {
988
+ return payloadTypes;
989
+ }
990
+
991
+ /**
992
+ * Get the payload type of the codec
993
+ * @param {'opus' | 'H264' | 'H265' | 'VP8' | 'VP9' | 'AV1'} codecName - Codec name
994
+ * @returns {number}
995
+ */
996
+ static getPayloadType(codecName) {
997
+ return payloadTypes.find(p => p.name === codecName).payload_type;
998
+ }
999
+
1000
+ static getSDPCodecName(portUdpH264, portUdpH265, portUdpOpus) {
1001
+ const payloadTypeH264 = Util.getPayloadType('H264');
1002
+ const payloadTypeH265 = Util.getPayloadType('H265');
1003
+ const payloadTypeOpus = Util.getPayloadType('opus');
1004
+ let sdpData = `v=0
1005
+ o=- 0 0 IN IP4 0.0.0.0
1006
+ s=-
1007
+ c=IN IP4 0.0.0.0
1008
+ t=0 0
1009
+ a=tool:libavformat 61.1.100
1010
+ m=video ${portUdpH264} RTP/AVP ${payloadTypeH264}
1011
+ c=IN IP4 127.0.0.1
1012
+ b=AS:1000
1013
+ a=rtpmap:${payloadTypeH264} H264/90000
1014
+ a=fmtp:${payloadTypeH264} profile-level-id=42e01f;sprop-parameter-sets=Z0IAH6tAoAt2AtwEBAaQeJEV,aM4JyA==;packetization-mode=1
1015
+ ${
1016
+ portUdpH265
1017
+ ? `m=video ${portUdpH265} RTP/AVP ${payloadTypeH265}
1018
+ c=IN IP4 127.0.0.1
1019
+ b=AS:1000
1020
+ a=rtpmap:${payloadTypeH265} H265/90000`
1021
+ : ''
1022
+ }
1023
+ m=audio ${portUdpOpus} RTP/AVP ${payloadTypeOpus}
1024
+ c=IN IP4 127.0.0.1
1025
+ b=AS:96
1026
+ a=rtpmap:${payloadTypeOpus} opus/48000/2
1027
+ a=fmtp:${payloadTypeOpus} minptime=10;useinbandfec=1
1028
+ a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level
1029
+ a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
1030
+ a=extmap:3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
1031
+ a=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid
1032
+ a=extmap:5 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay
1033
+ a=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/video-content-type
1034
+ a=extmap:7 http://www.webrtc.org/experiments/rtp-hdrext/video-timing
1035
+ a=extmap:8 http://www.webrtc.org/experiments/rtp-hdrext/color-space
1036
+ a=extmap:10 urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id
1037
+ a=extmap:11 urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id
1038
+ a=extmap:13 urn:3gpp:video-orientation
1039
+ a=extmap:14 urn:ietf:params:rtp-hdrext:toffset
1040
+ `;
1041
+ return sdpData;
1042
+ }
1043
+ }
1044
+
1045
+ module.exports = Util;
1046
+
1047
+ // Fixes Circular
1048
+ const GuildChannel = require('../structures/GuildChannel');