seyfert 1.0.1 → 1.1.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 (113) hide show
  1. package/lib/api/CDN.d.ts +1 -1
  2. package/lib/api/CDN.js +0 -2
  3. package/lib/api/Router.js +2 -2
  4. package/lib/api/Routes/applications.d.ts +29 -33
  5. package/lib/api/Routes/channels.d.ts +11 -17
  6. package/lib/api/Routes/interactions.d.ts +3 -7
  7. package/lib/api/Routes/webhooks.d.ts +4 -6
  8. package/lib/builders/Attachment.d.ts +2 -3
  9. package/lib/cache/adapters/redis.js +6 -0
  10. package/lib/cache/adapters/types.d.ts +23 -23
  11. package/lib/cache/adapters/workeradapter.d.ts +4 -4
  12. package/lib/cache/adapters/workeradapter.js +10 -5
  13. package/lib/cache/index.d.ts +4 -5
  14. package/lib/cache/index.js +4 -3
  15. package/lib/cache/resources/default/base.d.ts +11 -10
  16. package/lib/cache/resources/default/guild-based.d.ts +8 -7
  17. package/lib/cache/resources/default/guild-based.js +8 -7
  18. package/lib/cache/resources/default/guild-related.d.ts +10 -9
  19. package/lib/cache/resources/default/guild-related.js +3 -2
  20. package/lib/cache/resources/guilds.js +2 -1
  21. package/lib/cache/resources/overwrites.d.ts +1 -1
  22. package/lib/cache/resources/overwrites.js +7 -1
  23. package/lib/client/base.d.ts +33 -179
  24. package/lib/client/base.js +56 -21
  25. package/lib/client/client.d.ts +10 -3
  26. package/lib/client/client.js +23 -8
  27. package/lib/client/oninteractioncreate.js +9 -9
  28. package/lib/client/onmessagecreate.js +192 -153
  29. package/lib/client/workerclient.d.ts +9 -3
  30. package/lib/client/workerclient.js +50 -23
  31. package/lib/collection.js +2 -2
  32. package/lib/commands/applications/chat.d.ts +16 -8
  33. package/lib/commands/applications/chat.js +20 -13
  34. package/lib/commands/applications/chatcontext.d.ts +6 -4
  35. package/lib/commands/applications/chatcontext.js +6 -1
  36. package/lib/commands/applications/menu.d.ts +5 -1
  37. package/lib/commands/applications/menu.js +11 -5
  38. package/lib/commands/applications/menucontext.d.ts +5 -3
  39. package/lib/commands/applications/menucontext.js +7 -2
  40. package/lib/commands/applications/options.d.ts +1 -2
  41. package/lib/commands/applications/shared.d.ts +5 -4
  42. package/lib/commands/decorators.d.ts +18 -6
  43. package/lib/commands/decorators.js +18 -8
  44. package/lib/commands/handler.d.ts +11 -5
  45. package/lib/commands/handler.js +46 -37
  46. package/lib/commands/optionresolver.d.ts +11 -4
  47. package/lib/commands/optionresolver.js +6 -4
  48. package/lib/common/index.d.ts +7 -0
  49. package/lib/common/index.js +7 -0
  50. package/lib/common/it/utils.d.ts +1 -0
  51. package/lib/common/it/utils.js +4 -1
  52. package/lib/common/shorters/channels.d.ts +67 -129
  53. package/lib/common/shorters/channels.js +119 -135
  54. package/lib/common/shorters/emojis.d.ts +47 -0
  55. package/lib/common/shorters/emojis.js +80 -0
  56. package/lib/common/shorters/guilds.d.ts +22 -249
  57. package/lib/common/shorters/guilds.js +51 -140
  58. package/lib/common/shorters/members.d.ts +82 -108
  59. package/lib/common/shorters/members.js +151 -166
  60. package/lib/common/shorters/messages.d.ts +11 -23
  61. package/lib/common/shorters/messages.js +58 -104
  62. package/lib/common/shorters/reactions.d.ts +10 -0
  63. package/lib/common/shorters/reactions.js +45 -0
  64. package/lib/common/shorters/roles.d.ts +39 -7
  65. package/lib/common/shorters/roles.js +74 -42
  66. package/lib/common/shorters/templates.d.ts +6 -8
  67. package/lib/common/shorters/templates.js +17 -21
  68. package/lib/common/shorters/users.d.ts +4 -6
  69. package/lib/common/shorters/users.js +29 -33
  70. package/lib/common/shorters/webhook.d.ts +62 -26
  71. package/lib/common/shorters/webhook.js +113 -58
  72. package/lib/common/types/options.d.ts +2 -2
  73. package/lib/common/types/util.d.ts +3 -0
  74. package/lib/components/handler.d.ts +28 -9
  75. package/lib/components/handler.js +28 -11
  76. package/lib/events/handler.d.ts +10 -2
  77. package/lib/events/handler.js +6 -8
  78. package/lib/index.d.ts +4 -2
  79. package/lib/index.js +1 -1
  80. package/lib/langs/handler.d.ts +8 -0
  81. package/lib/langs/handler.js +8 -2
  82. package/lib/structures/AutoModerationRule.d.ts +2 -2
  83. package/lib/structures/ClientUser.d.ts +2 -2
  84. package/lib/structures/Guild.d.ts +2 -2
  85. package/lib/structures/GuildEmoji.d.ts +4 -4
  86. package/lib/structures/GuildEmoji.js +7 -7
  87. package/lib/structures/GuildMember.d.ts +7 -6
  88. package/lib/structures/GuildMember.js +5 -2
  89. package/lib/structures/GuildPreview.d.ts +2 -2
  90. package/lib/structures/GuildRole.d.ts +2 -2
  91. package/lib/structures/GuildTemplate.d.ts +2 -2
  92. package/lib/structures/Interaction.d.ts +9 -10
  93. package/lib/structures/Interaction.js +2 -2
  94. package/lib/structures/Message.d.ts +8 -7
  95. package/lib/structures/Message.js +7 -4
  96. package/lib/structures/Sticker.d.ts +2 -2
  97. package/lib/structures/User.d.ts +1 -0
  98. package/lib/structures/User.js +5 -0
  99. package/lib/structures/Webhook.d.ts +2 -2
  100. package/lib/structures/Webhook.js +3 -3
  101. package/lib/structures/channels.d.ts +21 -22
  102. package/lib/structures/channels.js +13 -25
  103. package/lib/structures/extra/Base.d.ts +1 -2
  104. package/lib/structures/extra/DiscordBase.d.ts +2 -2
  105. package/lib/websocket/constants/index.js +1 -0
  106. package/lib/websocket/discord/shard.js +4 -2
  107. package/lib/websocket/discord/sharder.d.ts +3 -0
  108. package/lib/websocket/discord/sharder.js +12 -5
  109. package/lib/websocket/discord/shared.d.ts +1 -0
  110. package/lib/websocket/discord/worker.d.ts +2 -1
  111. package/lib/websocket/discord/workermanager.d.ts +8 -3
  112. package/lib/websocket/discord/workermanager.js +78 -30
  113. package/package.json +8 -6
@@ -1,31 +1,67 @@
1
- import type { RESTPatchAPIWebhookJSONBody, RESTPatchAPIWebhookWithTokenJSONBody, RESTPostAPIWebhookWithTokenJSONBody } from '..';
2
- import { type MessageWebhookMethodEditParams, type MessageWebhookMethodWriteParams, Webhook, WebhookMessage } from '../../structures';
1
+ import type { RESTPatchAPIWebhookJSONBody, RESTPatchAPIWebhookWithTokenJSONBody, RESTPostAPIChannelWebhookJSONBody } from '..';
2
+ import { Webhook, WebhookMessage, type MessageWebhookMethodEditParams, type MessageWebhookMethodWriteParams } from '../../structures';
3
3
  import { BaseShorter } from './base';
4
4
  export declare class WebhookShorter extends BaseShorter {
5
- get webhooks(): {
6
- delete: (webhookId: string, { token, reason }: WebhookShorterOptionalParams) => Promise<never>;
7
- edit: (webhookId: string, body: RESTPatchAPIWebhookWithTokenJSONBody | RESTPatchAPIWebhookJSONBody, { token, reason }: WebhookShorterOptionalParams) => Promise<import("discord-api-types/rest/v10/webhook").RESTGetAPIWebhookWithTokenResult>;
8
- fetch: (webhookId: string, token?: string) => Promise<Webhook>;
9
- messages: {
10
- write: (webhookId: string, token: string, { body: data, ...payload }: {
11
- body: Omit<RESTPostAPIWebhookWithTokenJSONBody, "components" | "embeds"> & import("..").ResolverProps;
12
- query?: import("discord-api-types/rest/v10/webhook").RESTPostAPIWebhookWithTokenQuery | undefined;
13
- }) => Promise<WebhookMessage | null>;
14
- edit: (webhookId: string, token: string, { messageId, body: data, ...json }: {
15
- body: Omit<import("discord-api-types/rest/v10/webhook").RESTPatchAPIWebhookWithTokenMessageJSONBody, "components" | "embeds"> & import("..").ResolverProps;
16
- messageId: string;
17
- query?: import("discord-api-types/rest/v10/webhook").RESTGetAPIWebhookWithTokenMessageQuery | undefined;
18
- }) => Promise<WebhookMessage>;
19
- delete: (webhookId: string, token: string, messageId: string, reason?: string | undefined) => Promise<never>;
20
- fetch: (webhookId: string, token: string, messageId: string, threadId?: string | undefined) => Promise<WebhookMessage | undefined>;
21
- };
22
- };
23
- get messages(): {
24
- write: (webhookId: string, token: string, { body: data, ...payload }: MessageWebhookMethodWriteParams) => Promise<WebhookMessage | null>;
25
- edit: (webhookId: string, token: string, { messageId, body: data, ...json }: MessageWebhookMethodEditParams) => Promise<WebhookMessage>;
26
- delete: (webhookId: string, token: string, messageId: string, reason?: string) => Promise<never>;
27
- fetch: (webhookId: string, token: string, messageId: string, threadId?: string) => Promise<WebhookMessage | undefined>;
28
- };
5
+ create(channelId: string, body: RESTPostAPIChannelWebhookJSONBody): Promise<Webhook>;
6
+ /**
7
+ * Deletes a webhook.
8
+ * @param webhookId The ID of the webhook.
9
+ * @param options The optional parameters including token and reason.
10
+ * @returns A Promise that resolves when the webhook is deleted.
11
+ */
12
+ delete(webhookId: string, options: WebhookShorterOptionalParams): Promise<never>;
13
+ /**
14
+ * Edits a webhook.
15
+ * @param webhookId The ID of the webhook.
16
+ * @param body The data to update the webhook with.
17
+ * @param options The optional parameters including token and reason.
18
+ * @returns A Promise that resolves when the webhook is edited.
19
+ */
20
+ edit(webhookId: string, body: RESTPatchAPIWebhookWithTokenJSONBody | RESTPatchAPIWebhookJSONBody, options: WebhookShorterOptionalParams): Promise<import("discord-api-types/rest/v10/webhook").RESTGetAPIWebhookWithTokenResult>;
21
+ /**
22
+ * Fetches a webhook.
23
+ * @param webhookId The ID of the webhook.
24
+ * @param token The token of the webhook (optional).
25
+ * @returns A Promise that resolves to the fetched webhook.
26
+ */
27
+ fetch(webhookId: string, token?: string): Promise<Webhook>;
28
+ /**
29
+ * Writes a message using the webhook.
30
+ * @param webhookId The ID of the webhook.
31
+ * @param token The token of the webhook.
32
+ * @param data The data for writing the message.
33
+ * @returns A Promise that resolves to the written message.
34
+ */
35
+ writeMessage(webhookId: string, token: string, { body: data, ...payload }: MessageWebhookMethodWriteParams): Promise<WebhookMessage | null>;
36
+ /**
37
+ * Edits a message sent by the webhook.
38
+ * @param webhookId The ID of the webhook.
39
+ * @param token The token of the webhook.
40
+ * @param messageId The ID of the message to edit.
41
+ * @param data The data for editing the message.
42
+ * @returns A Promise that resolves to the edited message.
43
+ */
44
+ editMessage(webhookId: string, token: string, { messageId, body: data, ...json }: MessageWebhookMethodEditParams): Promise<WebhookMessage>;
45
+ /**
46
+ * Deletes a message sent by the webhook.
47
+ * @param webhookId The ID of the webhook.
48
+ * @param token The token of the webhook.
49
+ * @param messageId The ID of the message to delete.
50
+ * @param reason The reason for deleting the message.
51
+ * @returns A Promise that resolves when the message is deleted.
52
+ */
53
+ deleteMessage(webhookId: string, token: string, messageId: string, reason?: string): Promise<never>;
54
+ /**
55
+ * Fetches a message sent by the webhook.
56
+ * @param webhookId The ID of the webhook.
57
+ * @param token The token of the webhook.
58
+ * @param messageId The ID of the message to fetch.
59
+ * @param threadId The ID of the thread the message belongs to.
60
+ * @returns A Promise that resolves to the fetched message, or undefined if not found.
61
+ */
62
+ fetchMessage(webhookId: string, token: string, messageId: string, threadId?: string): Promise<WebhookMessage | undefined>;
63
+ listFromGuild(guildId: string): Promise<Webhook[]>;
64
+ listFromChannel(channelId: string): Promise<Webhook[]>;
29
65
  }
30
66
  export type WebhookShorterOptionalParams = Partial<{
31
67
  token: string;
@@ -5,65 +5,120 @@ const builders_1 = require("../../builders");
5
5
  const structures_1 = require("../../structures");
6
6
  const base_1 = require("./base");
7
7
  class WebhookShorter extends base_1.BaseShorter {
8
- get webhooks() {
9
- return {
10
- delete: (webhookId, { token, reason }) => {
11
- if (token) {
12
- return this.client.proxy.webhooks(webhookId)(token).delete({ reason, auth: false });
13
- }
14
- return this.client.proxy.webhooks(webhookId).delete({ reason });
15
- },
16
- edit: (webhookId, body, { token, reason }) => {
17
- if (token) {
18
- return this.client.proxy.webhooks(webhookId)(token).patch({ body, reason, auth: false });
19
- }
20
- return this.client.proxy.webhooks(webhookId).patch({ body, reason });
21
- },
22
- fetch: async (webhookId, token) => {
23
- let webhook;
24
- if (token) {
25
- webhook = await this.client.proxy.webhooks(webhookId)(token).get({ auth: false });
26
- }
27
- else {
28
- webhook = await this.client.proxy.webhooks(webhookId).get();
29
- }
30
- return new structures_1.Webhook(this.client, webhook);
31
- },
32
- messages: this.messages,
33
- };
8
+ async create(channelId, body) {
9
+ const webhook = await this.client.proxy.channels(channelId).webhooks.post({
10
+ body,
11
+ });
12
+ return new structures_1.Webhook(this.client, webhook);
34
13
  }
35
- get messages() {
36
- return {
37
- write: async (webhookId, token, { body: data, ...payload }) => {
38
- const { files, ...body } = data;
39
- const transformedBody = structures_1.MessagesMethods.transformMessageBody(body);
40
- const parsedFiles = files ? await (0, builders_1.resolveFiles)(files) : [];
41
- return this.client.proxy
42
- .webhooks(webhookId)(token)
43
- .post({ ...payload, files: parsedFiles, body: transformedBody })
44
- .then(m => (m?.id ? new structures_1.WebhookMessage(this.client, m, webhookId, token) : null));
45
- },
46
- edit: async (webhookId, token, { messageId, body: data, ...json }) => {
47
- const { files, ...body } = data;
48
- const transformedBody = structures_1.MessagesMethods.transformMessageBody(body);
49
- const parsedFiles = files ? await (0, builders_1.resolveFiles)(files) : [];
50
- return this.client.proxy
51
- .webhooks(webhookId)(token)
52
- .messages(messageId)
53
- .patch({ ...json, auth: false, files: parsedFiles, body: transformedBody })
54
- .then(m => new structures_1.WebhookMessage(this.client, m, webhookId, token));
55
- },
56
- delete: async (webhookId, token, messageId, reason) => {
57
- return this.client.proxy.webhooks(webhookId)(token).messages(messageId).delete({ reason });
58
- },
59
- fetch: async (webhookId, token, messageId, threadId) => {
60
- const message = await this.client.proxy
61
- .webhooks(webhookId)(token)
62
- .messages(messageId)
63
- .get({ auth: false, query: { threadId } });
64
- return message ? new structures_1.WebhookMessage(this.client, message, webhookId, token) : undefined;
65
- },
66
- };
14
+ /**
15
+ * Deletes a webhook.
16
+ * @param webhookId The ID of the webhook.
17
+ * @param options The optional parameters including token and reason.
18
+ * @returns A Promise that resolves when the webhook is deleted.
19
+ */
20
+ delete(webhookId, options) {
21
+ if (options.token) {
22
+ return this.client.proxy.webhooks(webhookId)(options.token).delete({ reason: options.reason, auth: false });
23
+ }
24
+ return this.client.proxy.webhooks(webhookId).delete({ reason: options.reason });
25
+ }
26
+ /**
27
+ * Edits a webhook.
28
+ * @param webhookId The ID of the webhook.
29
+ * @param body The data to update the webhook with.
30
+ * @param options The optional parameters including token and reason.
31
+ * @returns A Promise that resolves when the webhook is edited.
32
+ */
33
+ edit(webhookId, body, options) {
34
+ if (options.token) {
35
+ return this.client.proxy.webhooks(webhookId)(options.token).patch({ body, reason: options.reason, auth: false });
36
+ }
37
+ return this.client.proxy.webhooks(webhookId).patch({ body, reason: options.reason });
38
+ }
39
+ /**
40
+ * Fetches a webhook.
41
+ * @param webhookId The ID of the webhook.
42
+ * @param token The token of the webhook (optional).
43
+ * @returns A Promise that resolves to the fetched webhook.
44
+ */
45
+ async fetch(webhookId, token) {
46
+ let webhook;
47
+ if (token) {
48
+ webhook = await this.client.proxy.webhooks(webhookId)(token).get({ auth: false });
49
+ }
50
+ else {
51
+ webhook = await this.client.proxy.webhooks(webhookId).get();
52
+ }
53
+ return new structures_1.Webhook(this.client, webhook);
54
+ }
55
+ /**
56
+ * Writes a message using the webhook.
57
+ * @param webhookId The ID of the webhook.
58
+ * @param token The token of the webhook.
59
+ * @param data The data for writing the message.
60
+ * @returns A Promise that resolves to the written message.
61
+ */
62
+ async writeMessage(webhookId, token, { body: data, ...payload }) {
63
+ const { files, ...body } = data;
64
+ const transformedBody = structures_1.MessagesMethods.transformMessageBody(body);
65
+ const parsedFiles = files ? await (0, builders_1.resolveFiles)(files) : [];
66
+ return this.client.proxy
67
+ .webhooks(webhookId)(token)
68
+ .post({ ...payload, files: parsedFiles, body: transformedBody })
69
+ .then(m => (m?.id ? new structures_1.WebhookMessage(this.client, m, webhookId, token) : null));
70
+ }
71
+ /**
72
+ * Edits a message sent by the webhook.
73
+ * @param webhookId The ID of the webhook.
74
+ * @param token The token of the webhook.
75
+ * @param messageId The ID of the message to edit.
76
+ * @param data The data for editing the message.
77
+ * @returns A Promise that resolves to the edited message.
78
+ */
79
+ async editMessage(webhookId, token, { messageId, body: data, ...json }) {
80
+ const { files, ...body } = data;
81
+ const transformedBody = structures_1.MessagesMethods.transformMessageBody(body);
82
+ const parsedFiles = files ? await (0, builders_1.resolveFiles)(files) : [];
83
+ return this.client.proxy
84
+ .webhooks(webhookId)(token)
85
+ .messages(messageId)
86
+ .patch({ ...json, auth: false, files: parsedFiles, body: transformedBody })
87
+ .then(m => new structures_1.WebhookMessage(this.client, m, webhookId, token));
88
+ }
89
+ /**
90
+ * Deletes a message sent by the webhook.
91
+ * @param webhookId The ID of the webhook.
92
+ * @param token The token of the webhook.
93
+ * @param messageId The ID of the message to delete.
94
+ * @param reason The reason for deleting the message.
95
+ * @returns A Promise that resolves when the message is deleted.
96
+ */
97
+ deleteMessage(webhookId, token, messageId, reason) {
98
+ return this.client.proxy.webhooks(webhookId)(token).messages(messageId).delete({ reason });
99
+ }
100
+ /**
101
+ * Fetches a message sent by the webhook.
102
+ * @param webhookId The ID of the webhook.
103
+ * @param token The token of the webhook.
104
+ * @param messageId The ID of the message to fetch.
105
+ * @param threadId The ID of the thread the message belongs to.
106
+ * @returns A Promise that resolves to the fetched message, or undefined if not found.
107
+ */
108
+ async fetchMessage(webhookId, token, messageId, threadId) {
109
+ const message = await this.client.proxy
110
+ .webhooks(webhookId)(token)
111
+ .messages(messageId)
112
+ .get({ auth: false, query: { threadId } });
113
+ return message ? new structures_1.WebhookMessage(this.client, message, webhookId, token) : undefined;
114
+ }
115
+ async listFromGuild(guildId) {
116
+ const webhooks = await this.client.proxy.guilds(guildId).webhooks.get();
117
+ return webhooks.map(webhook => new structures_1.Webhook(this.client, webhook));
118
+ }
119
+ async listFromChannel(channelId) {
120
+ const webhooks = await this.client.proxy.channels(channelId).webhooks.get();
121
+ return webhooks.map(webhook => new structures_1.Webhook(this.client, webhook));
67
122
  }
68
123
  }
69
124
  exports.WebhookShorter = WebhookShorter;
@@ -1,9 +1,9 @@
1
1
  import type { Identify } from '..';
2
2
  import type { ImageURLOptions } from '../../api';
3
- import type { BaseClient } from '../../client/base';
3
+ import type { UsingClient } from '../../commands';
4
4
  export type ImageOptions = ImageURLOptions;
5
5
  export type MethodContext<T = {}> = Identify<{
6
- client: BaseClient;
6
+ client: UsingClient;
7
7
  } & T>;
8
8
  export type MessageWebhookPayload<Body, Extra = {}> = Identify<{
9
9
  body: Body;
@@ -34,6 +34,8 @@ export type Identify<T> = T extends infer U ? {
34
34
  } : never;
35
35
  export type TypeArray<T> = T | T[];
36
36
  export type When<T extends boolean, A, B = never> = T extends true ? A : B;
37
+ export type AuxIsStrictlyUndefined<T> = T extends undefined | null | never | void ? true : false;
38
+ export type IsStrictlyUndefined<T> = AuxIsStrictlyUndefined<T> extends true ? true : AuxIsStrictlyUndefined<T> extends false ? false : false;
37
39
  export type If<T extends boolean, A, B = null> = T extends true ? A : B extends null ? A | null : B;
38
40
  export type PickPartial<T, K extends keyof T> = {
39
41
  [P in keyof T]?: T[P] | undefined;
@@ -88,4 +90,5 @@ export type AtLeastOne<T, U = {
88
90
  [K in keyof T]: Pick<T, K>;
89
91
  }> = Partial<T> & U[keyof U];
90
92
  export type FlatObjectKeys<T extends Record<string, any>, Key = keyof T> = Key extends string ? T[Key] extends Record<string, unknown> ? `${Key}.${FlatObjectKeys<T[Key]>}` : T[Key] extends string ? `${Key}` : never : never;
93
+ export type Awaitable<V> = Promise<V> | V;
91
94
  export {};
@@ -1,33 +1,52 @@
1
1
  /// <reference types="node" />
2
2
  import type { ComponentCallback, ListenerOptions, ModalSubmitCallback } from '../builders/types';
3
- import type { BaseClient } from '../client/base';
4
3
  import { LimitedCollection } from '../collection';
4
+ import type { UsingClient } from '../commands';
5
5
  import { BaseHandler, type Logger, type OnFailCallback } from '../common';
6
6
  import type { ComponentInteraction, ModalSubmitInteraction } from '../structures';
7
7
  import { ComponentCommand, ModalCommand } from './command';
8
8
  type COMPONENTS = {
9
- components: Partial<Record<string, ComponentCallback>>;
9
+ components: {
10
+ match: string | string[] | RegExp;
11
+ callback: ComponentCallback;
12
+ }[];
10
13
  options?: ListenerOptions;
11
14
  messageId?: string;
12
15
  idle?: NodeJS.Timeout;
13
16
  timeout?: NodeJS.Timeout;
14
- __run: (customId: string, callback: ComponentCallback) => any;
17
+ __run: (customId: string | string[] | RegExp, callback: ComponentCallback) => any;
15
18
  };
19
+ export interface ComponentHandlerLike {
20
+ readonly values: Map<string, COMPONENTS>;
21
+ readonly commands: (ComponentCommand | ModalCommand)[];
22
+ readonly modals: Map<string, ModalSubmitCallback> | LimitedCollection<string, ModalSubmitCallback>;
23
+ onFail: ComponentHandler['onFail'];
24
+ createComponentCollector: ComponentHandler['createComponentCollector'];
25
+ hasModal: ComponentHandler['hasModal'];
26
+ onModalSubmit: ComponentHandler['onModalSubmit'];
27
+ executeModal: ComponentHandler['executeModal'];
28
+ hasComponent: ComponentHandler['hasComponent'];
29
+ executeComponent: ComponentHandler['executeComponent'];
30
+ onComponent: ComponentHandler['onComponent'];
31
+ load: ComponentHandler['load'];
32
+ reload: ComponentHandler['reload'];
33
+ reloadAll: ComponentHandler['reloadAll'];
34
+ onMessageDelete: ComponentHandler['onMessageDelete'];
35
+ }
16
36
  export declare class ComponentHandler extends BaseHandler {
17
- protected client: BaseClient;
18
- protected onFail?: OnFailCallback;
37
+ protected client: UsingClient;
38
+ onFail: OnFailCallback;
19
39
  readonly values: Map<string, COMPONENTS>;
20
40
  readonly modals: LimitedCollection<string, ModalSubmitCallback>;
21
41
  readonly commands: (ComponentCommand | ModalCommand)[];
22
42
  protected filter: (path: string) => boolean;
23
- constructor(logger: Logger, client: BaseClient);
24
- set OnFail(cb: OnFailCallback);
43
+ constructor(logger: Logger, client: UsingClient);
25
44
  createComponentCollector(messageId: string, options?: ListenerOptions): {
26
- run: (customId: string, callback: ComponentCallback) => any;
45
+ run: (customId: string | RegExp | string[], callback: ComponentCallback) => any;
27
46
  stop: (reason?: string) => void;
28
47
  };
29
48
  onComponent(id: string, interaction: ComponentInteraction): Promise<void>;
30
- hasComponent(id: string, customId: string): ComponentCallback | undefined;
49
+ hasComponent(id: string, customId: string): boolean;
31
50
  resetTimeouts(id: string): void;
32
51
  hasModal(interaction: ModalSubmitInteraction): boolean;
33
52
  onModalSubmit(interaction: ModalSubmitInteraction): any;
@@ -6,7 +6,7 @@ const common_1 = require("../common");
6
6
  const command_1 = require("./command");
7
7
  class ComponentHandler extends common_1.BaseHandler {
8
8
  client;
9
- onFail;
9
+ onFail = err => this.logger.warn('<Client>.components.onFail', err);
10
10
  values = new Map();
11
11
  // 10 minutes timeout, because discord dont send an event when the user cancel the modal
12
12
  modals = new collection_1.LimitedCollection({ expire: 60e3 * 10 });
@@ -16,12 +16,9 @@ class ComponentHandler extends common_1.BaseHandler {
16
16
  super(logger);
17
17
  this.client = client;
18
18
  }
19
- set OnFail(cb) {
20
- this.onFail = cb;
21
- }
22
19
  createComponentCollector(messageId, options = {}) {
23
20
  this.values.set(messageId, {
24
- components: {},
21
+ components: [],
25
22
  options,
26
23
  idle: options.idle
27
24
  ? setTimeout(() => {
@@ -41,7 +38,10 @@ class ComponentHandler extends common_1.BaseHandler {
41
38
  : undefined,
42
39
  __run: (customId, callback) => {
43
40
  if (this.values.has(messageId)) {
44
- this.values.get(messageId).components[customId] = callback;
41
+ this.values.get(messageId).components.push({
42
+ callback,
43
+ match: customId,
44
+ });
45
45
  }
46
46
  },
47
47
  });
@@ -57,7 +57,13 @@ class ComponentHandler extends common_1.BaseHandler {
57
57
  }
58
58
  async onComponent(id, interaction) {
59
59
  const row = this.values.get(id);
60
- const component = row?.components?.[interaction.customId];
60
+ const component = row?.components?.find(x => {
61
+ if (typeof x.match === 'string')
62
+ return x.match === interaction.customId;
63
+ if (Array.isArray(x.match))
64
+ return x.match.includes(interaction.customId);
65
+ return interaction.customId.match(x.match);
66
+ });
61
67
  if (!component)
62
68
  return;
63
69
  if (row.options?.filter) {
@@ -65,7 +71,7 @@ class ComponentHandler extends common_1.BaseHandler {
65
71
  return;
66
72
  }
67
73
  row.idle?.refresh();
68
- await component(interaction, reason => {
74
+ await component.callback(interaction, reason => {
69
75
  row.options?.onStop?.(reason ?? 'stop');
70
76
  this.deleteValue(id);
71
77
  }, () => {
@@ -73,7 +79,13 @@ class ComponentHandler extends common_1.BaseHandler {
73
79
  });
74
80
  }
75
81
  hasComponent(id, customId) {
76
- return this.values.get(id)?.components?.[customId];
82
+ return (this.values.get(id)?.components?.some(x => {
83
+ if (typeof x.match === 'string')
84
+ return x.match === customId;
85
+ if (Array.isArray(x.match))
86
+ return x.match.includes(customId);
87
+ return customId.match(x.match);
88
+ }) ?? false);
77
89
  }
78
90
  resetTimeouts(id) {
79
91
  const listener = this.values.get(id);
@@ -124,9 +136,12 @@ class ComponentHandler extends common_1.BaseHandler {
124
136
  continue;
125
137
  component.__filePath = paths[i].path;
126
138
  this.commands.push(component);
139
+ await this.__callback?.(component);
127
140
  }
128
141
  }
129
142
  async reload(path) {
143
+ if (!this.client.components)
144
+ return;
130
145
  const component = this.client.components.commands.find(x => x.__filePath?.endsWith(`${path}.js`) ||
131
146
  x.__filePath?.endsWith(`${path}.ts`) ||
132
147
  x.__filePath?.endsWith(path) ||
@@ -145,6 +160,8 @@ class ComponentHandler extends common_1.BaseHandler {
145
160
  return imported;
146
161
  }
147
162
  async reloadAll() {
163
+ if (!this.client.components)
164
+ return;
148
165
  for (const i of this.client.components.commands) {
149
166
  if (!i.__filePath)
150
167
  return this.logger.warn('Unknown command dont have __filePath property', i);
@@ -162,7 +179,7 @@ class ComponentHandler extends common_1.BaseHandler {
162
179
  }
163
180
  }
164
181
  catch (e) {
165
- await this.onFail?.(e);
182
+ await this.onFail(e);
166
183
  }
167
184
  }
168
185
  }
@@ -175,7 +192,7 @@ class ComponentHandler extends common_1.BaseHandler {
175
192
  }
176
193
  }
177
194
  catch (e) {
178
- await this.onFail?.(e);
195
+ await this.onFail(e);
179
196
  }
180
197
  }
181
198
  }
@@ -6,11 +6,19 @@ type EventValue = MakeRequired<ClientEvent, '__filePath'> & {
6
6
  fired?: boolean;
7
7
  };
8
8
  type GatewayEvents = Uppercase<SnakeCase<keyof ClientEvents>>;
9
+ export interface EventHandlerLike {
10
+ runEvent: EventHandler['runEvent'];
11
+ execute: EventHandler['execute'];
12
+ load: EventHandler['load'];
13
+ reload: EventHandler['reload'];
14
+ reloadAll: EventHandler['reloadAll'];
15
+ values: EventHandler['values'];
16
+ onFail: EventHandler['onFail'];
17
+ }
9
18
  export declare class EventHandler extends BaseHandler {
10
- protected onFail: OnFailCallback;
19
+ onFail: OnFailCallback;
11
20
  protected filter: (path: string) => boolean;
12
21
  values: Partial<Record<GatewayEvents, EventValue>>;
13
- set OnFail(cb: OnFailCallback);
14
22
  load(eventsDir: string): Promise<void>;
15
23
  execute(name: GatewayEvents, ...args: [GatewayDispatchPayload, Client<true> | WorkerClient<true>, number]): Promise<void>;
16
24
  runEvent(name: GatewayEvents, client: Client | WorkerClient, packet: any, shardId: number): Promise<void>;
@@ -27,12 +27,9 @@ exports.EventHandler = void 0;
27
27
  const common_1 = require("../common");
28
28
  const RawEvents = __importStar(require("../events/hooks"));
29
29
  class EventHandler extends common_1.BaseHandler {
30
- onFail = err => this.logger.warn('<Client>.events.OnFail', err);
30
+ onFail = err => this.logger.warn('<Client>.events.onFail', err);
31
31
  filter = (path) => path.endsWith('.js') || (!path.endsWith('.d.ts') && path.endsWith('.ts'));
32
32
  values = {};
33
- set OnFail(cb) {
34
- this.onFail = cb;
35
- }
36
33
  async load(eventsDir) {
37
34
  for (const i of await this.loadFilesK(await this.getFiles(eventsDir))) {
38
35
  const instance = i.file;
@@ -42,6 +39,7 @@ class EventHandler extends common_1.BaseHandler {
42
39
  }
43
40
  instance.__filePath = i.path;
44
41
  this.values[common_1.ReplaceRegex.snake(instance.data.name).toUpperCase()] = instance;
42
+ await this.__callback?.(instance);
45
43
  }
46
44
  }
47
45
  async execute(name, ...args) {
@@ -54,7 +52,7 @@ class EventHandler extends common_1.BaseHandler {
54
52
  case 'MESSAGE_CREATE':
55
53
  {
56
54
  const { d: data } = args[0];
57
- if (args[1].components.values.has(data.interaction?.id ?? data.id)) {
55
+ if (args[1].components?.values.has(data.interaction?.id ?? data.id)) {
58
56
  args[1].components.values.get(data.interaction?.id ?? data.id).messageId = data.id;
59
57
  }
60
58
  }
@@ -62,7 +60,7 @@ class EventHandler extends common_1.BaseHandler {
62
60
  case 'MESSAGE_DELETE':
63
61
  {
64
62
  const { d: data } = args[0];
65
- const value = [...args[1].components.values].find(x => x[1].messageId === data.id);
63
+ const value = [...(args[1].components?.values ?? [])].find(x => x[1].messageId === data.id);
66
64
  if (value) {
67
65
  args[1].components.onMessageDelete(value[0]);
68
66
  }
@@ -71,7 +69,7 @@ class EventHandler extends common_1.BaseHandler {
71
69
  case 'MESSAGE_DELETE_BULK':
72
70
  {
73
71
  const { d: data } = args[0];
74
- const values = [...args[1].components.values];
72
+ const values = [...(args[1].components?.values ?? [])];
75
73
  data.ids.forEach(id => {
76
74
  const value = values.find(x => x[1].messageId === id);
77
75
  if (value) {
@@ -97,7 +95,7 @@ class EventHandler extends common_1.BaseHandler {
97
95
  await Event.run(...[hook, client, shardId]);
98
96
  }
99
97
  catch (e) {
100
- await this.onFail?.(e);
98
+ await this.onFail(e);
101
99
  }
102
100
  }
103
101
  async reload(name) {
package/lib/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import type { InternalRuntimeConfig, InternalRuntimeConfigHTTP, RuntimeConfig, RuntimeConfigHTTP } from './client/base';
2
+ import type { InferWithPrefix } from './commands';
3
+ import { type When } from './common';
2
4
  import type { ClientNameEvents, EventContext } from './events';
3
- import type { ChatInputCommandInteraction, MessageCommandInteraction, UserCommandInteraction } from './structures';
5
+ import type { ChatInputCommandInteraction, Message, MessageCommandInteraction, UserCommandInteraction } from './structures';
4
6
  export { Logger, PermissionFlagsBits, PermissionStrings, Watcher } from './common';
5
7
  export { Collection, LimitedCollection } from './collection';
6
8
  export * from './api';
@@ -79,4 +81,4 @@ export declare const config: {
79
81
  * };
80
82
  * });
81
83
  */
82
- export declare function extendContext<T extends {}>(cb: (interaction: ChatInputCommandInteraction | UserCommandInteraction | MessageCommandInteraction) => T): (interaction: ChatInputCommandInteraction | UserCommandInteraction | MessageCommandInteraction) => T;
84
+ export declare function extendContext<T extends {}>(cb: (interaction: ChatInputCommandInteraction | UserCommandInteraction | MessageCommandInteraction | When<InferWithPrefix, Message, never>) => T): (interaction: ChatInputCommandInteraction | UserCommandInteraction | MessageCommandInteraction | When<InferWithPrefix, Message, never>) => T;
package/lib/index.js CHANGED
@@ -77,7 +77,7 @@ exports.config = {
77
77
  intents: 'intents' in data
78
78
  ? typeof data.intents === 'number'
79
79
  ? data.intents
80
- : data.intents?.reduce((pr, acc) => pr | common_1.GatewayIntentBits[acc], 0) ?? 0
80
+ : data.intents?.reduce((pr, acc) => pr | (typeof acc === 'number' ? acc : common_1.GatewayIntentBits[acc]), 0) ?? 0
81
81
  : 0,
82
82
  };
83
83
  },
@@ -1,4 +1,12 @@
1
1
  import { BaseHandler, type LocaleString } from '../common';
2
+ export interface LangsHandlerLike {
3
+ getKey: LangsHandler['getKey'];
4
+ load: LangsHandler['load'];
5
+ values: LangsHandler['values'];
6
+ aliases: LangsHandler['aliases'];
7
+ get: LangsHandler['get'];
8
+ defaultLang?: LangsHandler['defaultLang'];
9
+ }
2
10
  export declare class LangsHandler extends BaseHandler {
3
11
  values: Partial<Record<string, any>>;
4
12
  protected filter: (path: string) => boolean;
@@ -13,8 +13,13 @@ class LangsHandler extends common_1.BaseHandler {
13
13
  }
14
14
  getKey(lang, message) {
15
15
  let value = this.values[lang];
16
- for (const i of message.split('.')) {
17
- value = value[i];
16
+ try {
17
+ for (const i of message.split('.')) {
18
+ value = value[i];
19
+ }
20
+ }
21
+ catch {
22
+ return;
18
23
  }
19
24
  if (typeof value !== 'string') {
20
25
  return;
@@ -30,6 +35,7 @@ class LangsHandler extends common_1.BaseHandler {
30
35
  for (const i of files) {
31
36
  const locale = i.name.split('.').slice(0, -1).join('.');
32
37
  this.values[locale] = i.file;
38
+ await this.__callback?.(locale, i.file);
33
39
  }
34
40
  }
35
41
  }
@@ -1,10 +1,10 @@
1
- import type { BaseClient } from '../client/base';
1
+ import type { UsingClient } from '../commands';
2
2
  import type { APIAutoModerationRule, MethodContext, ObjectToLower, RESTPatchAPIAutoModerationRuleJSONBody, RESTPostAPIAutoModerationRuleJSONBody } from '../common';
3
3
  import { DiscordBase } from './extra/DiscordBase';
4
4
  export interface AutoModerationRule extends ObjectToLower<APIAutoModerationRule> {
5
5
  }
6
6
  export declare class AutoModerationRule extends DiscordBase<APIAutoModerationRule> {
7
- constructor(client: BaseClient, data: APIAutoModerationRule);
7
+ constructor(client: UsingClient, data: APIAutoModerationRule);
8
8
  fetchCreator(force?: boolean): Promise<import("./GuildMember").GuildMember>;
9
9
  guild(force?: boolean): Promise<import("./Guild").Guild<"cached"> | import("./Guild").Guild<"api">>;
10
10
  fetch(): Promise<APIAutoModerationRule>;