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
@@ -1,15 +1,11 @@
1
1
  import type { APIActionRowComponent, APIEmbed, APIInteractionResponseCallbackData, APIInteractionResponseChannelMessageWithSource, APIMessageActionRowComponent, APIModalInteractionResponse, RESTPatchAPIChannelMessageJSONBody, RESTPatchAPIWebhookWithTokenMessageJSONBody, RESTPostAPIChannelMessageJSONBody, RESTPostAPIWebhookWithTokenJSONBody } from '..';
2
2
  import type { RawFile } from '../../api';
3
- import type { ActionRow, Attachment, BuilderComponents, Embed, Modal, TextInput } from '../../builders';
4
- import type { ComponentsListener } from '../../components/listener';
3
+ import type { ActionRow, Attachment, AttachmentBuilder, BuilderComponents, Embed, Modal } from '../../builders';
5
4
  import type { OmitInsert } from './util';
6
- export type BodyModalComponentProper = {
7
- components?: ActionRow<TextInput>[] | undefined;
8
- };
9
5
  export interface ResolverProps {
10
6
  embeds?: Embed[] | APIEmbed[] | undefined;
11
- components?: ComponentsListener<BuilderComponents> | APIActionRowComponent<APIMessageActionRowComponent>[] | ActionRow<BuilderComponents>[] | undefined;
12
- files?: Attachment[] | RawFile[] | undefined;
7
+ components?: APIActionRowComponent<APIMessageActionRowComponent>[] | ActionRow<BuilderComponents>[] | undefined;
8
+ files?: AttachmentBuilder[] | Attachment[] | RawFile[] | undefined;
13
9
  }
14
10
  export type MessageCreateBodyRequest = OmitInsert<RESTPostAPIChannelMessageJSONBody, 'components' | 'embeds', ResolverProps>;
15
11
  export type MessageUpdateBodyRequest = OmitInsert<RESTPatchAPIChannelMessageJSONBody, 'components' | 'embeds', ResolverProps>;
@@ -1,21 +1,17 @@
1
1
  /// <reference types="node" />
2
- import { type BuilderComponents } from '../builders';
3
- import type { ComponentCallback, ModalSubmitCallback } from '../builders/types';
2
+ import type { ComponentCallback, ListenerOptions, ModalSubmitCallback } from '../builders/types';
4
3
  import type { BaseClient } from '../client/base';
5
4
  import { LimitedCollection } from '../collection';
6
- import { BaseHandler, type OnFailCallback, type APIMessage, type APIModalInteractionResponseCallbackData, type Logger } from '../common';
7
- import type { InteractionMessageUpdateBodyRequest, MessageCreateBodyRequest, MessageUpdateBodyRequest, ModalCreateBodyRequest, ResolverProps } from '../common/types/write';
8
- import type { ComponentInteraction, ModalSubmitInteraction, ReplyInteractionBody } from '../structures';
5
+ import { BaseHandler, type Logger, type OnFailCallback } from '../common';
6
+ import type { ComponentInteraction, ModalSubmitInteraction } from '../structures';
9
7
  import { ComponentCommand, ModalCommand } from './command';
10
- import { ComponentsListener } from './listener';
11
8
  type COMPONENTS = {
12
- buttons: Partial<Record<string, {
13
- callback: ComponentCallback;
14
- }>>;
15
- listener: ComponentsListener<BuilderComponents>;
9
+ components: Partial<Record<string, ComponentCallback>>;
10
+ options?: ListenerOptions;
16
11
  messageId?: string;
17
12
  idle?: NodeJS.Timeout;
18
13
  timeout?: NodeJS.Timeout;
14
+ __run: (customId: string, callback: ComponentCallback) => any;
19
15
  };
20
16
  export declare class ComponentHandler extends BaseHandler {
21
17
  protected client: BaseClient;
@@ -26,19 +22,17 @@ export declare class ComponentHandler extends BaseHandler {
26
22
  protected filter: (path: string) => boolean;
27
23
  constructor(logger: Logger, client: BaseClient);
28
24
  set OnFail(cb: OnFailCallback);
29
- hasComponent(id: string, customId: string): boolean;
25
+ createComponentCollector(messageId: string, options?: ListenerOptions): {
26
+ run: (customId: string, callback: ComponentCallback) => any;
27
+ stop: (reason?: string) => void;
28
+ };
30
29
  onComponent(id: string, interaction: ComponentInteraction): Promise<void>;
30
+ hasComponent(id: string, customId: string): ComponentCallback | undefined;
31
31
  resetTimeouts(id: string): void;
32
32
  hasModal(interaction: ModalSubmitInteraction): boolean;
33
33
  onModalSubmit(interaction: ModalSubmitInteraction): any;
34
- __setComponents(id: string, record: NonNullable<ResolverProps['components']>): void;
35
- protected __setModal(id: string, record: APIModalInteractionResponseCallbackData | ModalCreateBodyRequest): void;
36
34
  deleteValue(id: string, reason?: string): void;
37
- onRequestInteraction(interactionId: string, interaction: ReplyInteractionBody): void;
38
35
  onMessageDelete(id: string): void;
39
- onRequestMessage(body: MessageCreateBodyRequest, message: APIMessage): void;
40
- onRequestInteractionUpdate(body: InteractionMessageUpdateBodyRequest, message: APIMessage): void;
41
- onRequestUpdateMessage(body: MessageUpdateBodyRequest, message: APIMessage): void;
42
36
  load(componentsDir: string): Promise<void>;
43
37
  reload(path: string): Promise<any>;
44
38
  reloadAll(): Promise<void>;
@@ -1,11 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ComponentHandler = void 0;
4
- const builders_1 = require("../builders");
5
4
  const collection_1 = require("../collection");
6
5
  const common_1 = require("../common");
7
6
  const command_1 = require("./command");
8
- const listener_1 = require("./listener");
9
7
  class ComponentHandler extends common_1.BaseHandler {
10
8
  client;
11
9
  onFail;
@@ -13,7 +11,7 @@ class ComponentHandler extends common_1.BaseHandler {
13
11
  // 10 minutes timeout, because discord dont send an event when the user cancel the modal
14
12
  modals = new collection_1.LimitedCollection({ expire: 60e3 * 10 });
15
13
  commands = [];
16
- filter = (path) => path.endsWith('.js') || path.endsWith('.ts');
14
+ filter = (path) => path.endsWith('.js') || (!path.endsWith('.d.ts') && path.endsWith('.ts'));
17
15
  constructor(logger, client) {
18
16
  super(logger);
19
17
  this.client = client;
@@ -21,26 +19,62 @@ class ComponentHandler extends common_1.BaseHandler {
21
19
  set OnFail(cb) {
22
20
  this.onFail = cb;
23
21
  }
24
- hasComponent(id, customId) {
25
- return !!this.values.get(id)?.buttons?.[customId];
22
+ createComponentCollector(messageId, options = {}) {
23
+ this.values.set(messageId, {
24
+ components: {},
25
+ options,
26
+ idle: options.idle
27
+ ? setTimeout(() => {
28
+ this.deleteValue(messageId);
29
+ options.onStop?.('idle', () => {
30
+ this.createComponentCollector(messageId, options);
31
+ });
32
+ }, options.idle)
33
+ : undefined,
34
+ timeout: options.timeout
35
+ ? setTimeout(() => {
36
+ this.deleteValue(messageId);
37
+ options.onStop?.('timeout', () => {
38
+ this.createComponentCollector(messageId, options);
39
+ });
40
+ }, options.timeout)
41
+ : undefined,
42
+ __run: (customId, callback) => {
43
+ if (this.values.has(messageId)) {
44
+ this.values.get(messageId).components[customId] = callback;
45
+ }
46
+ },
47
+ });
48
+ return {
49
+ run: this.values.get(messageId).__run,
50
+ stop: (reason) => {
51
+ this.deleteValue(messageId);
52
+ options.onStop?.(reason, () => {
53
+ this.createComponentCollector(messageId, options);
54
+ });
55
+ },
56
+ };
26
57
  }
27
58
  async onComponent(id, interaction) {
28
59
  const row = this.values.get(id);
29
- const component = row?.buttons?.[interaction.customId];
60
+ const component = row?.components?.[interaction.customId];
30
61
  if (!component)
31
62
  return;
32
- if (row.listener.options?.filter) {
33
- if (!(await row.listener.options.filter(interaction)))
63
+ if (row.options?.filter) {
64
+ if (!(await row.options.filter(interaction)))
34
65
  return;
35
66
  }
36
67
  row.idle?.refresh();
37
- await component.callback(interaction, reason => {
38
- row.listener.options?.onStop?.(reason ?? 'stop');
68
+ await component(interaction, reason => {
69
+ row.options?.onStop?.(reason ?? 'stop');
39
70
  this.deleteValue(id);
40
71
  }, () => {
41
72
  this.resetTimeouts(id);
42
73
  });
43
74
  }
75
+ hasComponent(id, customId) {
76
+ return this.values.get(id)?.components?.[customId];
77
+ }
44
78
  resetTimeouts(id) {
45
79
  const listener = this.values.get(id);
46
80
  if (listener) {
@@ -55,101 +89,19 @@ class ComponentHandler extends common_1.BaseHandler {
55
89
  setImmediate(() => this.modals.delete(interaction.user.id));
56
90
  return this.modals.get(interaction.user.id)?.(interaction);
57
91
  }
58
- __setComponents(id, record) {
59
- this.deleteValue(id);
60
- if (!(record instanceof listener_1.ComponentsListener))
61
- return;
62
- const components = {
63
- buttons: {},
64
- listener: record,
65
- };
66
- if ((record.options.idle ?? -1) > 0) {
67
- components.idle = setTimeout(() => {
68
- clearTimeout(components.timeout);
69
- clearTimeout(components.idle);
70
- record.options?.onStop?.('idle', () => {
71
- this.__setComponents(id, record);
72
- });
73
- this.values.delete(id);
74
- }, record.options.idle);
75
- }
76
- if ((record.options.timeout ?? -1) > 0) {
77
- components.timeout = setTimeout(() => {
78
- clearTimeout(components.timeout);
79
- clearTimeout(components.idle);
80
- record.options?.onStop?.('timeout', () => {
81
- this.__setComponents(id, record);
82
- });
83
- this.values.delete(id);
84
- }, record.options.timeout);
85
- }
86
- for (const actionRow of record.components) {
87
- for (const child of actionRow.components) {
88
- if ((child instanceof builders_1.SelectMenu || child instanceof builders_1.Button) && 'custom_id' in child.data) {
89
- components.buttons[child.data.custom_id] = {
90
- callback: child.__exec,
91
- };
92
- }
93
- }
94
- }
95
- if (Object.entries(components.buttons).length) {
96
- this.values.set(id, components);
97
- }
98
- }
99
- __setModal(id, record) {
100
- if ('__exec' in record) {
101
- this.modals.set(id, record.__exec);
102
- }
103
- }
104
92
  deleteValue(id, reason) {
105
93
  const component = this.values.get(id);
106
94
  if (component) {
107
95
  if (reason !== undefined)
108
- component.listener.options.onStop?.(reason);
96
+ component.options?.onStop?.(reason);
109
97
  clearTimeout(component.timeout);
110
98
  clearTimeout(component.idle);
111
99
  this.values.delete(id);
112
100
  }
113
101
  }
114
- onRequestInteraction(interactionId, interaction) {
115
- // @ts-expect-error dapi
116
- if (!interaction.data) {
117
- return;
118
- }
119
- switch (interaction.type) {
120
- case common_1.InteractionResponseType.ChannelMessageWithSource:
121
- case common_1.InteractionResponseType.UpdateMessage:
122
- if (!interaction.data.components)
123
- return;
124
- this.__setComponents(interactionId, interaction.data.components);
125
- break;
126
- case common_1.InteractionResponseType.Modal:
127
- if (!(interaction.data instanceof builders_1.Modal))
128
- return;
129
- this.__setModal(interactionId, interaction.data);
130
- break;
131
- }
132
- }
133
102
  onMessageDelete(id) {
134
103
  this.deleteValue(id, 'messageDelete');
135
104
  }
136
- onRequestMessage(body, message) {
137
- if (!body.components) {
138
- return;
139
- }
140
- this.__setComponents(message.id, body.components);
141
- }
142
- onRequestInteractionUpdate(body, message) {
143
- if (!body.components) {
144
- return;
145
- }
146
- this.__setComponents(message.interaction.id, body.components);
147
- }
148
- onRequestUpdateMessage(body, message) {
149
- if (!body.components)
150
- return;
151
- this.__setComponents(message.id, body.components);
152
- }
153
105
  async load(componentsDir) {
154
106
  const paths = await this.loadFilesK(await this.getFiles(componentsDir));
155
107
  for (let i = 0; i < paths.length; i++) {
@@ -10,7 +10,6 @@ import { UserSelectMenuComponent } from './UserSelectMenuComponent';
10
10
  export type MessageComponents = ButtonComponent | LinkButtonComponent | RoleSelectMenuComponent | UserSelectMenuComponent | StringSelectMenuComponent | ChannelSelectMenuComponent | MentionableSelectMenuComponent | TextInputComponent;
11
11
  export type ActionRowMessageComponents = Exclude<MessageComponents, TextInputComponent>;
12
12
  export * from './command';
13
- export * from './listener';
14
13
  /**
15
14
  * Return a new component instance based on the component type.
16
15
  *
@@ -24,7 +24,6 @@ const RoleSelectMenuComponent_1 = require("./RoleSelectMenuComponent");
24
24
  const StringSelectMenuComponent_1 = require("./StringSelectMenuComponent");
25
25
  const UserSelectMenuComponent_1 = require("./UserSelectMenuComponent");
26
26
  __exportStar(require("./command"), exports);
27
- __exportStar(require("./listener"), exports);
28
27
  /**
29
28
  * Return a new component instance based on the component type.
30
29
  *
@@ -1,11 +1,11 @@
1
1
  /// <reference types="node" />
2
2
  import type { ActionRow, BuilderComponents, ListenerOptions } from '../builders';
3
- import { type RestOrArray } from '../common';
3
+ import type { RestOrArray } from '../common';
4
4
  export declare class ComponentsListener<T extends BuilderComponents> {
5
5
  readonly options: ListenerOptions;
6
6
  components: ActionRow<T>[];
7
7
  idle?: NodeJS.Timeout;
8
8
  timeout?: NodeJS.Timeout;
9
- constructor(options: ListenerOptions);
9
+ constructor(options?: ListenerOptions);
10
10
  addRows(...row: RestOrArray<ActionRow<T>>): this;
11
11
  }
@@ -1,17 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ComponentsListener = void 0;
4
- const common_1 = require("../common");
5
4
  class ComponentsListener {
6
5
  options;
7
6
  components = [];
8
7
  idle;
9
8
  timeout;
10
- constructor(options) {
9
+ constructor(options = {}) {
11
10
  this.options = options;
12
11
  }
13
12
  addRows(...row) {
14
- this.components = this.components.concat((0, common_1.fastFlat)(row));
13
+ this.components = this.components.concat(row.flat());
15
14
  return this;
16
15
  }
17
16
  }
@@ -9,14 +9,14 @@ export interface ClientDataEvent {
9
9
  name: ClientNameEvents;
10
10
  once: boolean;
11
11
  }
12
- export type Handler = {
12
+ export type CallbackEventHandler = {
13
13
  [K in keyof ClientEvents]: (...data: [Awaited<ClientEvents[K]>, UsingClient, number]) => unknown;
14
14
  };
15
15
  export type EventContext<T extends {
16
16
  data: {
17
17
  name: ClientNameEvents;
18
18
  };
19
- }> = Parameters<Handler[T['data']['name']]>;
19
+ }> = Parameters<CallbackEventHandler[T['data']['name']]>;
20
20
  export interface ClientEvent {
21
21
  data: ClientDataEvent;
22
22
  run(...args: EventContext<any>): any;
@@ -1,5 +1,5 @@
1
1
  import type { Client, WorkerClient } from '../client';
2
- import { BaseHandler, type OnFailCallback, type GatewayDispatchPayload, type MakeRequired, type SnakeCase } from '../common';
2
+ import { BaseHandler, type GatewayDispatchPayload, type MakeRequired, type OnFailCallback, type SnakeCase } from '../common';
3
3
  import type { ClientEvents } from '../events/hooks';
4
4
  import type { ClientEvent, ClientNameEvents } from './event';
5
5
  type EventValue = MakeRequired<ClientEvent, '__filePath'> & {
@@ -7,12 +7,13 @@ type EventValue = MakeRequired<ClientEvent, '__filePath'> & {
7
7
  };
8
8
  type GatewayEvents = Uppercase<SnakeCase<keyof ClientEvents>>;
9
9
  export declare class EventHandler extends BaseHandler {
10
- protected onFail?: OnFailCallback;
10
+ protected onFail: OnFailCallback;
11
11
  protected filter: (path: string) => boolean;
12
12
  values: Partial<Record<GatewayEvents, EventValue>>;
13
13
  set OnFail(cb: OnFailCallback);
14
14
  load(eventsDir: string): Promise<void>;
15
15
  execute(name: GatewayEvents, ...args: [GatewayDispatchPayload, Client<true> | WorkerClient<true>, number]): Promise<void>;
16
+ runEvent(name: GatewayEvents, client: Client | WorkerClient, packet: any, shardId: number): Promise<void>;
16
17
  reload(name: ClientNameEvents): Promise<any>;
17
18
  reloadAll(): Promise<void>;
18
19
  }
@@ -27,8 +27,8 @@ 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;
31
- filter = (path) => path.endsWith('.js') || path.endsWith('.ts');
30
+ onFail = err => this.logger.warn('<Client>.events.OnFail', err);
31
+ filter = (path) => path.endsWith('.js') || (!path.endsWith('.d.ts') && path.endsWith('.ts'));
32
32
  values = {};
33
33
  set OnFail(cb) {
34
34
  this.onFail = cb;
@@ -46,11 +46,16 @@ class EventHandler extends common_1.BaseHandler {
46
46
  }
47
47
  async execute(name, ...args) {
48
48
  switch (name) {
49
+ case 'GUILD_DELETE':
50
+ case 'CHANNEL_UPDATE':
51
+ await this.runEvent(args[0].t, args[1], args[0], args[2]);
52
+ await args[1].cache.onPacket(args[0]);
53
+ return;
49
54
  case 'MESSAGE_CREATE':
50
55
  {
51
56
  const { d: data } = args[0];
52
- if (args[1].components.values.has(data.interaction?.id ?? '')) {
53
- args[1].components.values.get(data.interaction.id).messageId = data.id;
57
+ if (args[1].components.values.has(data.interaction?.id ?? data.id)) {
58
+ args[1].components.values.get(data.interaction?.id ?? data.id).messageId = data.id;
54
59
  }
55
60
  }
56
61
  break;
@@ -76,6 +81,9 @@ class EventHandler extends common_1.BaseHandler {
76
81
  }
77
82
  break;
78
83
  }
84
+ await this.runEvent(args[0].t, args[1], args[0].d, args[2]);
85
+ }
86
+ async runEvent(name, client, packet, shardId) {
79
87
  const Event = this.values[name];
80
88
  if (!Event) {
81
89
  return;
@@ -85,8 +93,8 @@ class EventHandler extends common_1.BaseHandler {
85
93
  return;
86
94
  }
87
95
  Event.fired = true;
88
- const hook = await RawEvents[args[0].t]?.(args[1], args[0].d);
89
- await Event.run(...[hook, args[1], args[2]]);
96
+ const hook = await RawEvents[name]?.(client, packet);
97
+ await Event.run(...[hook, client, shardId]);
90
98
  }
91
99
  catch (e) {
92
100
  await this.onFail?.(e);
@@ -1,5 +1,6 @@
1
1
  import type { BaseClient } from '../../client/base';
2
- import type { GatewayReadyDispatchData, GatewayResumedDispatch } from '../../common';
2
+ import type { GatewayDispatchPayload, GatewayReadyDispatchData, GatewayResumedDispatch } from '../../common';
3
3
  import { ClientUser } from '../../structures';
4
4
  export declare const READY: (self: BaseClient, data: GatewayReadyDispatchData) => ClientUser;
5
5
  export declare const RESUMED: (_self: BaseClient, _data: GatewayResumedDispatch['d']) => void;
6
+ export declare const RAW: (_self: BaseClient, data: GatewayDispatchPayload) => GatewayDispatchPayload;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RESUMED = exports.READY = void 0;
3
+ exports.RAW = exports.RESUMED = exports.READY = void 0;
4
4
  const structures_1 = require("../../structures");
5
5
  const READY = (self, data) => {
6
6
  return new structures_1.ClientUser(self, data.user, data.application);
@@ -10,3 +10,7 @@ const RESUMED = (_self, _data) => {
10
10
  return;
11
11
  };
12
12
  exports.RESUMED = RESUMED;
13
+ const RAW = (_self, data) => {
14
+ return data;
15
+ };
16
+ exports.RAW = RAW;
@@ -14,22 +14,6 @@ export declare const THREAD_LIST_SYNC: (_self: BaseClient, data: GatewayThreadLi
14
14
  lastMessageId?: string | null | undefined;
15
15
  lastPinTimestamp?: string | null | undefined;
16
16
  recipients?: import("discord-api-types/payloads/v10/user").APIUser[] | undefined;
17
- } | {
18
- bitrate?: number | undefined;
19
- userLimit?: number | undefined;
20
- rtcRegion?: string | null | undefined;
21
- videoQualityMode?: import("discord-api-types/payloads/v10/channel").VideoQualityMode | undefined;
22
- name: string;
23
- guildId?: string | undefined;
24
- permissionOverwrites?: import("discord-api-types/payloads/v10/channel").APIOverwrite[] | undefined;
25
- position: number;
26
- parentId?: string | null | undefined;
27
- nsfw?: boolean | undefined;
28
- type: import("discord-api-types/payloads/v10/channel").ChannelType.GuildVoice;
29
- id: string;
30
- flags?: import("discord-api-types/payloads/v10/channel").ChannelFlags | undefined;
31
- rateLimitPerUser?: number | undefined;
32
- lastMessageId?: string | null | undefined;
33
17
  } | {
34
18
  defaultForumLayout: import("discord-api-types/payloads/v10/channel").ForumLayoutType;
35
19
  topic?: string | null | undefined;
@@ -57,14 +41,10 @@ export declare const THREAD_LIST_SYNC: (_self: BaseClient, data: GatewayThreadLi
57
41
  id: string;
58
42
  flags?: import("discord-api-types/payloads/v10/channel").ChannelFlags | undefined;
59
43
  } | {
60
- member?: import("discord-api-types/payloads/v10/channel").APIThreadMember | undefined;
61
- threadMetadata?: import("discord-api-types/payloads/v10/channel").APIThreadMetadata | undefined;
62
- messageCount?: number | undefined;
63
- memberCount?: number | undefined;
64
- ownerId?: string | undefined;
65
- totalMessageSent?: number | undefined;
66
- appliedTags: string[];
67
- type: import("discord-api-types/payloads/v10/channel").ThreadChannelType;
44
+ defaultAutoArchiveDuration?: import("discord-api-types/payloads/v10/channel").ThreadAutoArchiveDuration | undefined;
45
+ defaultThreadRateLimitPerUser?: number | undefined;
46
+ topic?: string | null | undefined;
47
+ type: import("discord-api-types/payloads/v10/channel").ChannelType.GuildAnnouncement;
68
48
  id: string;
69
49
  rateLimitPerUser?: number | undefined;
70
50
  flags?: import("discord-api-types/payloads/v10/channel").ChannelFlags | undefined;
@@ -76,6 +56,18 @@ export declare const THREAD_LIST_SYNC: (_self: BaseClient, data: GatewayThreadLi
76
56
  position: number;
77
57
  parentId?: string | null | undefined;
78
58
  nsfw?: boolean | undefined;
59
+ } | {
60
+ name: string | null;
61
+ applicationId?: string | undefined;
62
+ icon?: string | null | undefined;
63
+ ownerId?: string | undefined;
64
+ lastMessageId?: string | null | undefined;
65
+ managed?: boolean | undefined;
66
+ type: import("discord-api-types/payloads/v10/channel").ChannelType.GroupDM;
67
+ id: string;
68
+ flags?: import("discord-api-types/payloads/v10/channel").ChannelFlags | undefined;
69
+ lastPinTimestamp?: string | null | undefined;
70
+ recipients?: import("discord-api-types/payloads/v10/user").APIUser[] | undefined;
79
71
  } | {
80
72
  name: string;
81
73
  guildId?: string | undefined;
@@ -87,49 +79,46 @@ export declare const THREAD_LIST_SYNC: (_self: BaseClient, data: GatewayThreadLi
87
79
  id: string;
88
80
  flags?: import("discord-api-types/payloads/v10/channel").ChannelFlags | undefined;
89
81
  } | {
90
- defaultAutoArchiveDuration?: import("discord-api-types/payloads/v10/channel").ThreadAutoArchiveDuration | undefined;
91
- defaultThreadRateLimitPerUser?: number | undefined;
92
82
  topic?: string | null | undefined;
93
- type: import("discord-api-types/payloads/v10/channel").ChannelType.GuildAnnouncement;
94
- id: string;
95
- rateLimitPerUser?: number | undefined;
96
- flags?: import("discord-api-types/payloads/v10/channel").ChannelFlags | undefined;
97
83
  lastMessageId?: string | null | undefined;
84
+ rateLimitPerUser?: number | undefined;
98
85
  lastPinTimestamp?: string | null | undefined;
86
+ defaultAutoArchiveDuration?: import("discord-api-types/payloads/v10/channel").ThreadAutoArchiveDuration | undefined;
87
+ availableTags: {
88
+ id: string;
89
+ name: string;
90
+ moderated: boolean;
91
+ emojiId: string | null;
92
+ emojiName: string | null;
93
+ }[];
94
+ defaultThreadRateLimitPerUser?: number | undefined;
95
+ defaultReactionEmoji: import("discord-api-types/payloads/v10/channel").APIGuildForumDefaultReactionEmoji | null;
96
+ defaultSortOrder: import("discord-api-types/payloads/v10/channel").SortOrderType | null;
99
97
  name: string;
100
98
  guildId?: string | undefined;
101
99
  permissionOverwrites?: import("discord-api-types/payloads/v10/channel").APIOverwrite[] | undefined;
102
100
  position: number;
103
101
  parentId?: string | null | undefined;
104
102
  nsfw?: boolean | undefined;
105
- } | {
106
- name: string | null;
107
- applicationId?: string | undefined;
108
- icon?: string | null | undefined;
109
- ownerId?: string | undefined;
110
- lastMessageId?: string | null | undefined;
111
- managed?: boolean | undefined;
112
- type: import("discord-api-types/payloads/v10/channel").ChannelType.GroupDM;
103
+ type: import("discord-api-types/payloads/v10/channel").ChannelType.GuildMedia;
113
104
  id: string;
114
105
  flags?: import("discord-api-types/payloads/v10/channel").ChannelFlags | undefined;
115
- lastPinTimestamp?: string | null | undefined;
116
- recipients?: import("discord-api-types/payloads/v10/user").APIUser[] | undefined;
117
106
  } | {
118
- defaultAutoArchiveDuration?: import("discord-api-types/payloads/v10/channel").ThreadAutoArchiveDuration | undefined;
119
- defaultThreadRateLimitPerUser?: number | undefined;
120
- topic?: string | null | undefined;
121
- type: import("discord-api-types/payloads/v10/channel").ChannelType.GuildText;
122
- id: string;
123
- rateLimitPerUser?: number | undefined;
124
- flags?: import("discord-api-types/payloads/v10/channel").ChannelFlags | undefined;
125
- lastMessageId?: string | null | undefined;
126
- lastPinTimestamp?: string | null | undefined;
107
+ bitrate?: number | undefined;
108
+ userLimit?: number | undefined;
109
+ rtcRegion?: string | null | undefined;
110
+ videoQualityMode?: import("discord-api-types/payloads/v10/channel").VideoQualityMode | undefined;
127
111
  name: string;
128
112
  guildId?: string | undefined;
129
113
  permissionOverwrites?: import("discord-api-types/payloads/v10/channel").APIOverwrite[] | undefined;
130
114
  position: number;
131
115
  parentId?: string | null | undefined;
132
116
  nsfw?: boolean | undefined;
117
+ type: import("discord-api-types/payloads/v10/channel").ChannelType.GuildStageVoice;
118
+ id: string;
119
+ flags?: import("discord-api-types/payloads/v10/channel").ChannelFlags | undefined;
120
+ rateLimitPerUser?: number | undefined;
121
+ lastMessageId?: string | null | undefined;
133
122
  } | {
134
123
  bitrate?: number | undefined;
135
124
  userLimit?: number | undefined;
@@ -141,36 +130,47 @@ export declare const THREAD_LIST_SYNC: (_self: BaseClient, data: GatewayThreadLi
141
130
  position: number;
142
131
  parentId?: string | null | undefined;
143
132
  nsfw?: boolean | undefined;
144
- type: import("discord-api-types/payloads/v10/channel").ChannelType.GuildStageVoice;
133
+ type: import("discord-api-types/payloads/v10/channel").ChannelType.GuildVoice;
145
134
  id: string;
146
135
  flags?: import("discord-api-types/payloads/v10/channel").ChannelFlags | undefined;
147
136
  rateLimitPerUser?: number | undefined;
148
137
  lastMessageId?: string | null | undefined;
149
138
  } | {
139
+ defaultAutoArchiveDuration?: import("discord-api-types/payloads/v10/channel").ThreadAutoArchiveDuration | undefined;
140
+ defaultThreadRateLimitPerUser?: number | undefined;
150
141
  topic?: string | null | undefined;
151
- lastMessageId?: string | null | undefined;
142
+ type: import("discord-api-types/payloads/v10/channel").ChannelType.GuildText;
143
+ id: string;
152
144
  rateLimitPerUser?: number | undefined;
145
+ flags?: import("discord-api-types/payloads/v10/channel").ChannelFlags | undefined;
146
+ lastMessageId?: string | null | undefined;
153
147
  lastPinTimestamp?: string | null | undefined;
154
- defaultAutoArchiveDuration?: import("discord-api-types/payloads/v10/channel").ThreadAutoArchiveDuration | undefined;
155
- availableTags: {
156
- id: string;
157
- name: string;
158
- moderated: boolean;
159
- emojiId: string | null;
160
- emojiName: string | null;
161
- }[];
162
- defaultThreadRateLimitPerUser?: number | undefined;
163
- defaultReactionEmoji: import("discord-api-types/payloads/v10/channel").APIGuildForumDefaultReactionEmoji | null;
164
- defaultSortOrder: import("discord-api-types/payloads/v10/channel").SortOrderType | null;
165
148
  name: string;
166
149
  guildId?: string | undefined;
167
150
  permissionOverwrites?: import("discord-api-types/payloads/v10/channel").APIOverwrite[] | undefined;
168
151
  position: number;
169
152
  parentId?: string | null | undefined;
170
153
  nsfw?: boolean | undefined;
171
- type: import("discord-api-types/payloads/v10/channel").ChannelType.GuildMedia;
154
+ } | {
155
+ member?: import("discord-api-types/payloads/v10/channel").APIThreadMember | undefined;
156
+ threadMetadata?: import("discord-api-types/payloads/v10/channel").APIThreadMetadata | undefined;
157
+ messageCount?: number | undefined;
158
+ memberCount?: number | undefined;
159
+ ownerId?: string | undefined;
160
+ totalMessageSent?: number | undefined;
161
+ appliedTags: string[];
162
+ type: import("discord-api-types/payloads/v10/channel").ThreadChannelType;
172
163
  id: string;
164
+ rateLimitPerUser?: number | undefined;
173
165
  flags?: import("discord-api-types/payloads/v10/channel").ChannelFlags | undefined;
166
+ lastMessageId?: string | null | undefined;
167
+ lastPinTimestamp?: string | null | undefined;
168
+ name: string;
169
+ guildId?: string | undefined;
170
+ permissionOverwrites?: import("discord-api-types/payloads/v10/channel").APIOverwrite[] | undefined;
171
+ position: number;
172
+ parentId?: string | null | undefined;
173
+ nsfw?: boolean | undefined;
174
174
  })[];
175
175
  members: {
176
176
  id?: string | undefined;
package/lib/index.d.ts CHANGED
@@ -1,15 +1,18 @@
1
1
  import type { InternalRuntimeConfig, InternalRuntimeConfigHTTP, RuntimeConfig, RuntimeConfigHTTP } from './client/base';
2
2
  import type { ClientNameEvents, EventContext } from './events';
3
3
  import type { ChatInputCommandInteraction, MessageCommandInteraction, UserCommandInteraction } from './structures';
4
+ export { Logger, PermissionFlagsBits, PermissionStrings, Watcher } from './common';
5
+ export { Collection, LimitedCollection } from './collection';
4
6
  export * from './api';
5
7
  export * from './builders';
6
- export * from './client';
8
+ export * from './cache';
7
9
  export * from './commands';
8
- export { Logger, Watcher } from './common';
9
- export { ComponentCommand, ComponentsListener, ModalCommand } from './components';
10
- export type { ParseLocales } from './langs';
11
- export * from './structures';
10
+ export * from './components';
11
+ export * from './events';
12
+ export * from './langs';
12
13
  export { ShardManager, WorkerManager } from './websocket/discord';
14
+ export * from './structures';
15
+ export * from './client';
13
16
  export declare function throwError(msg: string): never;
14
17
  /**
15
18
  * Creates an event with the specified data and run function.