seyfert 0.1.0 → 1.0.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 (198) hide show
  1. package/README.md +19 -30
  2. package/lib/api/CDN.d.ts +0 -8
  3. package/lib/api/CDN.js +7 -13
  4. package/lib/api/Router.d.ts +2 -2
  5. package/lib/api/Router.js +1 -1
  6. package/lib/api/Routes/applications.d.ts +1 -1
  7. package/lib/api/Routes/channels.d.ts +1 -1
  8. package/lib/api/Routes/gateway.d.ts +1 -1
  9. package/lib/api/Routes/guilds.d.ts +1 -1
  10. package/lib/api/Routes/interactions.d.ts +1 -1
  11. package/lib/api/Routes/invites.d.ts +1 -1
  12. package/lib/api/Routes/stage-instances.d.ts +1 -1
  13. package/lib/api/Routes/stickers.d.ts +1 -1
  14. package/lib/api/Routes/users.d.ts +1 -1
  15. package/lib/api/Routes/voice.d.ts +1 -1
  16. package/lib/api/Routes/webhooks.d.ts +1 -1
  17. package/lib/api/api.d.ts +44 -0
  18. package/lib/api/api.js +354 -0
  19. package/lib/api/bucket.d.ts +19 -0
  20. package/lib/api/bucket.js +71 -0
  21. package/lib/api/index.d.ts +1 -1
  22. package/lib/api/index.js +1 -1
  23. package/lib/api/shared.d.ts +33 -5
  24. package/lib/api/shared.js +2 -7
  25. package/lib/api/utils/constants.d.ts +1 -30
  26. package/lib/api/utils/constants.js +2 -41
  27. package/lib/api/utils/types.d.ts +1 -320
  28. package/lib/api/utils/utils.d.ts +0 -38
  29. package/lib/api/utils/utils.js +1 -139
  30. package/lib/builders/ActionRow.js +1 -1
  31. package/lib/builders/Attachment.d.ts +14 -6
  32. package/lib/builders/Attachment.js +30 -7
  33. package/lib/builders/Button.d.ts +5 -14
  34. package/lib/builders/Button.js +0 -11
  35. package/lib/builders/{MessageEmbed.d.ts → Embed.d.ts} +15 -15
  36. package/lib/builders/{MessageEmbed.js → Embed.js} +16 -16
  37. package/lib/builders/Modal.js +1 -1
  38. package/lib/builders/SelectMenu.d.ts +14 -15
  39. package/lib/builders/SelectMenu.js +19 -18
  40. package/lib/builders/index.d.ts +1 -1
  41. package/lib/builders/index.js +1 -1
  42. package/lib/builders/types.d.ts +2 -2
  43. package/lib/cache/adapters/default.d.ts +1 -0
  44. package/lib/cache/adapters/default.js +3 -2
  45. package/lib/cache/adapters/redis.d.ts +3 -3
  46. package/lib/cache/adapters/redis.js +14 -5
  47. package/lib/cache/adapters/types.d.ts +1 -0
  48. package/lib/cache/adapters/workeradapter.d.ts +10 -1
  49. package/lib/cache/adapters/workeradapter.js +8 -3
  50. package/lib/cache/index.d.ts +18 -5
  51. package/lib/cache/index.js +23 -9
  52. package/lib/cache/resources/channels.d.ts +6 -2
  53. package/lib/cache/resources/channels.js +12 -6
  54. package/lib/cache/resources/default/base.d.ts +17 -16
  55. package/lib/cache/resources/default/base.js +25 -24
  56. package/lib/cache/resources/default/guild-based.d.ts +22 -19
  57. package/lib/cache/resources/default/guild-based.js +32 -31
  58. package/lib/cache/resources/default/guild-related.d.ts +22 -19
  59. package/lib/cache/resources/default/guild-related.js +37 -43
  60. package/lib/cache/resources/emojis.d.ts +4 -2
  61. package/lib/cache/resources/emojis.js +8 -6
  62. package/lib/cache/resources/guilds.d.ts +4 -2
  63. package/lib/cache/resources/guilds.js +15 -8
  64. package/lib/cache/resources/members.d.ts +4 -2
  65. package/lib/cache/resources/members.js +16 -13
  66. package/lib/cache/resources/overwrites.d.ts +25 -0
  67. package/lib/cache/resources/overwrites.js +39 -0
  68. package/lib/cache/resources/presence.js +3 -4
  69. package/lib/cache/resources/roles.d.ts +4 -2
  70. package/lib/cache/resources/roles.js +8 -6
  71. package/lib/cache/resources/stickers.d.ts +4 -2
  72. package/lib/cache/resources/stickers.js +8 -6
  73. package/lib/cache/resources/threads.d.ts +4 -2
  74. package/lib/cache/resources/threads.js +8 -6
  75. package/lib/cache/resources/users.d.ts +4 -2
  76. package/lib/cache/resources/users.js +8 -6
  77. package/lib/cache/resources/voice-states.d.ts +3 -3
  78. package/lib/cache/resources/voice-states.js +6 -7
  79. package/lib/client/base.d.ts +48 -16
  80. package/lib/client/base.js +19 -15
  81. package/lib/client/client.d.ts +15 -4
  82. package/lib/client/client.js +26 -28
  83. package/lib/client/httpclient.d.ts +3 -5
  84. package/lib/client/httpclient.js +29 -16
  85. package/lib/client/{oninteraction.d.ts → oninteractioncreate.d.ts} +1 -1
  86. package/lib/client/{oninteraction.js → oninteractioncreate.js} +34 -23
  87. package/lib/client/onmessagecreate.d.ts +3 -0
  88. package/lib/client/onmessagecreate.js +337 -0
  89. package/lib/client/workerclient.d.ts +19 -2
  90. package/lib/client/workerclient.js +156 -46
  91. package/lib/collection.d.ts +1 -1
  92. package/lib/collection.js +9 -6
  93. package/lib/commands/applications/chat.d.ts +32 -25
  94. package/lib/commands/applications/chat.js +51 -34
  95. package/lib/commands/applications/chatcontext.d.ts +34 -16
  96. package/lib/commands/applications/chatcontext.js +99 -20
  97. package/lib/commands/applications/menu.d.ts +9 -8
  98. package/lib/commands/applications/menu.js +14 -5
  99. package/lib/commands/applications/menucontext.d.ts +27 -10
  100. package/lib/commands/applications/menucontext.js +51 -7
  101. package/lib/commands/applications/options.d.ts +13 -13
  102. package/lib/commands/applications/shared.d.ts +7 -2
  103. package/lib/commands/decorators.d.ts +14 -14
  104. package/lib/commands/decorators.js +9 -5
  105. package/lib/commands/handler.d.ts +2 -1
  106. package/lib/commands/handler.js +60 -14
  107. package/lib/commands/index.d.ts +1 -1
  108. package/lib/commands/index.js +2 -1
  109. package/lib/commands/optionresolver.d.ts +6 -5
  110. package/lib/commands/optionresolver.js +10 -6
  111. package/lib/common/bot/watcher.d.ts +3 -3
  112. package/lib/common/bot/watcher.js +3 -1
  113. package/lib/common/index.d.ts +1 -1
  114. package/lib/common/index.js +2 -1
  115. package/lib/common/it/logger.d.ts +11 -0
  116. package/lib/common/it/logger.js +51 -2
  117. package/lib/common/it/utils.d.ts +3 -13
  118. package/lib/common/it/utils.js +9 -30
  119. package/lib/common/shorters/channels.d.ts +55 -5
  120. package/lib/common/shorters/channels.js +59 -0
  121. package/lib/common/shorters/guilds.d.ts +5 -2
  122. package/lib/common/shorters/guilds.js +18 -0
  123. package/lib/common/shorters/messages.js +0 -2
  124. package/lib/common/shorters/overwrites.d.ts +29 -0
  125. package/lib/common/shorters/overwrites.js +63 -0
  126. package/lib/common/shorters/roles.js +3 -3
  127. package/lib/common/shorters/webhook.d.ts +2 -2
  128. package/lib/common/types/util.d.ts +3 -2
  129. package/lib/common/types/write.d.ts +3 -7
  130. package/lib/components/handler.d.ts +11 -17
  131. package/lib/components/handler.js +45 -93
  132. package/lib/components/index.d.ts +0 -1
  133. package/lib/components/index.js +0 -1
  134. package/lib/components/listener.d.ts +2 -2
  135. package/lib/components/listener.js +2 -3
  136. package/lib/events/event.d.ts +2 -2
  137. package/lib/events/handler.d.ts +3 -2
  138. package/lib/events/handler.js +14 -6
  139. package/lib/events/hooks/dispatch.d.ts +2 -1
  140. package/lib/events/hooks/dispatch.js +5 -1
  141. package/lib/events/hooks/thread.d.ts +63 -63
  142. package/lib/index.d.ts +8 -5
  143. package/lib/index.js +20 -10
  144. package/lib/langs/handler.d.ts +6 -4
  145. package/lib/langs/handler.js +10 -8
  146. package/lib/langs/router.d.ts +8 -9
  147. package/lib/langs/router.js +5 -5
  148. package/lib/structures/ClientUser.d.ts +1 -16
  149. package/lib/structures/ClientUser.js +0 -31
  150. package/lib/structures/Guild.d.ts +1 -1
  151. package/lib/structures/GuildMember.d.ts +12 -0
  152. package/lib/structures/GuildMember.js +14 -0
  153. package/lib/structures/GuildRole.d.ts +4 -2
  154. package/lib/structures/GuildRole.js +4 -1
  155. package/lib/structures/GuildTemplate.js +1 -1
  156. package/lib/structures/Interaction.d.ts +2 -0
  157. package/lib/structures/Interaction.js +12 -13
  158. package/lib/structures/Message.d.ts +7 -2
  159. package/lib/structures/Message.js +6 -3
  160. package/lib/structures/Sticker.d.ts +1 -1
  161. package/lib/structures/Sticker.js +1 -1
  162. package/lib/structures/User.d.ts +5 -0
  163. package/lib/structures/User.js +3 -0
  164. package/lib/structures/Webhook.d.ts +1 -1
  165. package/lib/structures/Webhook.js +1 -1
  166. package/lib/structures/channels.d.ts +45 -6
  167. package/lib/structures/channels.js +23 -7
  168. package/lib/structures/extra/BitField.d.ts +9 -6
  169. package/lib/structures/extra/BitField.js +27 -3
  170. package/lib/structures/extra/Permissions.d.ts +6 -1
  171. package/lib/structures/extra/Permissions.js +7 -0
  172. package/lib/websocket/constants/index.js +1 -3
  173. package/lib/websocket/discord/basesocket.js +0 -1
  174. package/lib/websocket/discord/shared.d.ts +2 -0
  175. package/lib/websocket/discord/worker.d.ts +23 -7
  176. package/lib/websocket/discord/workermanager.d.ts +32 -5
  177. package/lib/websocket/discord/workermanager.js +98 -29
  178. package/package.json +23 -21
  179. package/lib/api/REST.d.ts +0 -127
  180. package/lib/api/REST.js +0 -424
  181. package/lib/api/errors/DiscordAPIError.d.ts +0 -51
  182. package/lib/api/errors/DiscordAPIError.js +0 -81
  183. package/lib/api/errors/HTTPError.d.ts +0 -20
  184. package/lib/api/errors/HTTPError.js +0 -28
  185. package/lib/api/errors/RateLimitError.d.ts +0 -19
  186. package/lib/api/errors/RateLimitError.js +0 -37
  187. package/lib/api/handlers/BurstHandler.d.ts +0 -51
  188. package/lib/api/handlers/BurstHandler.js +0 -124
  189. package/lib/api/handlers/SequentialHandler.d.ts +0 -81
  190. package/lib/api/handlers/SequentialHandler.js +0 -365
  191. package/lib/api/handlers/Shared.d.ts +0 -14
  192. package/lib/api/handlers/Shared.js +0 -125
  193. package/lib/api/interfaces/Handler.d.ts +0 -21
  194. package/lib/api/interfaces/Handler.js +0 -2
  195. package/lib/websocket/discord/handlemessage.d.ts +0 -0
  196. package/lib/websocket/discord/handlemessage.js +0 -1
  197. package/lib/websocket/discord/memberUpdate.d.ts +0 -16
  198. package/lib/websocket/discord/memberUpdate.js +0 -47
@@ -0,0 +1,19 @@
1
+ /// <reference types="node" />
2
+ export declare class Bucket {
3
+ limit: number;
4
+ remaining: number;
5
+ reset: number;
6
+ resetAfter: number;
7
+ queue: {
8
+ next: (cb: () => void, resolve: (data: any) => void, reject: (err: unknown) => void) => any;
9
+ resolve: (data: any) => void;
10
+ reject: (err: unknown) => void;
11
+ }[];
12
+ processing?: NodeJS.Timeout | boolean;
13
+ processingResetAfter?: NodeJS.Timeout | boolean;
14
+ last?: number;
15
+ constructor(limit: number);
16
+ process(override?: boolean): void;
17
+ push(func: this['queue'][number], unshift?: boolean): void;
18
+ triggerResetAfter(): void;
19
+ }
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Bucket = void 0;
4
+ class Bucket {
5
+ limit;
6
+ remaining;
7
+ reset = 0;
8
+ resetAfter = 0;
9
+ queue = [];
10
+ processing;
11
+ processingResetAfter;
12
+ last;
13
+ constructor(limit) {
14
+ this.limit = limit;
15
+ this.remaining = this.limit;
16
+ }
17
+ process(override = false) {
18
+ if (!this.queue.length) {
19
+ if (this.processing) {
20
+ clearTimeout(this.processing);
21
+ this.processing = false;
22
+ }
23
+ return;
24
+ }
25
+ if (this.processing && !override) {
26
+ return;
27
+ }
28
+ const now = Date.now();
29
+ if (!this.reset || this.reset < now) {
30
+ this.reset = now;
31
+ this.remaining = this.limit;
32
+ }
33
+ this.last = now;
34
+ if (this.remaining <= 0) {
35
+ this.processing = setTimeout(() => {
36
+ this.processing = false;
37
+ this.process(true);
38
+ }, this.resetAfter ? 0.5 : Math.max(0, (this.reset || 0) - now) + 1);
39
+ return;
40
+ }
41
+ --this.remaining;
42
+ this.processing = true;
43
+ const shift = this.queue.shift();
44
+ shift.next(() => {
45
+ if (this.queue.length > 0) {
46
+ this.process(true);
47
+ }
48
+ else {
49
+ this.processing = false;
50
+ }
51
+ }, shift.resolve, shift.reject);
52
+ }
53
+ push(func, unshift) {
54
+ if (unshift) {
55
+ this.queue.unshift(func);
56
+ }
57
+ else {
58
+ this.queue.push(func);
59
+ }
60
+ this.process();
61
+ }
62
+ triggerResetAfter() {
63
+ if (!this.processingResetAfter && this.resetAfter) {
64
+ this.processingResetAfter = setTimeout(() => {
65
+ this.remaining++;
66
+ this.processingResetAfter = undefined;
67
+ }, this.resetAfter * 1.5);
68
+ }
69
+ }
70
+ }
71
+ exports.Bucket = Bucket;
@@ -1,5 +1,5 @@
1
1
  export * from './CDN';
2
- export * from './REST';
3
2
  export * from './Router';
4
3
  export * from './Routes';
4
+ export * from './api';
5
5
  export * from './shared';
package/lib/api/index.js CHANGED
@@ -15,7 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./CDN"), exports);
18
- __exportStar(require("./REST"), exports);
19
18
  __exportStar(require("./Router"), exports);
20
19
  __exportStar(require("./Routes"), exports);
20
+ __exportStar(require("./api"), exports);
21
21
  __exportStar(require("./shared"), exports);
@@ -1,7 +1,35 @@
1
- export * from './REST';
2
- export * from './errors/DiscordAPIError';
3
- export * from './errors/HTTPError';
4
- export * from './errors/RateLimitError';
1
+ /// <reference types="node" />
2
+ import type { MakeRequired } from '../common';
3
+ export * from './api';
5
4
  export * from './utils/constants';
6
5
  export * from './utils/types';
7
- export { calculateUserDefaultAvatarIndex, makeURLSearchParams, parseResponse } from './utils/utils';
6
+ export { calculateUserDefaultAvatarIndex } from './utils/utils';
7
+ export interface ApiHandlerOptions {
8
+ baseUrl?: string;
9
+ domain?: string;
10
+ token: string;
11
+ debug?: boolean;
12
+ agent?: string;
13
+ smartBucket?: boolean;
14
+ workerProxy?: boolean;
15
+ }
16
+ export interface ApiHandlerInternalOptions extends MakeRequired<ApiHandlerOptions, 'baseUrl' | 'domain'> {
17
+ userAgent: string;
18
+ }
19
+ export interface RawFile {
20
+ contentType?: string;
21
+ data: Buffer | Uint8Array | boolean | number | string;
22
+ key?: string;
23
+ name: string;
24
+ }
25
+ export interface ApiRequestOptions {
26
+ body?: Record<string, any>;
27
+ query?: Record<string, any>;
28
+ files?: RawFile[];
29
+ auth?: boolean;
30
+ reason?: string;
31
+ route?: `/${string}`;
32
+ unshift?: boolean;
33
+ appendToFormData?: boolean;
34
+ }
35
+ export type HttpMethods = 'GET' | 'DELETE' | 'PUT' | 'POST' | 'PATCH';
package/lib/api/shared.js CHANGED
@@ -14,14 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.parseResponse = exports.makeURLSearchParams = exports.calculateUserDefaultAvatarIndex = void 0;
18
- __exportStar(require("./REST"), exports);
19
- __exportStar(require("./errors/DiscordAPIError"), exports);
20
- __exportStar(require("./errors/HTTPError"), exports);
21
- __exportStar(require("./errors/RateLimitError"), exports);
17
+ exports.calculateUserDefaultAvatarIndex = void 0;
18
+ __exportStar(require("./api"), exports);
22
19
  __exportStar(require("./utils/constants"), exports);
23
20
  __exportStar(require("./utils/types"), exports);
24
21
  var utils_1 = require("./utils/utils");
25
22
  Object.defineProperty(exports, "calculateUserDefaultAvatarIndex", { enumerable: true, get: function () { return utils_1.calculateUserDefaultAvatarIndex; } });
26
- Object.defineProperty(exports, "makeURLSearchParams", { enumerable: true, get: function () { return utils_1.makeURLSearchParams; } });
27
- Object.defineProperty(exports, "parseResponse", { enumerable: true, get: function () { return utils_1.parseResponse; } });
@@ -1,32 +1,4 @@
1
- export declare const DefaultUserAgent = "DiscordBot (https://seyfert.com)";
2
- export declare const DefaultRestOptions: {
3
- agent: null;
4
- api: string;
5
- authPrefix: string;
6
- headers: {};
7
- invalidRequestWarningInterval: number;
8
- globalRequestsPerSecond: number;
9
- offset: number;
10
- rejectOnRateLimit: null;
11
- retries: number;
12
- timeout: number;
13
- version: string;
14
- hashSweepInterval: number;
15
- hashLifetime: number;
16
- handlerSweepInterval: number;
17
- makeRequest(url: string, init: RequestInit): Promise<Response>;
18
- };
19
- /**
20
- * The events that the REST manager emits
21
- */
22
- export declare enum RESTEvents {
23
- Debug = "restDebug",
24
- HandlerSweep = "handlerSweep",
25
- HashSweep = "hashSweep",
26
- InvalidRequestWarning = "invalidRequestWarning",
27
- RateLimited = "rateLimited",
28
- Response = "response"
29
- }
1
+ export declare const DefaultUserAgent = "DiscordBot (https://seyfert.dev)";
30
2
  export declare const ALLOWED_EXTENSIONS: readonly ["webp", "png", "jpg", "jpeg", "gif"];
31
3
  export declare const ALLOWED_STICKER_EXTENSIONS: readonly ["png", "json", "gif"];
32
4
  export declare const ALLOWED_SIZES: readonly [16, 32, 64, 128, 256, 512, 1024, 2048, 4096];
@@ -36,4 +8,3 @@ export type ImageSize = (typeof ALLOWED_SIZES)[number];
36
8
  export declare const OverwrittenMimeTypes: {
37
9
  readonly 'image/apng': "image/png";
38
10
  };
39
- export declare const BurstHandlerMajorIdKey = "burst";
@@ -1,39 +1,7 @@
1
1
  "use strict";
2
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 = {}));
3
+ exports.OverwrittenMimeTypes = exports.ALLOWED_SIZES = exports.ALLOWED_STICKER_EXTENSIONS = exports.ALLOWED_EXTENSIONS = exports.DefaultUserAgent = void 0;
4
+ exports.DefaultUserAgent = 'DiscordBot (https://seyfert.dev)';
37
5
  exports.ALLOWED_EXTENSIONS = ['webp', 'png', 'jpg', 'jpeg', 'gif'];
38
6
  exports.ALLOWED_STICKER_EXTENSIONS = ['png', 'json', 'gif'];
39
7
  exports.ALLOWED_SIZES = [16, 32, 64, 128, 256, 512, 1_024, 2_048, 4_096];
@@ -41,10 +9,3 @@ exports.OverwrittenMimeTypes = {
41
9
  // https://github.com/discordjs/discord.js/issues/8557
42
10
  'image/apng': 'image/png',
43
11
  };
44
- exports.BurstHandlerMajorIdKey = 'burst';
45
- /**
46
- * Prefix for deprecation warnings.
47
- *
48
- * @internal
49
- */
50
- exports.DEPRECATION_WARNING_PREFIX = 'DeprecationWarning';
@@ -1,325 +1,8 @@
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
1
  export interface RequestHeaders {
320
2
  Authorization?: string;
321
3
  'User-Agent': string;
322
4
  'X-Audit-Log-Reason'?: string;
5
+ 'Content-Type'?: string;
323
6
  }
324
7
  /**
325
8
  * Possible API methods to be used when doing requests
@@ -331,5 +14,3 @@ export declare enum RequestMethod {
331
14
  Post = "POST",
332
15
  Put = "PUT"
333
16
  }
334
- export type RouteLike = `/${string}`;
335
- export type HandlerRequestData = Pick<InternalRequest, 'auth' | 'body' | 'files' | 'signal'>;
@@ -1,49 +1,11 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="node" />
3
2
  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
3
  /**
36
4
  * Calculates the default avatar index for a given user id.
37
5
  *
38
6
  * @param userId - The user id to calculate the default avatar index for
39
7
  */
40
8
  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
9
  /**
48
10
  * Verifies that a value is a buffer-like object.
49
11
  *