seyfert 0.1.0 → 1.0.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 (193) 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 +39 -0
  18. package/lib/api/api.js +318 -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 +31 -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 +3 -12
  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.js +2 -2
  44. package/lib/cache/adapters/redis.d.ts +2 -3
  45. package/lib/cache/adapters/redis.js +13 -5
  46. package/lib/cache/adapters/workeradapter.d.ts +9 -1
  47. package/lib/cache/adapters/workeradapter.js +7 -3
  48. package/lib/cache/index.d.ts +20 -6
  49. package/lib/cache/index.js +26 -10
  50. package/lib/cache/resources/channels.d.ts +6 -2
  51. package/lib/cache/resources/channels.js +12 -6
  52. package/lib/cache/resources/default/base.d.ts +17 -16
  53. package/lib/cache/resources/default/base.js +25 -24
  54. package/lib/cache/resources/default/guild-based.d.ts +22 -19
  55. package/lib/cache/resources/default/guild-based.js +32 -31
  56. package/lib/cache/resources/default/guild-related.d.ts +22 -19
  57. package/lib/cache/resources/default/guild-related.js +37 -43
  58. package/lib/cache/resources/emojis.d.ts +4 -2
  59. package/lib/cache/resources/emojis.js +8 -6
  60. package/lib/cache/resources/guilds.d.ts +4 -2
  61. package/lib/cache/resources/guilds.js +15 -8
  62. package/lib/cache/resources/members.d.ts +4 -2
  63. package/lib/cache/resources/members.js +16 -13
  64. package/lib/cache/resources/overwrites.d.ts +25 -0
  65. package/lib/cache/resources/overwrites.js +39 -0
  66. package/lib/cache/resources/presence.js +3 -4
  67. package/lib/cache/resources/roles.d.ts +4 -2
  68. package/lib/cache/resources/roles.js +8 -6
  69. package/lib/cache/resources/stickers.d.ts +4 -2
  70. package/lib/cache/resources/stickers.js +8 -6
  71. package/lib/cache/resources/threads.d.ts +4 -2
  72. package/lib/cache/resources/threads.js +8 -6
  73. package/lib/cache/resources/users.d.ts +4 -2
  74. package/lib/cache/resources/users.js +8 -6
  75. package/lib/cache/resources/voice-states.d.ts +3 -3
  76. package/lib/cache/resources/voice-states.js +6 -7
  77. package/lib/client/base.d.ts +49 -16
  78. package/lib/client/base.js +21 -17
  79. package/lib/client/client.d.ts +14 -3
  80. package/lib/client/client.js +21 -21
  81. package/lib/client/httpclient.d.ts +3 -5
  82. package/lib/client/httpclient.js +29 -16
  83. package/lib/client/{oninteraction.d.ts → oninteractioncreate.d.ts} +1 -1
  84. package/lib/client/{oninteraction.js → oninteractioncreate.js} +34 -23
  85. package/lib/client/onmessagecreate.d.ts +3 -0
  86. package/lib/client/onmessagecreate.js +337 -0
  87. package/lib/client/workerclient.d.ts +5 -1
  88. package/lib/client/workerclient.js +67 -44
  89. package/lib/collection.d.ts +1 -1
  90. package/lib/collection.js +9 -6
  91. package/lib/commands/applications/chat.d.ts +32 -25
  92. package/lib/commands/applications/chat.js +51 -34
  93. package/lib/commands/applications/chatcontext.d.ts +34 -16
  94. package/lib/commands/applications/chatcontext.js +99 -20
  95. package/lib/commands/applications/menu.d.ts +9 -8
  96. package/lib/commands/applications/menu.js +14 -5
  97. package/lib/commands/applications/menucontext.d.ts +27 -10
  98. package/lib/commands/applications/menucontext.js +51 -7
  99. package/lib/commands/applications/options.d.ts +13 -13
  100. package/lib/commands/applications/shared.d.ts +7 -2
  101. package/lib/commands/decorators.d.ts +14 -14
  102. package/lib/commands/decorators.js +9 -5
  103. package/lib/commands/handler.d.ts +2 -1
  104. package/lib/commands/handler.js +60 -14
  105. package/lib/commands/index.d.ts +1 -1
  106. package/lib/commands/index.js +2 -1
  107. package/lib/commands/optionresolver.d.ts +6 -5
  108. package/lib/commands/optionresolver.js +10 -6
  109. package/lib/common/bot/watcher.d.ts +3 -3
  110. package/lib/common/bot/watcher.js +3 -1
  111. package/lib/common/index.d.ts +1 -1
  112. package/lib/common/index.js +2 -1
  113. package/lib/common/it/logger.d.ts +11 -0
  114. package/lib/common/it/logger.js +51 -2
  115. package/lib/common/it/utils.d.ts +3 -13
  116. package/lib/common/it/utils.js +9 -30
  117. package/lib/common/shorters/channels.d.ts +55 -5
  118. package/lib/common/shorters/channels.js +59 -0
  119. package/lib/common/shorters/guilds.d.ts +5 -2
  120. package/lib/common/shorters/guilds.js +18 -0
  121. package/lib/common/shorters/messages.js +0 -2
  122. package/lib/common/shorters/overwrites.d.ts +29 -0
  123. package/lib/common/shorters/overwrites.js +63 -0
  124. package/lib/common/shorters/roles.js +3 -3
  125. package/lib/common/shorters/webhook.d.ts +2 -2
  126. package/lib/common/types/util.d.ts +2 -1
  127. package/lib/common/types/write.d.ts +3 -7
  128. package/lib/components/handler.d.ts +12 -18
  129. package/lib/components/handler.js +58 -103
  130. package/lib/components/index.d.ts +0 -1
  131. package/lib/components/index.js +0 -1
  132. package/lib/components/listener.d.ts +2 -2
  133. package/lib/components/listener.js +2 -3
  134. package/lib/events/event.d.ts +2 -2
  135. package/lib/events/handler.d.ts +3 -2
  136. package/lib/events/handler.js +14 -6
  137. package/lib/events/hooks/dispatch.d.ts +2 -1
  138. package/lib/events/hooks/dispatch.js +5 -1
  139. package/lib/events/hooks/thread.d.ts +63 -63
  140. package/lib/index.d.ts +8 -5
  141. package/lib/index.js +20 -10
  142. package/lib/langs/handler.d.ts +6 -4
  143. package/lib/langs/handler.js +10 -8
  144. package/lib/langs/router.d.ts +8 -9
  145. package/lib/langs/router.js +5 -5
  146. package/lib/structures/ClientUser.d.ts +1 -16
  147. package/lib/structures/ClientUser.js +0 -31
  148. package/lib/structures/Guild.d.ts +1 -1
  149. package/lib/structures/GuildMember.d.ts +12 -0
  150. package/lib/structures/GuildMember.js +14 -0
  151. package/lib/structures/GuildRole.d.ts +4 -2
  152. package/lib/structures/GuildRole.js +4 -1
  153. package/lib/structures/GuildTemplate.js +1 -1
  154. package/lib/structures/Interaction.d.ts +2 -0
  155. package/lib/structures/Interaction.js +12 -13
  156. package/lib/structures/Message.d.ts +7 -2
  157. package/lib/structures/Message.js +6 -3
  158. package/lib/structures/Sticker.d.ts +1 -1
  159. package/lib/structures/Sticker.js +1 -1
  160. package/lib/structures/User.d.ts +5 -0
  161. package/lib/structures/User.js +3 -0
  162. package/lib/structures/Webhook.d.ts +1 -1
  163. package/lib/structures/Webhook.js +1 -1
  164. package/lib/structures/channels.d.ts +45 -6
  165. package/lib/structures/channels.js +23 -7
  166. package/lib/structures/extra/BitField.d.ts +9 -6
  167. package/lib/structures/extra/BitField.js +27 -3
  168. package/lib/structures/extra/Permissions.d.ts +6 -1
  169. package/lib/structures/extra/Permissions.js +7 -0
  170. package/lib/websocket/discord/basesocket.js +0 -1
  171. package/lib/websocket/discord/workermanager.d.ts +9 -1
  172. package/lib/websocket/discord/workermanager.js +21 -13
  173. package/package.json +21 -20
  174. package/lib/api/REST.d.ts +0 -127
  175. package/lib/api/REST.js +0 -424
  176. package/lib/api/errors/DiscordAPIError.d.ts +0 -51
  177. package/lib/api/errors/DiscordAPIError.js +0 -81
  178. package/lib/api/errors/HTTPError.d.ts +0 -20
  179. package/lib/api/errors/HTTPError.js +0 -28
  180. package/lib/api/errors/RateLimitError.d.ts +0 -19
  181. package/lib/api/errors/RateLimitError.js +0 -37
  182. package/lib/api/handlers/BurstHandler.d.ts +0 -51
  183. package/lib/api/handlers/BurstHandler.js +0 -124
  184. package/lib/api/handlers/SequentialHandler.d.ts +0 -81
  185. package/lib/api/handlers/SequentialHandler.js +0 -365
  186. package/lib/api/handlers/Shared.d.ts +0 -14
  187. package/lib/api/handlers/Shared.js +0 -125
  188. package/lib/api/interfaces/Handler.d.ts +0 -21
  189. package/lib/api/interfaces/Handler.js +0 -2
  190. package/lib/websocket/discord/handlemessage.d.ts +0 -0
  191. package/lib/websocket/discord/handlemessage.js +0 -1
  192. package/lib/websocket/discord/memberUpdate.d.ts +0 -16
  193. package/lib/websocket/discord/memberUpdate.js +0 -47
@@ -1,125 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleErrors = exports.makeNetworkRequest = exports.incrementInvalidCount = void 0;
4
- const DiscordAPIError_js_1 = require("../errors/DiscordAPIError.js");
5
- const HTTPError_js_1 = require("../errors/HTTPError.js");
6
- const constants_js_1 = require("../utils/constants.js");
7
- const utils_js_1 = require("../utils/utils.js");
8
- /**
9
- * Invalid request limiting is done on a per-IP basis, not a per-token basis.
10
- * The best we can do is track invalid counts process-wide (on the theory that
11
- * users could have multiple bots run from one process) rather than per-bot.
12
- * Therefore, store these at file scope here rather than in the client's
13
- * RESTManager object.
14
- */
15
- let invalidCount = 0;
16
- let invalidCountResetTime = null;
17
- /**
18
- * Increment the invalid request count and emit warning if necessary
19
- *
20
- * @internal
21
- */
22
- function incrementInvalidCount(manager) {
23
- if (!invalidCountResetTime || invalidCountResetTime < Date.now()) {
24
- invalidCountResetTime = Date.now() + 1_000 * 60 * 10;
25
- invalidCount = 0;
26
- }
27
- invalidCount++;
28
- const emitInvalid = manager.options.invalidRequestWarningInterval > 0 &&
29
- invalidCount % manager.options.invalidRequestWarningInterval === 0;
30
- if (emitInvalid) {
31
- // Let library users know periodically about invalid requests
32
- manager.debugger?.info({
33
- count: invalidCount,
34
- remainingTime: invalidCountResetTime - Date.now(),
35
- });
36
- }
37
- }
38
- exports.incrementInvalidCount = incrementInvalidCount;
39
- /**
40
- * Performs the actual network request for a request handler
41
- *
42
- * @param manager - The manager that holds options and emits informational events
43
- * @param routeId - The generalized api route with literal ids for major parameters
44
- * @param url - The fully resolved url to make the request to
45
- * @param options - The fetch options needed to make the request
46
- * @param requestData - Extra data from the user's request needed for errors and additional processing
47
- * @param retries - The number of retries this request has already attempted (recursion occurs on the handler)
48
- * @returns The respond from the network or `null` when the request should be retried
49
- * @internal
50
- */
51
- async function makeNetworkRequest(manager, routeId, url, options, requestData, retries) {
52
- const controller = new AbortController();
53
- const timeout = setTimeout(() => controller.abort(), manager.options.timeout);
54
- if (requestData.signal) {
55
- // If the user signal was aborted, abort the controller, else abort the local signal.
56
- // The reason why we don't re-use the user's signal, is because users may use the same signal for multiple
57
- // requests, and we do not want to cause unexpected side-effects.
58
- if (requestData.signal.aborted)
59
- controller.abort();
60
- else
61
- requestData.signal.addEventListener('abort', () => controller.abort());
62
- }
63
- let res;
64
- try {
65
- res = await manager.options.makeRequest(url, { ...options, signal: controller.signal });
66
- }
67
- catch (error) {
68
- if (!(error instanceof Error))
69
- throw error;
70
- // Retry the specified number of times if needed
71
- if ((0, utils_js_1.shouldRetry)(error) && retries !== manager.options.retries) {
72
- // Retry is handled by the handler upon receiving null
73
- return null;
74
- }
75
- throw error;
76
- }
77
- finally {
78
- clearTimeout(timeout);
79
- }
80
- manager.debugger?.info(constants_js_1.RESTEvents.Response, {
81
- method: options.method ?? 'get',
82
- path: routeId.original,
83
- route: routeId.bucketRoute,
84
- options,
85
- data: requestData,
86
- retries,
87
- }, res instanceof Response ? res.clone() : { ...res });
88
- return res;
89
- }
90
- exports.makeNetworkRequest = makeNetworkRequest;
91
- /**
92
- * Handles 5xx and 4xx errors (not 429's) conventionally. 429's should be handled before calling this function
93
- *
94
- * @param manager - The manager that holds options and emits informational events
95
- * @param res - The response received from {@link makeNetworkRequest}
96
- * @param method - The method used to make the request
97
- * @param url - The fully resolved url to make the request to
98
- * @param requestData - Extra data from the user's request needed for errors and additional processing
99
- * @param retries - The number of retries this request has already attempted (recursion occurs on the handler)
100
- * @returns The response if the status code is not handled or null to request a retry
101
- */
102
- async function handleErrors(manager, res, method, url, requestData, retries) {
103
- const status = res.status;
104
- if (status >= 500 && status < 600) {
105
- // Retry the specified number of times for possible server side issues
106
- if (retries !== manager.options.retries) {
107
- return null;
108
- }
109
- // We are out of retries, throw an error
110
- throw new HTTPError_js_1.HTTPError(status, res.statusText, method, url, requestData);
111
- }
112
- // Handle possible malformed requests
113
- if (status >= 400 && status < 500) {
114
- // If we receive this status code, it means the token we had is no longer valid.
115
- if (status === 401 && requestData.auth) {
116
- manager.setToken(null);
117
- }
118
- // The request will not succeed for some reason, parse the error returned from the api
119
- const data = (await (0, utils_js_1.parseResponse)(res));
120
- // throw the API error
121
- throw new DiscordAPIError_js_1.DiscordAPIError(data, 'code' in data ? data.code : data.error, status, method, url, requestData);
122
- }
123
- return res;
124
- }
125
- exports.handleErrors = handleErrors;
@@ -1,21 +0,0 @@
1
- import type { RequestInit } from 'undici-types';
2
- import type { HandlerRequestData, ResponseLike, RouteData } from '../utils/types.js';
3
- export interface IHandler {
4
- /**
5
- * The unique id of the handler
6
- */
7
- readonly id: string;
8
- /**
9
- * If the bucket is currently inactive (no pending requests)
10
- */
11
- get inactive(): boolean;
12
- /**
13
- * Queues a request to be sent
14
- *
15
- * @param routeId - The generalized api route with literal ids for major parameters
16
- * @param url - The url to do the request on
17
- * @param options - All the information needed to make a request
18
- * @param requestData - Extra data from the user's request needed for errors and additional processing
19
- */
20
- queueRequest(routeId: RouteData, url: string, options: RequestInit, requestData: HandlerRequestData): Promise<ResponseLike>;
21
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
File without changes
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,16 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- /// <reference types="node" />
4
- /// <reference types="node" />
5
- /// <reference types="node" />
6
- import type { APIUser, GatewayGuildMemberUpdateDispatchData } from 'discord-api-types/v10';
7
- export declare class MemberUpdateHandler {
8
- guildMemberUpdate: Map<string, {
9
- timeout: NodeJS.Timeout;
10
- member: GatewayGuildMemberUpdateDispatchData;
11
- }>;
12
- check(member: GatewayGuildMemberUpdateDispatchData): boolean;
13
- setMember(member: GatewayGuildMemberUpdateDispatchData): void;
14
- membersEquals(old: GatewayGuildMemberUpdateDispatchData, member: GatewayGuildMemberUpdateDispatchData): boolean;
15
- usersEqual(old: APIUser, user: APIUser): boolean;
16
- }
@@ -1,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MemberUpdateHandler = void 0;
4
- class MemberUpdateHandler {
5
- guildMemberUpdate = new Map();
6
- check(member) {
7
- if (!this.guildMemberUpdate.has(member.user.id)) {
8
- this.setMember(member);
9
- return true;
10
- }
11
- const data = this.guildMemberUpdate.get(member.user.id);
12
- if (this.usersEqual(data.member.user, member.user)) {
13
- return this.membersEquals(data.member, member);
14
- }
15
- clearTimeout(data.timeout);
16
- this.setMember(member);
17
- return true;
18
- }
19
- setMember(member) {
20
- this.guildMemberUpdate.set(member.user.id, {
21
- member,
22
- timeout: setTimeout(() => {
23
- this.guildMemberUpdate.delete(member.user.id);
24
- }, 1.5e3),
25
- });
26
- }
27
- membersEquals(old, member) {
28
- return (old.joined_at === member.joined_at &&
29
- old.nick === member.nick &&
30
- old.avatar === member.avatar &&
31
- old.pending === member.pending &&
32
- old.communication_disabled_until === member.communication_disabled_until &&
33
- old.flags === member.flags &&
34
- (old.roles === member.roles ||
35
- (old.roles.length === member.roles.length && old.roles.every((role, i) => role === member.roles[i]))));
36
- }
37
- usersEqual(old, user) {
38
- return (old.username === user.username &&
39
- old.discriminator === user.discriminator &&
40
- old.global_name === user.global_name &&
41
- old.avatar === user.avatar &&
42
- old.public_flags === user.public_flags &&
43
- old.banner === user.banner &&
44
- old.accent_color === user.accent_color);
45
- }
46
- }
47
- exports.MemberUpdateHandler = MemberUpdateHandler;