@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,123 @@
1
+
2
+ import { isJSONEncodable } from '@ovencord/util';
3
+ import { AuthorizingIntegrationOwners } from '../structures/AuthorizingIntegrationOwners.js';
4
+
5
+ /**
6
+ * Transforms a string to snake_case.
7
+ *
8
+ * @param {string} str The string to transform
9
+ * @returns {string}
10
+ */
11
+ const snakeCase = (str: string): string => str.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`);
12
+
13
+ /**
14
+ * Transforms camel-cased keys into snake cased keys
15
+ *
16
+ * @param {*} obj The object to transform
17
+ * @returns {*}
18
+ */
19
+ export function toSnakeCase(obj: any): any {
20
+ if (typeof obj !== 'object' || !obj) return obj;
21
+ if (obj instanceof Date) return obj;
22
+ if (isJSONEncodable(obj)) return toSnakeCase(obj.toJSON());
23
+ if (Array.isArray(obj)) return obj.map(toSnakeCase);
24
+ return Object.fromEntries(Object.entries(obj).map(([key, value]) => [snakeCase(key), toSnakeCase(value)]));
25
+ }
26
+
27
+ /**
28
+ * Transforms an API auto moderation action object to a camel-cased variant.
29
+ *
30
+ * @param {any} autoModerationAction The action to transform
31
+ * @returns {any}
32
+ * @ignore
33
+ */
34
+ export function _transformAPIAutoModerationAction(autoModerationAction: any): any {
35
+ return {
36
+ type: autoModerationAction.type,
37
+ metadata: {
38
+ durationSeconds: autoModerationAction.metadata.duration_seconds ?? null,
39
+ channelId: autoModerationAction.metadata.channel_id ?? null,
40
+ customMessage: autoModerationAction.metadata.custom_message ?? null,
41
+ },
42
+ };
43
+ }
44
+
45
+ /**
46
+ * Transforms an API message interaction metadata object to a camel-cased variant.
47
+ *
48
+ * @param {any} client The client
49
+ * @param {any} messageInteractionMetadata The metadata to transform
50
+ * @returns {any}
51
+ * @ignore
52
+ */
53
+ export function _transformAPIMessageInteractionMetadata(client: any, messageInteractionMetadata: any): any {
54
+ return {
55
+ id: messageInteractionMetadata.id,
56
+ type: messageInteractionMetadata.type,
57
+ user: client.users._add(messageInteractionMetadata.user),
58
+ authorizingIntegrationOwners: new AuthorizingIntegrationOwners(
59
+ client,
60
+ messageInteractionMetadata.authorizing_integration_owners,
61
+ ),
62
+ originalResponseMessageId: messageInteractionMetadata.original_response_message_id ?? null,
63
+ interactedMessageId: messageInteractionMetadata.interacted_message_id ?? null,
64
+ triggeringInteractionMetadata: messageInteractionMetadata.triggering_interaction_metadata
65
+ ? _transformAPIMessageInteractionMetadata(client, messageInteractionMetadata.triggering_interaction_metadata)
66
+ : null,
67
+ };
68
+ }
69
+
70
+ /**
71
+ * Transforms a guild scheduled event recurrence rule object to a snake-cased variant.
72
+ *
73
+ * @param {any} recurrenceRule The recurrence rule to transform
74
+ * @returns {any}
75
+ * @ignore
76
+ */
77
+ export function _transformGuildScheduledEventRecurrenceRule(recurrenceRule: any): any {
78
+ return {
79
+ start: new Date(recurrenceRule.startAt).toISOString(),
80
+ frequency: recurrenceRule.frequency,
81
+ interval: recurrenceRule.interval,
82
+ by_weekday: recurrenceRule.byWeekday,
83
+ by_n_weekday: recurrenceRule.byNWeekday,
84
+ by_month: recurrenceRule.byMonth,
85
+ by_month_day: recurrenceRule.byMonthDay,
86
+ };
87
+ }
88
+
89
+ /**
90
+ * Transforms API incidents data to a camel-cased variant.
91
+ *
92
+ * @param {any} data The incidents data to transform
93
+ * @returns {any}
94
+ * @ignore
95
+ */
96
+ export function _transformAPIIncidentsData(data: any): any {
97
+ return {
98
+ invitesDisabledUntil: data.invites_disabled_until ? new Date(data.invites_disabled_until) : null,
99
+ dmsDisabledUntil: data.dms_disabled_until ? new Date(data.dms_disabled_until) : null,
100
+ dmSpamDetectedAt: data.dm_spam_detected_at ? new Date(data.dm_spam_detected_at) : null,
101
+ raidDetectedAt: data.raid_detected_at ? new Date(data.raid_detected_at) : null,
102
+ };
103
+ }
104
+
105
+ /**
106
+ * Transforms a collectibles object to a camel-cased variant.
107
+ *
108
+ * @param {any} collectibles The collectibles to transform
109
+ * @returns {any}
110
+ * @ignore
111
+ */
112
+ export function _transformCollectibles(collectibles: any): any {
113
+ if (!collectibles.nameplate) return { nameplate: null };
114
+
115
+ return {
116
+ nameplate: {
117
+ skuId: collectibles.nameplate.sku_id,
118
+ asset: collectibles.nameplate.asset,
119
+ label: collectibles.nameplate.label,
120
+ palette: collectibles.nameplate.palette,
121
+ },
122
+ };
123
+ }
@@ -0,0 +1,33 @@
1
+ /* eslint-disable jsdoc/check-values */
2
+
3
+ import { UserFlags } 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 User#flags} bitfield.
8
+ *
9
+ * @extends {BitField}
10
+ */
11
+ export class UserFlagsBitField extends BitField {
12
+ /**
13
+ * Numeric user flags.
14
+ *
15
+ * @type {UserFlags}
16
+ * @memberof UserFlagsBitField
17
+ */
18
+ static Flags = UserFlags;
19
+ }
20
+
21
+ /**
22
+ * @name UserFlagsBitField
23
+ * @kind constructor
24
+ * @memberof UserFlagsBitField
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 UserFlagsBitField#bitfield
33
+ */
@@ -0,0 +1,519 @@
1
+
2
+ import { parse } from 'node:path';
3
+ import { Collection } from '@ovencord/collection';
4
+ import { lazy } from '@ovencord/util';
5
+ import { ChannelType, RouteBases, Routes } from 'discord-api-types/v10';
6
+ import { Colors } from './Colors.js';
7
+ // eslint-disable-next-line import-x/order
8
+ import { DiscordjsError, DiscordjsRangeError, DiscordjsTypeError, ErrorCodes } from '../errors/index.js';
9
+
10
+ // Fixes circular dependencies.
11
+ const getAttachment = lazy(() => require('../structures/Attachment.js').Attachment);
12
+ const getGuildChannel = lazy(() => require('../structures/GuildChannel.js').GuildChannel);
13
+ const getSKU = lazy(() => require('../structures/SKU.js').SKU);
14
+
15
+ const isObject = (data: any): boolean => typeof data === 'object' && data !== null;
16
+
17
+ /**
18
+ * Flatten an object. Any properties that are collections will get converted to an array of keys.
19
+ *
20
+ * @param {Object} obj The object to flatten.
21
+ * @param {...Object<string, boolean|string>} [props] Specific properties to include/exclude.
22
+ * @returns {Object}
23
+ */
24
+ export function flatten(obj: any, ...props: any[]): any {
25
+ if (!isObject(obj)) return obj;
26
+
27
+ const objProps = Object.keys(obj)
28
+ .filter(key => !key.startsWith('_'))
29
+ .map(key => ({ [key]: true }));
30
+
31
+ const mergedProps = objProps.length ? Object.assign(...objProps, ...props) : Object.assign({}, ...props);
32
+
33
+ const out: any = {};
34
+
35
+ // eslint-disable-next-line prefer-const
36
+ for (let [prop, newProp] of Object.entries(mergedProps)) {
37
+ if (!newProp) continue;
38
+ newProp = newProp === true ? prop : newProp;
39
+
40
+ const element = obj[prop];
41
+ const elemIsObj = isObject(element);
42
+ const valueOf = elemIsObj && typeof element.valueOf === 'function' ? element.valueOf() : null;
43
+ const hasToJSON = elemIsObj && typeof element.toJSON === 'function';
44
+
45
+ // If it's a Collection, make the array of keys
46
+ if (element instanceof Collection) out[newProp as string] = Array.from(element.keys());
47
+ // If the valueOf is a Collection, use its array of keys
48
+ else if (valueOf instanceof Collection) out[newProp as string] = Array.from(valueOf.keys());
49
+ // If it's an array, call toJSON function on each element if present, otherwise flatten each element
50
+ else if (Array.isArray(element)) out[newProp as string] = element.map(elm => elm.toJSON?.() ?? flatten(elm));
51
+ // If it's an object with a primitive `valueOf`, use that value
52
+ else if (typeof valueOf !== 'object') out[newProp as string] = valueOf;
53
+ // If it's an object with a toJSON function, use the return value of it
54
+ else if (hasToJSON) out[newProp as string] = element.toJSON();
55
+ // If element is an object, use the flattened version of it
56
+ else if (typeof element === 'object') out[newProp as string] = flatten(element);
57
+ // If it's a primitive
58
+ else if (!elemIsObj) out[newProp as string] = element;
59
+ }
60
+
61
+ return out;
62
+ }
63
+
64
+ /**
65
+ * @typedef {Object} FetchRecommendedShardCountOptions
66
+ * @property {number} [guildsPerShard=1000] Number of guilds assigned per shard
67
+ * @property {number} [multipleOf=1] The multiple the shard count should round up to. (16 for large bot sharding)
68
+ */
69
+
70
+ /**
71
+ * Gets the recommended shard count from Discord.
72
+ *
73
+ * @param {string} token Discord auth token
74
+ * @param {FetchRecommendedShardCountOptions} [options] Options for fetching the recommended shard count
75
+ * @returns {Promise<number>} The recommended number of shards
76
+ */
77
+ export async function fetchRecommendedShardCount(token: string, { guildsPerShard = 1_000, multipleOf = 1 } = {}): Promise<number> {
78
+ if (!token) throw new DiscordjsError(ErrorCodes.TokenMissing);
79
+ const response = await fetch(RouteBases.api + Routes.gatewayBot(), {
80
+ method: 'GET',
81
+ headers: { Authorization: `Bot ${token.replace(/^bot\s*/i, '')}` },
82
+ });
83
+ if (!response.ok) {
84
+ if (response.status === 401) throw new DiscordjsError(ErrorCodes.TokenInvalid);
85
+ throw response;
86
+ }
87
+
88
+ const { shards }: any = await response.json();
89
+ return Math.ceil((shards * (1_000 / guildsPerShard)) / multipleOf) * multipleOf;
90
+ }
91
+
92
+ /**
93
+ * A partial emoji object.
94
+ *
95
+ * @typedef {Object} PartialEmoji
96
+ * @property {boolean} animated Whether the emoji is animated
97
+ * @property {Snowflake|undefined} id The id of the emoji
98
+ * @property {string} name The name of the emoji
99
+ */
100
+
101
+ /**
102
+ * Parses emoji info out of a string. The string must be one of:
103
+ * - A UTF-8 emoji (no id)
104
+ * - A URL-encoded UTF-8 emoji (no id)
105
+ * - A Discord custom emoji (`<:name:id>` or `<a:name:id>`)
106
+ *
107
+ * @param {string} text Emoji string to parse
108
+ * @returns {?PartialEmoji}
109
+ */
110
+ export function parseEmoji(text: string): any {
111
+ const decodedText = text.includes('%') ? decodeURIComponent(text) : text;
112
+ if (!decodedText.includes(':')) return { animated: false, name: decodedText, id: undefined };
113
+ const match = /<?(?:(?<animated>a):)?(?<name>\w{2,32}):(?<id>\d{17,19})?>?/.exec(decodedText);
114
+ return match && { animated: Boolean(match.groups!.animated), name: match.groups!.name, id: match.groups!.id };
115
+ }
116
+
117
+ /**
118
+ * A partial emoji object with only an id.
119
+ *
120
+ * @typedef {Object} PartialEmojiOnlyId
121
+ * @property {Snowflake} id The id of the emoji
122
+ */
123
+
124
+ /**
125
+ * Resolves a partial emoji object from an {@link EmojiIdentifierResolvable}, without checking a Client.
126
+ *
127
+ * @param {Emoji|EmojiIdentifierResolvable} emoji Emoji identifier to resolve
128
+ * @returns {?(PartialEmoji|PartialEmojiOnlyId)} Supplying a snowflake yields `PartialEmojiOnlyId`.
129
+ */
130
+ export function resolvePartialEmoji(emoji: any): any {
131
+ if (!emoji) return null;
132
+ if (typeof emoji === 'string') return /^\d{17,19}$/.test(emoji) ? { id: emoji } : parseEmoji(emoji);
133
+ const { id, name, animated } = emoji;
134
+ if (!id && !name) return null;
135
+ return { id, name, animated: Boolean(animated) };
136
+ }
137
+
138
+ /**
139
+ * Resolves a {@link GuildEmoji} from an emoji id.
140
+ *
141
+ * @param {Client} client The client to use to resolve the emoji
142
+ * @param {Snowflake} emojiId The emoji id to resolve
143
+ * @returns {?GuildEmoji}
144
+ * @private
145
+ */
146
+ export function resolveGuildEmoji(client: any, emojiId: string): any {
147
+ for (const guild of client.guilds.cache.values()) {
148
+ if (!guild.available) {
149
+ continue;
150
+ }
151
+
152
+ const emoji = guild.emojis.cache.get(emojiId);
153
+
154
+ if (emoji) {
155
+ return emoji;
156
+ }
157
+ }
158
+
159
+ return null;
160
+ }
161
+
162
+ /**
163
+ * Options used to make an error object.
164
+ *
165
+ * @typedef {Object} MakeErrorOptions
166
+ * @property {string} name Error type
167
+ * @property {string} message Message for the error
168
+ * @property {string} stack Stack for the error
169
+ * @private
170
+ */
171
+
172
+ /**
173
+ * Makes an Error from a plain info object.
174
+ *
175
+ * @param {MakeErrorOptions} obj Error info
176
+ * @returns {Error}
177
+ * @private
178
+ */
179
+ export function makeError(obj: any): Error {
180
+ const err = new Error(obj.message);
181
+ err.name = obj.name;
182
+ err.stack = obj.stack;
183
+ return err;
184
+ }
185
+
186
+ /**
187
+ * Makes a plain error info object from an Error.
188
+ *
189
+ * @param {Error} err Error to get info from
190
+ * @returns {MakeErrorOptions}
191
+ * @private
192
+ */
193
+ export function makePlainError(err: Error): any {
194
+ return {
195
+ name: err.name,
196
+ message: err.message,
197
+ stack: err.stack,
198
+ };
199
+ }
200
+
201
+ const TextSortableGroupTypes = [
202
+ ChannelType.GuildText,
203
+ ChannelType.GuildAnnouncement,
204
+ ChannelType.GuildForum,
205
+ ChannelType.GuildMedia,
206
+ ];
207
+
208
+ const VoiceSortableGroupTypes = [ChannelType.GuildVoice, ChannelType.GuildStageVoice];
209
+ const CategorySortableGroupTypes = [ChannelType.GuildCategory];
210
+
211
+ /**
212
+ * Gets an array of the channel types that can be moved in the channel group. For example, a GuildText channel would
213
+ * return an array containing the types that can be ordered within the text channels (always at the top), and a voice
214
+ * channel would return an array containing the types that can be ordered within the voice channels (always at the
215
+ * bottom).
216
+ *
217
+ * @param {ChannelType} type The type of the channel
218
+ * @returns {ChannelType[]}
219
+ * @private
220
+ */
221
+ export function getSortableGroupTypes(type: ChannelType): ChannelType[] {
222
+ switch (type) {
223
+ case ChannelType.GuildText:
224
+ case ChannelType.GuildAnnouncement:
225
+ case ChannelType.GuildForum:
226
+ case ChannelType.GuildMedia:
227
+ return TextSortableGroupTypes;
228
+ case ChannelType.GuildVoice:
229
+ case ChannelType.GuildStageVoice:
230
+ return VoiceSortableGroupTypes;
231
+ case ChannelType.GuildCategory:
232
+ return CategorySortableGroupTypes;
233
+ default:
234
+ return [type];
235
+ }
236
+ }
237
+
238
+ /**
239
+ * Moves an element in an array *in place*.
240
+ *
241
+ * @param {Array<*>} array Array to modify
242
+ * @param {*} element Element to move
243
+ * @param {number} newIndex Index or offset to move the element to
244
+ * @param {boolean} [offset=false] Move the element by an offset amount rather than to a set index
245
+ * @returns {number}
246
+ * @private
247
+ */
248
+ export function moveElementInArray(array: any[], element: any, newIndex: number, offset = false): number {
249
+ const index = array.indexOf(element);
250
+ const targetIndex = (offset ? index : 0) + newIndex;
251
+ if (targetIndex > -1 && targetIndex < array.length) {
252
+ const removedElement = array.splice(index, 1)[0];
253
+ array.splice(targetIndex, 0, removedElement);
254
+ }
255
+
256
+ return array.indexOf(element);
257
+ }
258
+
259
+ /**
260
+ * Verifies the provided data is a string, otherwise throws provided error.
261
+ *
262
+ * @param {string} data The string resolvable to resolve
263
+ * @param {Function} [error=Error] The Error constructor to instantiate. Defaults to Error
264
+ * @param {string} [errorMessage="Expected string, got <data> instead."] The error message to throw with. Defaults to "Expected string, got <data> instead."
265
+ * @param {boolean} [allowEmpty=true] Whether an empty string should be allowed
266
+ * @returns {string}
267
+ */
268
+ export function verifyString(
269
+ data: any,
270
+ error: any = Error,
271
+ errorMessage = `Expected a string, got ${data} instead.`,
272
+ allowEmpty = true,
273
+ ): string {
274
+ if (typeof data !== 'string') throw new error(errorMessage);
275
+ if (!allowEmpty && data.length === 0) throw new error(errorMessage);
276
+ return data;
277
+ }
278
+
279
+ /**
280
+ * Resolves a ColorResolvable into a color number.
281
+ *
282
+ * @param {ColorResolvable} color Color to resolve
283
+ * @returns {number} A color
284
+ */
285
+ export function resolveColor(color: any): number {
286
+ let resolvedColor;
287
+
288
+ if (typeof color === 'string') {
289
+ if (color === 'Random') return Math.floor(Math.random() * (0xffffff + 1));
290
+ if (color === 'Default') return 0;
291
+ if (/^#?[\da-f]{6}$/i.test(color)) return Number.parseInt(color.replace('#', ''), 16);
292
+ resolvedColor = Colors[color as keyof typeof Colors];
293
+ } else if (Array.isArray(color)) {
294
+ resolvedColor = (color[0] << 16) + (color[1] << 8) + color[2];
295
+ } else {
296
+ resolvedColor = color;
297
+ }
298
+
299
+ if (!Number.isInteger(resolvedColor)) {
300
+ throw new DiscordjsTypeError(ErrorCodes.ColorConvert, color);
301
+ }
302
+
303
+ if (resolvedColor < 0 || resolvedColor > 0xffffff) {
304
+ throw new DiscordjsRangeError(ErrorCodes.ColorRange);
305
+ }
306
+
307
+ return resolvedColor;
308
+ }
309
+
310
+ /**
311
+ * Sorts by Discord's position and id.
312
+ *
313
+ * @param {Collection} collection Collection of objects to sort
314
+ * @returns {Collection}
315
+ */
316
+ export function discordSort(collection: Collection<string, any>): Collection<string, any> {
317
+ const isGuildChannel = collection.first() instanceof getGuildChannel();
318
+ return collection.toSorted(
319
+ isGuildChannel
320
+ ? (a, b) => a.rawPosition - b.rawPosition || Number(BigInt(a.id) - BigInt(b.id))
321
+ : (a, b) => a.rawPosition - b.rawPosition || Number(BigInt(b.id) - BigInt(a.id)),
322
+ );
323
+ }
324
+
325
+ /**
326
+ * Sets the position of a Channel or Role.
327
+ *
328
+ * @param {BaseChannel|Role} item Object to set the position of
329
+ * @param {number} position New position for the object
330
+ * @param {boolean} relative Whether `position` is relative to its current position
331
+ * @param {Collection<string, BaseChannel|Role>} sorted A collection of the objects sorted properly
332
+ * @param {Client} client The client to use to patch the data
333
+ * @param {string} route Route to call PATCH on
334
+ * @param {string} [reason] Reason for the change
335
+ * @returns {Promise<BaseChannel[]|Role[]>} Updated item list, with `id` and `position` properties
336
+ * @private
337
+ */
338
+ export async function setPosition(item: any, position: number, relative: boolean, sorted: Collection<string, any>, client: any, route: string, reason?: string): Promise<any[]> {
339
+ let updatedItems = [...sorted.values()];
340
+ moveElementInArray(updatedItems, item, position, relative);
341
+ updatedItems = updatedItems.map((innerItem, index) => ({ id: innerItem.id, position: index }));
342
+ await client.rest.patch(route, { body: updatedItems, reason });
343
+ return updatedItems;
344
+ }
345
+
346
+ /**
347
+ * Alternative to Node's `path.basename`, removing query string after the extension if it exists.
348
+ *
349
+ * @param {string} path Path to get the basename of
350
+ * @param {string} [ext] File extension to remove
351
+ * @returns {string} Basename of the path
352
+ * @private
353
+ */
354
+ export function basename(path: string, ext?: string): string {
355
+ const res = parse(path);
356
+ return ext && res.ext.startsWith(ext) ? res.name : res.base.split('?')[0];
357
+ }
358
+
359
+ /**
360
+ * Find the filename to use for attachments.
361
+ *
362
+ * @param {BufferResolvable|Stream} thing The thing to attach as attachment
363
+ * @returns {string} filename to use
364
+ */
365
+ export function findName(thing: any): string {
366
+ if (typeof thing === 'string') {
367
+ return basename(thing);
368
+ }
369
+
370
+ if (thing.path) {
371
+ return basename(thing.path);
372
+ }
373
+
374
+ return 'file.jpg';
375
+ }
376
+
377
+ /**
378
+ * The content to have all mentions replaced by the equivalent text.
379
+ *
380
+ * @param {string} str The string to be converted
381
+ * @param {TextBasedChannels} channel The channel the string was sent in
382
+ * @returns {string}
383
+ */
384
+ export function cleanContent(str: string, channel: any): string {
385
+ return str.replaceAll(
386
+ /<(?:(?<type>@[!&]?|#)|(?:\/(?<commandName>[-_\p{L}\p{N}\p{sc=Deva}\p{sc=Thai} ]+):)|(?:a?:(?<emojiName>[\w]+):))(?<id>\d{17,19})>/gu,
387
+ (match, type, commandName, emojiName, id) => {
388
+ if (commandName) return `/${commandName}`;
389
+
390
+ if (emojiName) return `:${emojiName}:`;
391
+
392
+ switch (type) {
393
+ case '@':
394
+ case '@!': {
395
+ const member = channel.guild?.members.cache.get(id);
396
+ if (member) {
397
+ return `@${member.displayName}`;
398
+ }
399
+
400
+ const user = channel.client.users.cache.get(id);
401
+ return user ? `@${user.displayName}` : match;
402
+ }
403
+
404
+ case '@&': {
405
+ if (channel.type === ChannelType.DM) return match;
406
+ const role = channel.guild.roles.cache.get(id);
407
+ return role ? `@${role.name}` : match;
408
+ }
409
+
410
+ case '#': {
411
+ const mentionedChannel = channel.client.channels.cache.get(id);
412
+ return mentionedChannel ? `#${mentionedChannel.name}` : match;
413
+ }
414
+
415
+ default: {
416
+ return match;
417
+ }
418
+ }
419
+ },
420
+ );
421
+ }
422
+
423
+ /**
424
+ * The content to put in a code block with all code block fences replaced by the equivalent backticks.
425
+ *
426
+ * @param {string} text The string to be converted
427
+ * @returns {string}
428
+ */
429
+ export function cleanCodeBlockContent(text: string): string {
430
+ return text.replaceAll('```', '`\u200B``');
431
+ }
432
+
433
+ /**
434
+ * Parses a webhook URL for the id and token.
435
+ *
436
+ * @param {string} url The URL to parse
437
+ * @returns {?WebhookDataIdWithToken} `null` if the URL is invalid, otherwise the id and the token
438
+ */
439
+ export function parseWebhookURL(url: string): any {
440
+ const matches =
441
+ /https?:\/\/(?:ptb\.|canary\.)?discord\.com\/api(?:\/v\d{1,2})?\/webhooks\/(?<id>\d{17,19})\/(?<token>[\w-]{68})/i.exec(
442
+ url,
443
+ );
444
+
445
+ return matches && { id: matches.groups!.id, token: matches.groups!.token };
446
+ }
447
+
448
+ /**
449
+ * Transforms the resolved data received from the API.
450
+ *
451
+ * @param {SupportingInteractionResolvedData} supportingData Data to support the transformation
452
+ * @param {APIInteractionDataResolved} [data] The received resolved objects
453
+ * @returns {CommandInteractionResolvedData}
454
+ * @private
455
+ */
456
+ export function transformResolved(
457
+ { client, guild, channel }: any,
458
+ { members, users, channels, roles, messages, attachments }: any = {},
459
+ ): any {
460
+ const result: any = {};
461
+
462
+ if (members) {
463
+ result.members = new Collection();
464
+ for (const [id, member] of Object.entries(members)) {
465
+ const user = (users as any)[id];
466
+ result.members.set(id, guild?.members._add({ user, ...member }) ?? member);
467
+ }
468
+ }
469
+
470
+ if (users) {
471
+ result.users = new Collection();
472
+ for (const user of Object.values(users)) {
473
+ result.users.set((user as any).id, client.users._add(user));
474
+ }
475
+ }
476
+
477
+ if (roles) {
478
+ result.roles = new Collection();
479
+ for (const role of Object.values(roles)) {
480
+ result.roles.set((role as any).id, guild?.roles._add(role) ?? role);
481
+ }
482
+ }
483
+
484
+ if (channels) {
485
+ result.channels = new Collection();
486
+ for (const apiChannel of Object.values(channels)) {
487
+ result.channels.set((apiChannel as any).id, client.channels._add(apiChannel, guild) ?? apiChannel);
488
+ }
489
+ }
490
+
491
+ if (messages) {
492
+ result.messages = new Collection();
493
+ for (const message of Object.values(messages)) {
494
+ result.messages.set((message as any).id, channel?.messages?._add(message) ?? message);
495
+ }
496
+ }
497
+
498
+ if (attachments) {
499
+ result.attachments = new Collection();
500
+ for (const attachment of Object.values(attachments)) {
501
+ const patched = new (getAttachment())(attachment);
502
+ result.attachments.set((attachment as any).id, patched);
503
+ }
504
+ }
505
+
506
+ return result;
507
+ }
508
+
509
+ /**
510
+ * Resolves a SKU id from a SKU resolvable.
511
+ *
512
+ * @param {SKUResolvable} resolvable The SKU resolvable to resolve
513
+ * @returns {?Snowflake} The resolved SKU id, or `null` if the resolvable was invalid
514
+ */
515
+ export function resolveSKUId(resolvable: any): string | null {
516
+ if (typeof resolvable === 'string') return resolvable;
517
+ if (resolvable instanceof getSKU()) return resolvable.id;
518
+ return null;
519
+ }