seyfert 0.1.0

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 (345) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +57 -0
  3. package/lib/api/CDN.d.ts +220 -0
  4. package/lib/api/CDN.js +236 -0
  5. package/lib/api/REST.d.ts +127 -0
  6. package/lib/api/REST.js +424 -0
  7. package/lib/api/Router.d.ts +17 -0
  8. package/lib/api/Router.js +63 -0
  9. package/lib/api/Routes/applications.d.ts +46 -0
  10. package/lib/api/Routes/applications.js +2 -0
  11. package/lib/api/Routes/cdn.d.ts +66 -0
  12. package/lib/api/Routes/cdn.js +2 -0
  13. package/lib/api/Routes/channels.d.ts +109 -0
  14. package/lib/api/Routes/channels.js +2 -0
  15. package/lib/api/Routes/gateway.d.ts +11 -0
  16. package/lib/api/Routes/gateway.js +2 -0
  17. package/lib/api/Routes/guilds.d.ts +171 -0
  18. package/lib/api/Routes/guilds.js +2 -0
  19. package/lib/api/Routes/index.d.ts +13 -0
  20. package/lib/api/Routes/index.js +17 -0
  21. package/lib/api/Routes/interactions.d.ts +14 -0
  22. package/lib/api/Routes/interactions.js +2 -0
  23. package/lib/api/Routes/invites.d.ts +9 -0
  24. package/lib/api/Routes/invites.js +2 -0
  25. package/lib/api/Routes/stage-instances.d.ts +13 -0
  26. package/lib/api/Routes/stage-instances.js +2 -0
  27. package/lib/api/Routes/stickers.d.ts +11 -0
  28. package/lib/api/Routes/stickers.js +2 -0
  29. package/lib/api/Routes/users.d.ts +35 -0
  30. package/lib/api/Routes/users.js +2 -0
  31. package/lib/api/Routes/voice.d.ts +10 -0
  32. package/lib/api/Routes/voice.js +2 -0
  33. package/lib/api/Routes/webhooks.d.ts +29 -0
  34. package/lib/api/Routes/webhooks.js +2 -0
  35. package/lib/api/errors/DiscordAPIError.d.ts +51 -0
  36. package/lib/api/errors/DiscordAPIError.js +81 -0
  37. package/lib/api/errors/HTTPError.d.ts +20 -0
  38. package/lib/api/errors/HTTPError.js +28 -0
  39. package/lib/api/errors/RateLimitError.d.ts +19 -0
  40. package/lib/api/errors/RateLimitError.js +37 -0
  41. package/lib/api/handlers/BurstHandler.d.ts +51 -0
  42. package/lib/api/handlers/BurstHandler.js +124 -0
  43. package/lib/api/handlers/SequentialHandler.d.ts +81 -0
  44. package/lib/api/handlers/SequentialHandler.js +365 -0
  45. package/lib/api/handlers/Shared.d.ts +14 -0
  46. package/lib/api/handlers/Shared.js +125 -0
  47. package/lib/api/index.d.ts +5 -0
  48. package/lib/api/index.js +21 -0
  49. package/lib/api/interfaces/Handler.d.ts +21 -0
  50. package/lib/api/interfaces/Handler.js +2 -0
  51. package/lib/api/shared.d.ts +7 -0
  52. package/lib/api/shared.js +27 -0
  53. package/lib/api/utils/constants.d.ts +39 -0
  54. package/lib/api/utils/constants.js +50 -0
  55. package/lib/api/utils/types.d.ts +335 -0
  56. package/lib/api/utils/types.js +14 -0
  57. package/lib/api/utils/utils.d.ts +52 -0
  58. package/lib/api/utils/utils.js +159 -0
  59. package/lib/builders/ActionRow.d.ts +40 -0
  60. package/lib/builders/ActionRow.js +58 -0
  61. package/lib/builders/Attachment.d.ts +106 -0
  62. package/lib/builders/Attachment.js +196 -0
  63. package/lib/builders/Base.d.ts +10 -0
  64. package/lib/builders/Base.js +13 -0
  65. package/lib/builders/Button.d.ts +59 -0
  66. package/lib/builders/Button.js +94 -0
  67. package/lib/builders/MessageEmbed.d.ts +116 -0
  68. package/lib/builders/MessageEmbed.js +159 -0
  69. package/lib/builders/Modal.d.ts +111 -0
  70. package/lib/builders/Modal.js +162 -0
  71. package/lib/builders/SelectMenu.d.ts +201 -0
  72. package/lib/builders/SelectMenu.js +293 -0
  73. package/lib/builders/index.d.ts +12 -0
  74. package/lib/builders/index.js +54 -0
  75. package/lib/builders/types.d.ts +21 -0
  76. package/lib/builders/types.js +2 -0
  77. package/lib/cache/adapters/default.d.ts +24 -0
  78. package/lib/cache/adapters/default.js +118 -0
  79. package/lib/cache/adapters/index.d.ts +4 -0
  80. package/lib/cache/adapters/index.js +20 -0
  81. package/lib/cache/adapters/redis.d.ts +35 -0
  82. package/lib/cache/adapters/redis.js +180 -0
  83. package/lib/cache/adapters/types.d.ts +25 -0
  84. package/lib/cache/adapters/types.js +2 -0
  85. package/lib/cache/adapters/workeradapter.d.ts +24 -0
  86. package/lib/cache/adapters/workeradapter.js +76 -0
  87. package/lib/cache/index.d.ts +97 -0
  88. package/lib/cache/index.js +394 -0
  89. package/lib/cache/resources/channels.d.ts +7 -0
  90. package/lib/cache/resources/channels.js +20 -0
  91. package/lib/cache/resources/default/base.d.ts +25 -0
  92. package/lib/cache/resources/default/base.js +75 -0
  93. package/lib/cache/resources/default/guild-based.d.ts +33 -0
  94. package/lib/cache/resources/default/guild-based.js +91 -0
  95. package/lib/cache/resources/default/guild-related.d.ts +32 -0
  96. package/lib/cache/resources/default/guild-related.js +102 -0
  97. package/lib/cache/resources/emojis.d.ts +7 -0
  98. package/lib/cache/resources/emojis.js +17 -0
  99. package/lib/cache/resources/guilds.d.ts +10 -0
  100. package/lib/cache/resources/guilds.js +117 -0
  101. package/lib/cache/resources/members.d.ts +10 -0
  102. package/lib/cache/resources/members.js +41 -0
  103. package/lib/cache/resources/presence.d.ts +9 -0
  104. package/lib/cache/resources/presence.js +14 -0
  105. package/lib/cache/resources/roles.d.ts +7 -0
  106. package/lib/cache/resources/roles.js +17 -0
  107. package/lib/cache/resources/stage-instances.d.ts +5 -0
  108. package/lib/cache/resources/stage-instances.js +8 -0
  109. package/lib/cache/resources/stickers.d.ts +7 -0
  110. package/lib/cache/resources/stickers.js +17 -0
  111. package/lib/cache/resources/threads.d.ts +7 -0
  112. package/lib/cache/resources/threads.js +17 -0
  113. package/lib/cache/resources/users.d.ts +7 -0
  114. package/lib/cache/resources/users.js +17 -0
  115. package/lib/cache/resources/voice-states.d.ts +9 -0
  116. package/lib/cache/resources/voice-states.js +13 -0
  117. package/lib/client/base.d.ts +244 -0
  118. package/lib/client/base.js +178 -0
  119. package/lib/client/client.d.ts +32 -0
  120. package/lib/client/client.js +156 -0
  121. package/lib/client/httpclient.d.ts +21 -0
  122. package/lib/client/httpclient.js +143 -0
  123. package/lib/client/index.d.ts +4 -0
  124. package/lib/client/index.js +19 -0
  125. package/lib/client/oninteraction.d.ts +4 -0
  126. package/lib/client/oninteraction.js +180 -0
  127. package/lib/client/workerclient.d.ts +28 -0
  128. package/lib/client/workerclient.js +213 -0
  129. package/lib/collection.d.ts +233 -0
  130. package/lib/collection.js +371 -0
  131. package/lib/commands/applications/chat.d.ts +139 -0
  132. package/lib/commands/applications/chat.js +173 -0
  133. package/lib/commands/applications/chatcontext.d.ts +28 -0
  134. package/lib/commands/applications/chatcontext.js +53 -0
  135. package/lib/commands/applications/menu.d.ts +39 -0
  136. package/lib/commands/applications/menu.js +87 -0
  137. package/lib/commands/applications/menucontext.d.ts +25 -0
  138. package/lib/commands/applications/menucontext.js +64 -0
  139. package/lib/commands/applications/options.d.ts +67 -0
  140. package/lib/commands/applications/options.js +44 -0
  141. package/lib/commands/applications/shared.d.ts +35 -0
  142. package/lib/commands/applications/shared.js +2 -0
  143. package/lib/commands/decorators.d.ts +107 -0
  144. package/lib/commands/decorators.js +85 -0
  145. package/lib/commands/handler.d.ts +15 -0
  146. package/lib/commands/handler.js +140 -0
  147. package/lib/commands/index.d.ts +8 -0
  148. package/lib/commands/index.js +24 -0
  149. package/lib/commands/optionresolver.d.ts +49 -0
  150. package/lib/commands/optionresolver.js +146 -0
  151. package/lib/common/bot/watcher.d.ts +53 -0
  152. package/lib/common/bot/watcher.js +104 -0
  153. package/lib/common/index.d.ts +13 -0
  154. package/lib/common/index.js +30 -0
  155. package/lib/common/it/colors.d.ts +274 -0
  156. package/lib/common/it/colors.js +453 -0
  157. package/lib/common/it/constants.d.ts +36 -0
  158. package/lib/common/it/constants.js +40 -0
  159. package/lib/common/it/logger.d.ts +114 -0
  160. package/lib/common/it/logger.js +189 -0
  161. package/lib/common/it/utils.d.ts +107 -0
  162. package/lib/common/it/utils.js +275 -0
  163. package/lib/common/shorters/base.d.ts +5 -0
  164. package/lib/common/shorters/base.js +10 -0
  165. package/lib/common/shorters/channels.d.ts +90 -0
  166. package/lib/common/shorters/channels.js +95 -0
  167. package/lib/common/shorters/guilds.d.ts +389 -0
  168. package/lib/common/shorters/guilds.js +350 -0
  169. package/lib/common/shorters/members.d.ts +115 -0
  170. package/lib/common/shorters/members.js +179 -0
  171. package/lib/common/shorters/messages.d.ts +27 -0
  172. package/lib/common/shorters/messages.js +117 -0
  173. package/lib/common/shorters/roles.d.ts +12 -0
  174. package/lib/common/shorters/roles.js +51 -0
  175. package/lib/common/shorters/templates.d.ts +12 -0
  176. package/lib/common/shorters/templates.js +29 -0
  177. package/lib/common/shorters/users.d.ts +11 -0
  178. package/lib/common/shorters/users.js +42 -0
  179. package/lib/common/shorters/webhook.d.ts +33 -0
  180. package/lib/common/shorters/webhook.js +69 -0
  181. package/lib/common/types/options.d.ts +10 -0
  182. package/lib/common/types/options.js +2 -0
  183. package/lib/common/types/resolvables.d.ts +10 -0
  184. package/lib/common/types/resolvables.js +2 -0
  185. package/lib/common/types/util.d.ts +90 -0
  186. package/lib/common/types/util.js +2 -0
  187. package/lib/common/types/write.d.ts +21 -0
  188. package/lib/common/types/write.js +2 -0
  189. package/lib/components/ActionRow.d.ts +10 -0
  190. package/lib/components/ActionRow.js +13 -0
  191. package/lib/components/ButtonComponent.d.ts +19 -0
  192. package/lib/components/ButtonComponent.js +34 -0
  193. package/lib/components/ChannelSelectMenuComponent.d.ts +6 -0
  194. package/lib/components/ChannelSelectMenuComponent.js +12 -0
  195. package/lib/components/MentionableSelectMenuComponent.d.ts +4 -0
  196. package/lib/components/MentionableSelectMenuComponent.js +7 -0
  197. package/lib/components/RoleSelectMenuComponent.d.ts +4 -0
  198. package/lib/components/RoleSelectMenuComponent.js +7 -0
  199. package/lib/components/StringSelectMenuComponent.d.ts +6 -0
  200. package/lib/components/StringSelectMenuComponent.js +12 -0
  201. package/lib/components/TextInputComponent.d.ts +7 -0
  202. package/lib/components/TextInputComponent.js +14 -0
  203. package/lib/components/UserSelectMenuComponent.d.ts +4 -0
  204. package/lib/components/UserSelectMenuComponent.js +7 -0
  205. package/lib/components/command.d.ts +23 -0
  206. package/lib/components/command.js +15 -0
  207. package/lib/components/handler.d.ts +48 -0
  208. package/lib/components/handler.js +231 -0
  209. package/lib/components/index.d.ts +20 -0
  210. package/lib/components/index.js +55 -0
  211. package/lib/components/listener.d.ts +11 -0
  212. package/lib/components/listener.js +18 -0
  213. package/lib/events/event.d.ts +23 -0
  214. package/lib/events/event.js +2 -0
  215. package/lib/events/handler.d.ts +19 -0
  216. package/lib/events/handler.js +112 -0
  217. package/lib/events/hooks/application_command.d.ts +12 -0
  218. package/lib/events/hooks/application_command.js +8 -0
  219. package/lib/events/hooks/auto_moderation.d.ts +22 -0
  220. package/lib/events/hooks/auto_moderation.js +21 -0
  221. package/lib/events/hooks/channel.d.ts +11 -0
  222. package/lib/events/hooks/channel.js +24 -0
  223. package/lib/events/hooks/custom.d.ts +4 -0
  224. package/lib/events/hooks/custom.js +11 -0
  225. package/lib/events/hooks/dispatch.d.ts +5 -0
  226. package/lib/events/hooks/dispatch.js +12 -0
  227. package/lib/events/hooks/entitlement.d.ts +35 -0
  228. package/lib/events/hooks/entitlement.js +16 -0
  229. package/lib/events/hooks/guild.d.ts +228 -0
  230. package/lib/events/hooks/guild.js +101 -0
  231. package/lib/events/hooks/index.d.ts +23 -0
  232. package/lib/events/hooks/index.js +34 -0
  233. package/lib/events/hooks/integration.d.ts +94 -0
  234. package/lib/events/hooks/integration.js +27 -0
  235. package/lib/events/hooks/interactions.d.ts +4 -0
  236. package/lib/events/hooks/interactions.js +8 -0
  237. package/lib/events/hooks/invite.d.ts +21 -0
  238. package/lib/events/hooks/invite.js +12 -0
  239. package/lib/events/hooks/message.d.ts +69 -0
  240. package/lib/events/hooks/message.js +37 -0
  241. package/lib/events/hooks/presence.d.ts +27 -0
  242. package/lib/events/hooks/presence.js +8 -0
  243. package/lib/events/hooks/stage.d.ts +29 -0
  244. package/lib/events/hooks/stage.js +16 -0
  245. package/lib/events/hooks/thread.d.ts +198 -0
  246. package/lib/events/hooks/thread.js +29 -0
  247. package/lib/events/hooks/typing.d.ts +16 -0
  248. package/lib/events/hooks/typing.js +14 -0
  249. package/lib/events/hooks/user.d.ts +4 -0
  250. package/lib/events/hooks/user.js +8 -0
  251. package/lib/events/hooks/voice.d.ts +37 -0
  252. package/lib/events/hooks/voice.js +18 -0
  253. package/lib/events/hooks/webhook.d.ts +6 -0
  254. package/lib/events/hooks/webhook.js +8 -0
  255. package/lib/events/index.d.ts +2 -0
  256. package/lib/events/index.js +18 -0
  257. package/lib/index.d.ts +79 -0
  258. package/lib/index.js +104 -0
  259. package/lib/langs/handler.d.ts +11 -0
  260. package/lib/langs/handler.js +34 -0
  261. package/lib/langs/index.d.ts +2 -0
  262. package/lib/langs/index.js +18 -0
  263. package/lib/langs/router.d.ts +18 -0
  264. package/lib/langs/router.js +42 -0
  265. package/lib/structures/AnonymousGuild.d.ts +7 -0
  266. package/lib/structures/AnonymousGuild.js +11 -0
  267. package/lib/structures/AutoModerationRule.d.ts +22 -0
  268. package/lib/structures/AutoModerationRule.js +34 -0
  269. package/lib/structures/ClientUser.d.ts +25 -0
  270. package/lib/structures/ClientUser.js +52 -0
  271. package/lib/structures/Guild.d.ts +86 -0
  272. package/lib/structures/Guild.js +66 -0
  273. package/lib/structures/GuildEmoji.d.ts +29 -0
  274. package/lib/structures/GuildEmoji.js +47 -0
  275. package/lib/structures/GuildMember.d.ts +92 -0
  276. package/lib/structures/GuildMember.js +137 -0
  277. package/lib/structures/GuildPreview.d.ts +10 -0
  278. package/lib/structures/GuildPreview.js +14 -0
  279. package/lib/structures/GuildRole.d.ts +21 -0
  280. package/lib/structures/GuildRole.js +32 -0
  281. package/lib/structures/GuildTemplate.d.ts +23 -0
  282. package/lib/structures/GuildTemplate.js +36 -0
  283. package/lib/structures/Interaction.d.ts +152 -0
  284. package/lib/structures/Interaction.js +409 -0
  285. package/lib/structures/Message.d.ts +53 -0
  286. package/lib/structures/Message.js +123 -0
  287. package/lib/structures/Sticker.d.ts +27 -0
  288. package/lib/structures/Sticker.js +44 -0
  289. package/lib/structures/User.d.ts +20 -0
  290. package/lib/structures/User.js +37 -0
  291. package/lib/structures/Webhook.d.ts +42 -0
  292. package/lib/structures/Webhook.js +63 -0
  293. package/lib/structures/channels.d.ts +232 -0
  294. package/lib/structures/channels.js +366 -0
  295. package/lib/structures/extra/Base.d.ts +7 -0
  296. package/lib/structures/extra/Base.js +39 -0
  297. package/lib/structures/extra/BaseComponent.d.ts +9 -0
  298. package/lib/structures/extra/BaseComponent.js +12 -0
  299. package/lib/structures/extra/BaseGuild.d.ts +40 -0
  300. package/lib/structures/extra/BaseGuild.js +71 -0
  301. package/lib/structures/extra/BaseSelectMenuComponent.d.ts +9 -0
  302. package/lib/structures/extra/BaseSelectMenuComponent.js +13 -0
  303. package/lib/structures/extra/BitField.d.ts +14 -0
  304. package/lib/structures/extra/BitField.js +56 -0
  305. package/lib/structures/extra/DiscordBase.d.ts +18 -0
  306. package/lib/structures/extra/DiscordBase.js +28 -0
  307. package/lib/structures/extra/Permissions.d.ts +54 -0
  308. package/lib/structures/extra/Permissions.js +9 -0
  309. package/lib/structures/extra/functions.d.ts +11 -0
  310. package/lib/structures/extra/functions.js +69 -0
  311. package/lib/structures/index.d.ts +15 -0
  312. package/lib/structures/index.js +31 -0
  313. package/lib/websocket/SharedTypes.d.ts +128 -0
  314. package/lib/websocket/SharedTypes.js +2 -0
  315. package/lib/websocket/constants/index.d.ts +26 -0
  316. package/lib/websocket/constants/index.js +31 -0
  317. package/lib/websocket/discord/basesocket.d.ts +12 -0
  318. package/lib/websocket/discord/basesocket.js +37 -0
  319. package/lib/websocket/discord/events/memberUpdate.d.ts +16 -0
  320. package/lib/websocket/discord/events/memberUpdate.js +47 -0
  321. package/lib/websocket/discord/events/presenceUpdate.d.ts +24 -0
  322. package/lib/websocket/discord/events/presenceUpdate.js +46 -0
  323. package/lib/websocket/discord/handlemessage.d.ts +0 -0
  324. package/lib/websocket/discord/handlemessage.js +1 -0
  325. package/lib/websocket/discord/index.d.ts +4 -0
  326. package/lib/websocket/discord/index.js +20 -0
  327. package/lib/websocket/discord/memberUpdate.d.ts +16 -0
  328. package/lib/websocket/discord/memberUpdate.js +47 -0
  329. package/lib/websocket/discord/shard.d.ts +46 -0
  330. package/lib/websocket/discord/shard.js +278 -0
  331. package/lib/websocket/discord/sharder.d.ts +25 -0
  332. package/lib/websocket/discord/sharder.js +153 -0
  333. package/lib/websocket/discord/shared.d.ts +99 -0
  334. package/lib/websocket/discord/shared.js +8 -0
  335. package/lib/websocket/discord/worker.d.ts +43 -0
  336. package/lib/websocket/discord/worker.js +2 -0
  337. package/lib/websocket/discord/workermanager.d.ts +69 -0
  338. package/lib/websocket/discord/workermanager.js +273 -0
  339. package/lib/websocket/index.d.ts +3 -0
  340. package/lib/websocket/index.js +19 -0
  341. package/lib/websocket/structures/index.d.ts +117 -0
  342. package/lib/websocket/structures/index.js +261 -0
  343. package/lib/websocket/structures/timeout.d.ts +20 -0
  344. package/lib/websocket/structures/timeout.js +75 -0
  345. package/package.json +70 -0
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEPRECATION_WARNING_PREFIX = exports.BurstHandlerMajorIdKey = exports.OverwrittenMimeTypes = exports.ALLOWED_SIZES = exports.ALLOWED_STICKER_EXTENSIONS = exports.ALLOWED_EXTENSIONS = exports.RESTEvents = exports.DefaultRestOptions = exports.DefaultUserAgent = void 0;
4
+ const common_1 = require("../../common");
5
+ exports.DefaultUserAgent = 'DiscordBot (https://seyfert.com)';
6
+ exports.DefaultRestOptions = {
7
+ agent: null,
8
+ api: common_1.BASE_URL,
9
+ authPrefix: 'Bot',
10
+ headers: {},
11
+ invalidRequestWarningInterval: 0,
12
+ globalRequestsPerSecond: 50,
13
+ offset: 50,
14
+ rejectOnRateLimit: null,
15
+ retries: 3,
16
+ timeout: 15_000,
17
+ version: common_1.APIVersion,
18
+ hashSweepInterval: 14_400_000, // 4 Hours
19
+ hashLifetime: 86_400_000, // 24 Hours
20
+ handlerSweepInterval: 3_600_000, // 1 Hour
21
+ makeRequest(url, init) {
22
+ return fetch(url, init);
23
+ },
24
+ };
25
+ /**
26
+ * The events that the REST manager emits
27
+ */
28
+ var RESTEvents;
29
+ (function (RESTEvents) {
30
+ RESTEvents["Debug"] = "restDebug";
31
+ RESTEvents["HandlerSweep"] = "handlerSweep";
32
+ RESTEvents["HashSweep"] = "hashSweep";
33
+ RESTEvents["InvalidRequestWarning"] = "invalidRequestWarning";
34
+ RESTEvents["RateLimited"] = "rateLimited";
35
+ RESTEvents["Response"] = "response";
36
+ })(RESTEvents || (exports.RESTEvents = RESTEvents = {}));
37
+ exports.ALLOWED_EXTENSIONS = ['webp', 'png', 'jpg', 'jpeg', 'gif'];
38
+ exports.ALLOWED_STICKER_EXTENSIONS = ['png', 'json', 'gif'];
39
+ exports.ALLOWED_SIZES = [16, 32, 64, 128, 256, 512, 1_024, 2_048, 4_096];
40
+ exports.OverwrittenMimeTypes = {
41
+ // https://github.com/discordjs/discord.js/issues/8557
42
+ 'image/apng': 'image/png',
43
+ };
44
+ exports.BurstHandlerMajorIdKey = 'burst';
45
+ /**
46
+ * Prefix for deprecation warnings.
47
+ *
48
+ * @internal
49
+ */
50
+ exports.DEPRECATION_WARNING_PREFIX = 'DeprecationWarning';
@@ -0,0 +1,335 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ import type { Readable } from 'node:stream';
5
+ import type { ReadableStream } from 'node:stream/web';
6
+ import type { Agent, BodyInit, Dispatcher, RequestInit, Response } from 'undici-types';
7
+ import type { Collection } from '../../collection';
8
+ import type { MakeRequired } from '../../common';
9
+ import type { IHandler } from '../interfaces/Handler';
10
+ export interface RestEvents {
11
+ handlerSweep: [sweptHandlers: Collection<string, IHandler>];
12
+ hashSweep: [sweptHashes: Collection<string, HashData>];
13
+ invalidRequestWarning: [invalidRequestInfo: InvalidRequestWarningData];
14
+ rateLimited: [rateLimitInfo: RateLimitData];
15
+ response: [request: APIRequest, response: ResponseLike];
16
+ restDebug: [info: string];
17
+ }
18
+ export interface RestEventsMap extends RestEvents {
19
+ }
20
+ /**
21
+ * Options to be passed when creating the REST instance
22
+ */
23
+ export interface RESTOptions {
24
+ /**
25
+ * The agent to set globally
26
+ */
27
+ agent: Dispatcher | null;
28
+ /**
29
+ * The base api path, without version
30
+ *
31
+ * @defaultValue `'https://discord.com/api'`
32
+ */
33
+ api: string;
34
+ /**
35
+ * The authorization prefix to use for requests, useful if you want to use
36
+ * bearer tokens
37
+ *
38
+ * @defaultValue `'Bot'`
39
+ */
40
+ authPrefix: 'Bearer' | 'Bot';
41
+ /**
42
+ * How many requests to allow sending per second (Infinity for unlimited, 50 for the standard global limit used by Discord)
43
+ *
44
+ * @defaultValue `50`
45
+ */
46
+ globalRequestsPerSecond: number;
47
+ /**
48
+ * The amount of time in milliseconds that passes between each hash sweep. (defaults to 1h)
49
+ *
50
+ * @defaultValue `3_600_000`
51
+ */
52
+ handlerSweepInterval: number;
53
+ /**
54
+ * The maximum amount of time a hash can exist in milliseconds without being hit with a request (defaults to 24h)
55
+ *
56
+ * @defaultValue `86_400_000`
57
+ */
58
+ hashLifetime: number;
59
+ /**
60
+ * The amount of time in milliseconds that passes between each hash sweep. (defaults to 4h)
61
+ *
62
+ * @defaultValue `14_400_000`
63
+ */
64
+ hashSweepInterval: number;
65
+ /**
66
+ * Additional headers to send for all API requests
67
+ *
68
+ * @defaultValue `{}`
69
+ */
70
+ headers: Record<string, string>;
71
+ /**
72
+ * The number of invalid REST requests (those that return 401, 403, or 429) in a 10 minute window between emitted warnings (0 for no warnings).
73
+ * That is, if set to 500, warnings will be emitted at invalid request number 500, 1000, 1500, and so on.
74
+ *
75
+ * @defaultValue `0`
76
+ */
77
+ invalidRequestWarningInterval: number;
78
+ /**
79
+ * The method called to perform the actual HTTP request given a url and web `fetch` options
80
+ * For example, to use global fetch, simply provide `makeRequest: fetch`
81
+ */
82
+ makeRequest(url: string, init: RequestInit): Promise<ResponseLike>;
83
+ /**
84
+ * The extra offset to add to rate limits in milliseconds
85
+ *
86
+ * @defaultValue `50`
87
+ */
88
+ offset: number;
89
+ /**
90
+ * Determines how rate limiting and pre-emptive throttling should be handled.
91
+ * When an array of strings, each element is treated as a prefix for the request route
92
+ * (e.g. `/channels` to match any route starting with `/channels` such as `/channels/:id/messages`)
93
+ * for which to throw {@link RateLimitError}s. All other request routes will be queued normally
94
+ *
95
+ * @defaultValue `null`
96
+ */
97
+ rejectOnRateLimit: RateLimitQueueFilter | string[] | null;
98
+ /**
99
+ * The number of retries for errors with the 500 code, or errors
100
+ * that timeout
101
+ *
102
+ * @defaultValue `3`
103
+ */
104
+ retries: number;
105
+ /**
106
+ * The time to wait in milliseconds before a request is aborted
107
+ *
108
+ * @defaultValue `15_000`
109
+ */
110
+ timeout: number;
111
+ /**
112
+ * Extra information to add to the user agent
113
+ *
114
+ * @defaultValue DefaultUserAgentAppendix
115
+ */
116
+ userAgentAppendix: string;
117
+ /**
118
+ * The version of the API to use
119
+ *
120
+ * @defaultValue `'10'`
121
+ */
122
+ version: string;
123
+ /**
124
+ * Token of app
125
+ */
126
+ token: string;
127
+ debug?: boolean;
128
+ }
129
+ export type RESTConstructorOptions = MakeRequired<Partial<RESTOptions>, 'token'>;
130
+ /**
131
+ * Data emitted on `RESTEvents.RateLimited`
132
+ */
133
+ export interface RateLimitData {
134
+ /**
135
+ * Whether the rate limit that was reached was the global limit
136
+ */
137
+ global: boolean;
138
+ /**
139
+ * The bucket hash for this request
140
+ */
141
+ hash: string;
142
+ /**
143
+ * The amount of requests we can perform before locking requests
144
+ */
145
+ limit: number;
146
+ /**
147
+ * The major parameter of the route
148
+ *
149
+ * For example, in `/channels/x`, this will be `x`.
150
+ * If there is no major parameter (e.g: `/bot/gateway`) this will be `global`.
151
+ */
152
+ majorParameter: string;
153
+ /**
154
+ * The HTTP method being performed
155
+ */
156
+ method: string;
157
+ /**
158
+ * The time, in milliseconds, that will need to pass before this specific request can be retried
159
+ */
160
+ retryAfter: number;
161
+ /**
162
+ * The route being hit in this request
163
+ */
164
+ route: string;
165
+ /**
166
+ * The scope of the rate limit that was hit.
167
+ *
168
+ * This can be `user` for rate limits that are per client, `global` for rate limits that affect all clients or `shared` for rate limits that
169
+ * are shared per resource.
170
+ */
171
+ scope: 'global' | 'shared' | 'user';
172
+ /**
173
+ * The time, in milliseconds, that will need to pass before the sublimit lock for the route resets, and requests that fall under a sublimit
174
+ * can be retried
175
+ *
176
+ * This is only present on certain sublimits, and `0` otherwise
177
+ */
178
+ sublimitTimeout: number;
179
+ /**
180
+ * The time, in milliseconds, until the route's request-lock is reset
181
+ */
182
+ timeToReset: number;
183
+ /**
184
+ * The full URL for this request
185
+ */
186
+ url: string;
187
+ }
188
+ export type Awaitable<Value> = PromiseLike<Value> | Value;
189
+ /**
190
+ * A function that determines whether the rate limit hit should throw an Error
191
+ */
192
+ export type RateLimitQueueFilter = (rateLimitData: RateLimitData) => Awaitable<boolean>;
193
+ export interface APIRequest {
194
+ /**
195
+ * The data that was used to form the body of this request
196
+ */
197
+ data: HandlerRequestData;
198
+ /**
199
+ * The HTTP method used in this request
200
+ */
201
+ method: string;
202
+ /**
203
+ * Additional HTTP options for this request
204
+ */
205
+ options: RequestInit;
206
+ /**
207
+ * The full path used to make the request
208
+ */
209
+ path: RouteLike;
210
+ /**
211
+ * The number of times this request has been attempted
212
+ */
213
+ retries: number;
214
+ /**
215
+ * The API route identifying the ratelimit for this request
216
+ */
217
+ route: string;
218
+ }
219
+ export interface ResponseLike extends Pick<Response, 'arrayBuffer' | 'bodyUsed' | 'headers' | 'json' | 'ok' | 'status' | 'statusText' | 'text'> {
220
+ body: Readable | ReadableStream | null;
221
+ }
222
+ export interface InvalidRequestWarningData {
223
+ /**
224
+ * Number of invalid requests that have been made in the window
225
+ */
226
+ count: number;
227
+ /**
228
+ * Time in milliseconds remaining before the count resets
229
+ */
230
+ remainingTime: number;
231
+ }
232
+ /**
233
+ * Represents a file to be added to the request
234
+ */
235
+ export interface RawFile {
236
+ /**
237
+ * Content-Type of the file
238
+ */
239
+ contentType?: string;
240
+ /**
241
+ * The actual data for the file
242
+ */
243
+ data: Buffer | Uint8Array | boolean | number | string;
244
+ /**
245
+ * An explicit key to use for key of the formdata field for this file.
246
+ * When not provided, the index of the file in the files array is used in the form `files[${index}]`.
247
+ * If you wish to alter the placeholder snowflake, you must provide this property in the same form (`files[${placeholder}]`)
248
+ */
249
+ key?: string;
250
+ /**
251
+ * The name of the file
252
+ */
253
+ name: string;
254
+ }
255
+ /**
256
+ * Represents possible data to be given to an endpoint
257
+ */
258
+ export interface RequestData {
259
+ /**
260
+ * Whether to append JSON data to form data instead of `payload_json` when sending files
261
+ */
262
+ appendToFormData?: boolean;
263
+ /**
264
+ * If this request needs the `Authorization` header
265
+ *
266
+ * @defaultValue `true`
267
+ */
268
+ auth?: boolean;
269
+ /**
270
+ * The authorization prefix to use for this request, useful if you use this with bearer tokens
271
+ *
272
+ * @defaultValue `'Bot'`
273
+ */
274
+ authPrefix?: 'Bearer' | 'Bot';
275
+ /**
276
+ * The body to send to this request.
277
+ * If providing as BodyInit, set `passThroughBody: true`
278
+ */
279
+ body?: BodyInit | unknown;
280
+ /**
281
+ * The {@link https://undici.nodejs.org/#/docs/api/Agent | Agent} to use for the request.
282
+ */
283
+ dispatcher?: Agent;
284
+ /**
285
+ * Files to be attached to this request
286
+ */
287
+ files?: RawFile[] | undefined;
288
+ /**
289
+ * Additional headers to add to this request
290
+ */
291
+ headers?: Record<string, string>;
292
+ /**
293
+ * Whether to pass-through the body property directly to `fetch()`.
294
+ * <warn>This only applies when files is NOT present</warn>
295
+ */
296
+ passThroughBody?: boolean;
297
+ /**
298
+ * Query string parameters to append to the called endpoint
299
+ */
300
+ query?: URLSearchParams;
301
+ /**
302
+ * Reason to show in the audit logs
303
+ */
304
+ reason?: string | undefined;
305
+ /**
306
+ * The signal to abort the queue entry or the REST call, where applicable
307
+ */
308
+ signal?: AbortSignal | undefined;
309
+ /**
310
+ * If this request should be versioned
311
+ *
312
+ * @defaultValue `true`
313
+ */
314
+ versioned?: boolean;
315
+ }
316
+ /**
317
+ * Possible headers for an API call
318
+ */
319
+ export interface RequestHeaders {
320
+ Authorization?: string;
321
+ 'User-Agent': string;
322
+ 'X-Audit-Log-Reason'?: string;
323
+ }
324
+ /**
325
+ * Possible API methods to be used when doing requests
326
+ */
327
+ export declare enum RequestMethod {
328
+ Delete = "DELETE",
329
+ Get = "GET",
330
+ Patch = "PATCH",
331
+ Post = "POST",
332
+ Put = "PUT"
333
+ }
334
+ export type RouteLike = `/${string}`;
335
+ export type HandlerRequestData = Pick<InternalRequest, 'auth' | 'body' | 'files' | 'signal'>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RequestMethod = void 0;
4
+ /**
5
+ * Possible API methods to be used when doing requests
6
+ */
7
+ var RequestMethod;
8
+ (function (RequestMethod) {
9
+ RequestMethod["Delete"] = "DELETE";
10
+ RequestMethod["Get"] = "GET";
11
+ RequestMethod["Patch"] = "PATCH";
12
+ RequestMethod["Post"] = "POST";
13
+ RequestMethod["Put"] = "PUT";
14
+ })(RequestMethod || (exports.RequestMethod = RequestMethod = {}));
@@ -0,0 +1,52 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import type { Snowflake } from 'discord-api-types/v10';
4
+ import { type ResponseLike } from './types.js';
5
+ /**
6
+ * Creates and populates an URLSearchParams instance from an object, stripping
7
+ * out null and undefined values, while also coercing non-strings to strings.
8
+ *
9
+ * @param options - The options to use
10
+ * @returns A populated URLSearchParams instance
11
+ */
12
+ export declare function makeURLSearchParams<OptionsType extends object>(options?: Readonly<OptionsType>): URLSearchParams;
13
+ /**
14
+ * Converts the response to usable data
15
+ *
16
+ * @param res - The fetch response
17
+ */
18
+ export declare function parseResponse(res: ResponseLike): Promise<unknown>;
19
+ /**
20
+ * Check whether a request falls under a sublimit
21
+ *
22
+ * @param bucketRoute - The buckets route identifier
23
+ * @param body - The options provided as JSON data
24
+ * @param method - The HTTP method that will be used to make the request
25
+ * @returns Whether the request falls under a sublimit
26
+ */
27
+ export declare function hasSublimit(bucketRoute: string, body?: unknown, method?: string): boolean;
28
+ /**
29
+ * Check whether an error indicates that a retry can be attempted
30
+ *
31
+ * @param error - The error thrown by the network request
32
+ * @returns Whether the error indicates a retry should be attempted
33
+ */
34
+ export declare function shouldRetry(error: Error | NodeJS.ErrnoException): boolean;
35
+ /**
36
+ * Calculates the default avatar index for a given user id.
37
+ *
38
+ * @param userId - The user id to calculate the default avatar index for
39
+ */
40
+ export declare function calculateUserDefaultAvatarIndex(userId: Snowflake): number;
41
+ /**
42
+ * Sleeps for a given amount of time.
43
+ *
44
+ * @param ms - The amount of time (in milliseconds) to sleep for
45
+ */
46
+ export declare function sleep(ms: number): Promise<void>;
47
+ /**
48
+ * Verifies that a value is a buffer-like object.
49
+ *
50
+ * @param value - The value to check
51
+ */
52
+ export declare function isBufferLike(value: unknown): value is ArrayBuffer | Buffer | Uint8Array | Uint8ClampedArray;
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deprecationWarning = exports.isBufferLike = exports.sleep = exports.calculateUserDefaultAvatarIndex = exports.onRateLimit = exports.shouldRetry = exports.hasSublimit = exports.parseResponse = exports.makeURLSearchParams = void 0;
4
+ const RateLimitError_js_1 = require("../errors/RateLimitError.js");
5
+ const constants_js_1 = require("./constants.js");
6
+ const types_js_1 = require("./types.js");
7
+ function serializeSearchParam(value) {
8
+ switch (typeof value) {
9
+ case 'string':
10
+ return value;
11
+ case 'number':
12
+ case 'bigint':
13
+ case 'boolean':
14
+ return value.toString();
15
+ case 'object':
16
+ if (value === null)
17
+ return null;
18
+ if (value instanceof Date) {
19
+ return Number.isNaN(value.getTime()) ? null : value.toISOString();
20
+ }
21
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
22
+ if (typeof value.toString === 'function' && value.toString !== Object.prototype.toString)
23
+ return value.toString();
24
+ return null;
25
+ default:
26
+ return null;
27
+ }
28
+ }
29
+ /**
30
+ * Creates and populates an URLSearchParams instance from an object, stripping
31
+ * out null and undefined values, while also coercing non-strings to strings.
32
+ *
33
+ * @param options - The options to use
34
+ * @returns A populated URLSearchParams instance
35
+ */
36
+ function makeURLSearchParams(options) {
37
+ const params = new URLSearchParams();
38
+ if (!options)
39
+ return params;
40
+ for (const [key, value] of Object.entries(options)) {
41
+ const serialized = serializeSearchParam(value);
42
+ if (serialized !== null)
43
+ params.append(key, serialized);
44
+ }
45
+ return params;
46
+ }
47
+ exports.makeURLSearchParams = makeURLSearchParams;
48
+ /**
49
+ * Converts the response to usable data
50
+ *
51
+ * @param res - The fetch response
52
+ */
53
+ async function parseResponse(res) {
54
+ if (res.headers.get('Content-Type')?.startsWith('application/json')) {
55
+ return res.json();
56
+ }
57
+ return res.arrayBuffer();
58
+ }
59
+ exports.parseResponse = parseResponse;
60
+ /**
61
+ * Check whether a request falls under a sublimit
62
+ *
63
+ * @param bucketRoute - The buckets route identifier
64
+ * @param body - The options provided as JSON data
65
+ * @param method - The HTTP method that will be used to make the request
66
+ * @returns Whether the request falls under a sublimit
67
+ */
68
+ function hasSublimit(bucketRoute, body, method) {
69
+ // TODO: Update for new sublimits
70
+ // Currently known sublimits:
71
+ // Editing channel `name` or `topic`
72
+ if (bucketRoute === '/channels/:id') {
73
+ if (typeof body !== 'object' || body === null)
74
+ return false;
75
+ // This should never be a POST body, but just in case
76
+ if (method !== types_js_1.RequestMethod.Patch)
77
+ return false;
78
+ const castedBody = body;
79
+ return ['name', 'topic'].some(key => Reflect.has(castedBody, key));
80
+ }
81
+ // If we are checking if a request has a sublimit on a route not checked above, sublimit all requests to avoid a flood of 429s
82
+ return true;
83
+ }
84
+ exports.hasSublimit = hasSublimit;
85
+ /**
86
+ * Check whether an error indicates that a retry can be attempted
87
+ *
88
+ * @param error - The error thrown by the network request
89
+ * @returns Whether the error indicates a retry should be attempted
90
+ */
91
+ function shouldRetry(error) {
92
+ // Retry for possible timed out requests
93
+ if (error.name === 'AbortError')
94
+ return true;
95
+ // Downlevel ECONNRESET to retry as it may be recoverable
96
+ return ('code' in error && error.code === 'ECONNRESET') || error.message.includes('ECONNRESET');
97
+ }
98
+ exports.shouldRetry = shouldRetry;
99
+ /**
100
+ * Determines whether the request should be queued or whether a RateLimitError should be thrown
101
+ *
102
+ * @internal
103
+ */
104
+ async function onRateLimit(manager, rateLimitData) {
105
+ if (!manager.options.rejectOnRateLimit)
106
+ return;
107
+ const shouldThrow = typeof manager.options.rejectOnRateLimit === 'function'
108
+ ? await manager.options.rejectOnRateLimit(rateLimitData)
109
+ : manager.options.rejectOnRateLimit.some(route => rateLimitData.route.startsWith(route.toLowerCase()));
110
+ if (shouldThrow) {
111
+ throw new RateLimitError_js_1.RateLimitError(rateLimitData);
112
+ }
113
+ }
114
+ exports.onRateLimit = onRateLimit;
115
+ /**
116
+ * Calculates the default avatar index for a given user id.
117
+ *
118
+ * @param userId - The user id to calculate the default avatar index for
119
+ */
120
+ function calculateUserDefaultAvatarIndex(userId) {
121
+ return Number(BigInt(userId) >> 22n) % 6;
122
+ }
123
+ exports.calculateUserDefaultAvatarIndex = calculateUserDefaultAvatarIndex;
124
+ /**
125
+ * Sleeps for a given amount of time.
126
+ *
127
+ * @param ms - The amount of time (in milliseconds) to sleep for
128
+ */
129
+ async function sleep(ms) {
130
+ return new Promise(resolve => {
131
+ setTimeout(() => resolve(), ms);
132
+ });
133
+ }
134
+ exports.sleep = sleep;
135
+ /**
136
+ * Verifies that a value is a buffer-like object.
137
+ *
138
+ * @param value - The value to check
139
+ */
140
+ function isBufferLike(value) {
141
+ return value instanceof ArrayBuffer || value instanceof Uint8Array || value instanceof Uint8ClampedArray;
142
+ }
143
+ exports.isBufferLike = isBufferLike;
144
+ /**
145
+ * Irrespective environment warning.
146
+ *
147
+ * @remarks Only the message is needed. The deprecation prefix is handled already.
148
+ * @param message - A string the warning will emit with
149
+ * @internal
150
+ */
151
+ function deprecationWarning(message) {
152
+ if (typeof globalThis.process === 'undefined') {
153
+ console.warn(`${constants_js_1.DEPRECATION_WARNING_PREFIX}: ${message}`);
154
+ }
155
+ else {
156
+ process.emitWarning(message, constants_js_1.DEPRECATION_WARNING_PREFIX);
157
+ }
158
+ }
159
+ exports.deprecationWarning = deprecationWarning;
@@ -0,0 +1,40 @@
1
+ import { type APIActionRowComponent, type APIActionRowComponentTypes, type APIMessageActionRowComponent, type RestOrArray } from '../common';
2
+ import { BaseComponentBuilder } from './Base';
3
+ import type { BuilderComponents, FixedComponents } from './types';
4
+ /**
5
+ * Represents an Action Row component in a message.
6
+ * @template T - The type of components in the Action Row.
7
+ */
8
+ export declare class ActionRow<T extends BuilderComponents> extends BaseComponentBuilder<APIActionRowComponent<APIActionRowComponentTypes>> {
9
+ /**
10
+ * Creates a new instance of the ActionRow class.
11
+ * @param data - Optional data to initialize the Action Row.
12
+ * @example
13
+ * const actionRow = new ActionRow<Button>({ components: [buttonRawJSON] });
14
+ */
15
+ constructor({ components, ...data }?: Partial<APIActionRowComponent<APIActionRowComponentTypes>>);
16
+ components: FixedComponents<T>[];
17
+ /**
18
+ * Adds one or more components to the Action Row.
19
+ * @param component - The component(s) to add.
20
+ * @returns The updated Action Row instance.
21
+ * @example
22
+ * actionRow.addComponents(buttonComponent);
23
+ * actionRow.addComponents(buttonComponent1, buttonComponent2);
24
+ * actionRow.addComponents([buttonComponent1, buttonComponent2]);
25
+ */
26
+ addComponents(...component: RestOrArray<FixedComponents<T>>): this;
27
+ /**
28
+ * Sets the components of the Action Row.
29
+ * @param component - The components to set.
30
+ * @returns The updated Action Row instance.
31
+ * @example
32
+ * actionRow.setComponents([buttonComponent1, buttonComponent2]);
33
+ */
34
+ setComponents(component: FixedComponents<T>[]): this;
35
+ /**
36
+ * Converts the Action Row to its JSON representation.
37
+ * @returns The JSON representation of the Action Row.
38
+ */
39
+ toJSON(): APIActionRowComponent<APIMessageActionRowComponent>;
40
+ }