seyfert 1.3.3 → 1.5.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 (138) hide show
  1. package/README.md +7 -7
  2. package/lib/api/Router.js +3 -1
  3. package/lib/api/Routes/guilds.d.ts +4 -1
  4. package/lib/api/api.js +13 -7
  5. package/lib/builders/Attachment.d.ts +1 -4
  6. package/lib/builders/Attachment.js +4 -4
  7. package/lib/cache/adapters/workeradapter.js +7 -3
  8. package/lib/cache/index.d.ts +6 -2
  9. package/lib/cache/index.js +18 -0
  10. package/lib/cache/resources/bans.d.ts +12 -0
  11. package/lib/cache/resources/bans.js +35 -0
  12. package/lib/cache/resources/default/base.d.ts +1 -2
  13. package/lib/cache/resources/default/guild-based.d.ts +1 -2
  14. package/lib/cache/resources/members.js +4 -4
  15. package/lib/cache/resources/messages.js +8 -6
  16. package/lib/client/base.d.ts +33 -7
  17. package/lib/client/base.js +80 -21
  18. package/lib/client/client.d.ts +18 -6
  19. package/lib/client/client.js +45 -37
  20. package/lib/client/collectors.d.ts +36 -0
  21. package/lib/client/collectors.js +85 -0
  22. package/lib/client/httpclient.d.ts +7 -8
  23. package/lib/client/httpclient.js +96 -17
  24. package/lib/client/oninteractioncreate.d.ts +2 -2
  25. package/lib/client/oninteractioncreate.js +15 -7
  26. package/lib/client/onmessagecreate.d.ts +12 -2
  27. package/lib/client/onmessagecreate.js +105 -82
  28. package/lib/client/workerclient.d.ts +5 -2
  29. package/lib/client/workerclient.js +66 -63
  30. package/lib/collection.d.ts +2 -2
  31. package/lib/collection.js +2 -2
  32. package/lib/commands/applications/chat.d.ts +11 -10
  33. package/lib/commands/applications/chat.js +23 -8
  34. package/lib/commands/applications/chatcontext.d.ts +1 -1
  35. package/lib/commands/applications/chatcontext.js +2 -2
  36. package/lib/commands/applications/menu.d.ts +8 -7
  37. package/lib/commands/applications/menu.js +3 -50
  38. package/lib/commands/applications/menucontext.d.ts +1 -1
  39. package/lib/commands/applications/menucontext.js +3 -3
  40. package/lib/commands/applications/options.d.ts +3 -1
  41. package/lib/commands/applications/shared.d.ts +12 -0
  42. package/lib/commands/basecontext.d.ts +26 -0
  43. package/lib/commands/{basecontex.js → basecontext.js} +24 -0
  44. package/lib/commands/decorators.d.ts +11 -17
  45. package/lib/commands/decorators.js +7 -14
  46. package/lib/commands/handler.d.ts +6 -1
  47. package/lib/commands/handler.js +161 -29
  48. package/lib/common/bot/watcher.d.ts +1 -2
  49. package/lib/common/bot/watcher.js +9 -4
  50. package/lib/common/index.d.ts +1 -0
  51. package/lib/common/index.js +3 -1
  52. package/lib/common/it/formatter.d.ts +155 -0
  53. package/lib/common/it/formatter.js +184 -0
  54. package/lib/common/it/logger.d.ts +1 -1
  55. package/lib/common/it/logger.js +14 -13
  56. package/lib/common/it/utils.d.ts +2 -0
  57. package/lib/common/it/utils.js +21 -9
  58. package/lib/common/shorters/bans.d.ts +43 -0
  59. package/lib/common/shorters/bans.js +78 -0
  60. package/lib/common/shorters/emojis.d.ts +1 -1
  61. package/lib/common/shorters/emojis.js +4 -3
  62. package/lib/common/shorters/interaction.js +9 -7
  63. package/lib/common/shorters/messages.js +2 -2
  64. package/lib/common/shorters/webhook.js +2 -2
  65. package/lib/components/componentcommand.d.ts +22 -0
  66. package/lib/components/{command.js → componentcommand.js} +3 -5
  67. package/lib/components/componentcontext.d.ts +20 -16
  68. package/lib/components/componentcontext.js +27 -9
  69. package/lib/components/handler.d.ts +11 -6
  70. package/lib/components/handler.js +106 -32
  71. package/lib/components/index.d.ts +3 -1
  72. package/lib/components/index.js +3 -1
  73. package/lib/components/modalcommand.d.ts +16 -0
  74. package/lib/components/modalcommand.js +10 -0
  75. package/lib/components/modalcontext.d.ts +104 -0
  76. package/lib/components/modalcontext.js +132 -0
  77. package/lib/events/event.d.ts +4 -3
  78. package/lib/events/handler.d.ts +12 -6
  79. package/lib/events/handler.js +60 -20
  80. package/lib/events/hooks/application_command.d.ts +2 -2
  81. package/lib/events/hooks/auto_moderation.d.ts +5 -5
  82. package/lib/events/hooks/channel.d.ts +5 -5
  83. package/lib/events/hooks/custom.d.ts +3 -3
  84. package/lib/events/hooks/dispatch.d.ts +4 -4
  85. package/lib/events/hooks/entitlement.d.ts +4 -4
  86. package/lib/events/hooks/guild.d.ts +41 -96
  87. package/lib/events/hooks/guild.js +6 -6
  88. package/lib/events/hooks/integration.d.ts +61 -4
  89. package/lib/events/hooks/interactions.d.ts +2 -2
  90. package/lib/events/hooks/invite.d.ts +6 -3
  91. package/lib/events/hooks/message.d.ts +23 -18
  92. package/lib/events/hooks/message.js +1 -1
  93. package/lib/events/hooks/presence.d.ts +11 -3
  94. package/lib/events/hooks/presence.js +2 -2
  95. package/lib/events/hooks/stage.d.ts +7 -13
  96. package/lib/events/hooks/stage.js +2 -2
  97. package/lib/events/hooks/thread.d.ts +21 -10
  98. package/lib/events/hooks/thread.js +2 -2
  99. package/lib/events/hooks/typing.d.ts +3 -2
  100. package/lib/events/hooks/user.d.ts +2 -2
  101. package/lib/events/hooks/user.js +2 -2
  102. package/lib/events/hooks/voice.d.ts +5 -45
  103. package/lib/events/hooks/voice.js +4 -7
  104. package/lib/events/hooks/webhook.d.ts +2 -2
  105. package/lib/index.d.ts +4 -4
  106. package/lib/index.js +11 -5
  107. package/lib/langs/handler.d.ts +4 -1
  108. package/lib/langs/handler.js +3 -3
  109. package/lib/structures/Guild.d.ts +9 -1
  110. package/lib/structures/Guild.js +2 -0
  111. package/lib/structures/GuildBan.d.ts +25 -0
  112. package/lib/structures/GuildBan.js +36 -0
  113. package/lib/structures/GuildEmoji.d.ts +1 -1
  114. package/lib/structures/GuildMember.d.ts +7 -2
  115. package/lib/structures/GuildMember.js +4 -4
  116. package/lib/structures/Interaction.d.ts +4 -3
  117. package/lib/structures/Interaction.js +29 -12
  118. package/lib/structures/Message.d.ts +69 -8
  119. package/lib/structures/Message.js +59 -17
  120. package/lib/structures/Sticker.d.ts +3 -3
  121. package/lib/structures/User.d.ts +1 -0
  122. package/lib/structures/User.js +4 -1
  123. package/lib/structures/VoiceState.d.ts +6 -5
  124. package/lib/structures/VoiceState.js +6 -3
  125. package/lib/structures/channels.d.ts +4 -1
  126. package/lib/structures/channels.js +37 -6
  127. package/lib/structures/extra/functions.js +1 -1
  128. package/lib/websocket/discord/basesocket.d.ts +1 -0
  129. package/lib/websocket/discord/basesocket.js +17 -0
  130. package/lib/websocket/discord/shard.d.ts +1 -0
  131. package/lib/websocket/discord/shard.js +6 -0
  132. package/lib/websocket/discord/sharder.js +10 -3
  133. package/lib/websocket/discord/shared.d.ts +1 -0
  134. package/lib/websocket/discord/workermanager.d.ts +2 -3
  135. package/lib/websocket/discord/workermanager.js +4 -2
  136. package/package.json +7 -7
  137. package/lib/commands/basecontex.d.ts +0 -15
  138. package/lib/components/command.d.ts +0 -24
@@ -7,7 +7,7 @@ const base_1 = require("./base");
7
7
  class MessageShorter extends base_1.BaseShorter {
8
8
  async write(channelId, { files, ...body }) {
9
9
  const parsedFiles = files ? await (0, builders_1.resolveFiles)(files) : [];
10
- const transformedBody = structures_1.MessagesMethods.transformMessageBody(body);
10
+ const transformedBody = structures_1.MessagesMethods.transformMessageBody(body, parsedFiles, this.client);
11
11
  return this.client.proxy
12
12
  .channels(channelId)
13
13
  .messages.post({
@@ -25,7 +25,7 @@ class MessageShorter extends base_1.BaseShorter {
25
25
  .channels(channelId)
26
26
  .messages(messageId)
27
27
  .patch({
28
- body: structures_1.MessagesMethods.transformMessageBody(body),
28
+ body: structures_1.MessagesMethods.transformMessageBody(body, parsedFiles, this.client),
29
29
  files: parsedFiles,
30
30
  })
31
31
  .then(async (message) => {
@@ -67,8 +67,8 @@ class WebhookShorter extends base_1.BaseShorter {
67
67
  */
68
68
  async writeMessage(webhookId, token, { body: data, ...payload }) {
69
69
  const { files, ...body } = data;
70
- const transformedBody = structures_1.MessagesMethods.transformMessageBody(body);
71
70
  const parsedFiles = files ? await (0, builders_1.resolveFiles)(files) : [];
71
+ const transformedBody = structures_1.MessagesMethods.transformMessageBody(body, parsedFiles, this.client);
72
72
  return this.client.proxy
73
73
  .webhooks(webhookId)(token)
74
74
  .post({ ...payload, files: parsedFiles, body: transformedBody })
@@ -84,8 +84,8 @@ class WebhookShorter extends base_1.BaseShorter {
84
84
  */
85
85
  async editMessage(webhookId, token, { messageId, body: data, ...json }) {
86
86
  const { files, ...body } = data;
87
- const transformedBody = structures_1.MessagesMethods.transformMessageBody(body);
88
87
  const parsedFiles = files ? await (0, builders_1.resolveFiles)(files) : [];
88
+ const transformedBody = structures_1.MessagesMethods.transformMessageBody(body, parsedFiles, this.client);
89
89
  return this.client.proxy
90
90
  .webhooks(webhookId)(token)
91
91
  .messages(messageId)
@@ -0,0 +1,22 @@
1
+ import type { ContextComponentCommandInteractionMap, ComponentContext } from './componentcontext';
2
+ import type { ExtraProps, RegisteredMiddlewares, UsingClient } from '../commands';
3
+ export declare const InteractionCommandType: {
4
+ readonly COMPONENT: 0;
5
+ readonly MODAL: 1;
6
+ };
7
+ export interface ComponentCommand {
8
+ __filePath?: string;
9
+ }
10
+ export declare abstract class ComponentCommand {
11
+ type: 0;
12
+ abstract componentType: keyof ContextComponentCommandInteractionMap;
13
+ abstract filter(context: ComponentContext<typeof this.componentType>): Promise<boolean> | boolean;
14
+ abstract run(context: ComponentContext<typeof this.componentType>): any;
15
+ middlewares: (keyof RegisteredMiddlewares)[];
16
+ props: ExtraProps;
17
+ get cType(): number;
18
+ onAfterRun?(context: ComponentContext, error: unknown | undefined): any;
19
+ onRunError?(context: ComponentContext, error: unknown): any;
20
+ onMiddlewaresError?(context: ComponentContext, error: string): any;
21
+ onInternalError?(client: UsingClient, error?: unknown): any;
22
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ModalCommand = exports.ComponentCommand = exports.InteractionCommandType = void 0;
3
+ exports.ComponentCommand = exports.InteractionCommandType = void 0;
4
4
  const v10_1 = require("discord-api-types/v10");
5
5
  exports.InteractionCommandType = {
6
6
  COMPONENT: 0,
@@ -8,12 +8,10 @@ exports.InteractionCommandType = {
8
8
  };
9
9
  class ComponentCommand {
10
10
  type = exports.InteractionCommandType.COMPONENT;
11
+ middlewares = [];
12
+ props;
11
13
  get cType() {
12
14
  return v10_1.ComponentType[this.componentType];
13
15
  }
14
16
  }
15
17
  exports.ComponentCommand = ComponentCommand;
16
- class ModalCommand {
17
- type = exports.InteractionCommandType.MODAL;
18
- }
19
- exports.ModalCommand = ModalCommand;
@@ -1,26 +1,25 @@
1
- import type { AllChannels, ButtonInteraction, ChannelSelectMenuInteraction, ComponentInteraction, Guild, GuildMember, MentionableSelectMenuInteraction, Message, ReturnCache, RoleSelectMenuInteraction, StringSelectMenuInteraction, UserSelectMenuInteraction, WebhookMessage } from '..';
2
- import type { ExtendContext, UsingClient } from '../commands';
3
- import { BaseContext } from '../commands/basecontex';
4
- import type { ComponentInteractionMessageUpdate, InteractionCreateBodyRequest, InteractionMessageUpdateBodyRequest, When } from '../common';
5
- export interface ComponentContext<Type extends keyof ComponentCommandInteractionMap> extends BaseContext, ExtendContext {
1
+ import type { AllChannels, ButtonInteraction, ChannelSelectMenuInteraction, ComponentCommand, Guild, GuildMember, MentionableSelectMenuInteraction, Message, ReturnCache, RoleSelectMenuInteraction, StringSelectMenuInteraction, UserSelectMenuInteraction, WebhookMessage } from '..';
2
+ import type { CommandMetadata, ExtendContext, GlobalMetadata, RegisteredMiddlewares, UsingClient } from '../commands';
3
+ import { BaseContext } from '../commands/basecontext';
4
+ import type { ComponentInteractionMessageUpdate, InteractionCreateBodyRequest, InteractionMessageUpdateBodyRequest, ModalCreateBodyRequest, UnionToTuple, When } from '../common';
5
+ export interface ComponentContext<Type extends keyof ContextComponentCommandInteractionMap = keyof ContextComponentCommandInteractionMap> extends BaseContext, ExtendContext {
6
6
  }
7
7
  /**
8
8
  * Represents a context for interacting with components in a Discord bot.
9
9
  * @template Type - The type of component interaction.
10
10
  */
11
- export declare class ComponentContext<Type extends keyof ComponentCommandInteractionMap> extends BaseContext {
11
+ export declare class ComponentContext<Type extends keyof ContextComponentCommandInteractionMap, M extends keyof RegisteredMiddlewares = never> extends BaseContext {
12
12
  readonly client: UsingClient;
13
- interaction: ComponentCommandInteractionMap[Type] | ComponentInteraction;
13
+ interaction: ContextComponentCommandInteractionMap[Type];
14
14
  /**
15
15
  * Creates a new instance of the ComponentContext class.
16
16
  * @param client - The UsingClient instance.
17
17
  * @param interaction - The component interaction object.
18
18
  */
19
- constructor(client: UsingClient, interaction: ComponentCommandInteractionMap[Type] | ComponentInteraction);
20
- /**
21
- * Gets the proxy object.
22
- */
23
- get proxy(): import("..").APIRoutes;
19
+ constructor(client: UsingClient, interaction: ContextComponentCommandInteractionMap[Type]);
20
+ command: ComponentCommand;
21
+ metadata: CommandMetadata<UnionToTuple<M>>;
22
+ globalMetadata: GlobalMetadata;
24
23
  /**
25
24
  * Gets the language object for the interaction's locale.
26
25
  */
@@ -63,6 +62,7 @@ export declare class ComponentContext<Type extends keyof ComponentCommandInterac
63
62
  * @returns A promise that resolves when the response is deleted.
64
63
  */
65
64
  deleteResponse(): Promise<void | undefined>;
65
+ modal(body: ModalCreateBodyRequest): Promise<void>;
66
66
  /**
67
67
  * Gets the channel of the interaction.
68
68
  * @param mode - The mode to fetch the channel.
@@ -100,13 +100,17 @@ export declare class ComponentContext<Type extends keyof ComponentCommandInterac
100
100
  * Gets the member of the interaction.
101
101
  */
102
102
  get member(): import("..").InteractionGuildMember | undefined;
103
- isComponent(): this is ComponentContext<keyof ComponentCommandInteractionMap>;
103
+ isComponent(): this is ComponentContext<keyof ContextComponentCommandInteractionMap>;
104
+ isButton(): this is ComponentContext<'Button'>;
105
+ isChannelSelectMenu(): this is ComponentContext<'ChannelSelect'>;
106
+ isRoleSelectMenu(): this is ComponentContext<'RoleSelect'>;
107
+ isMentionableSelectMenu(): this is ComponentContext<'MentionableSelect'>;
108
+ isUserSelectMenu(): this is ComponentContext<'UserSelect'>;
109
+ isStringSelectMenu(): this is ComponentContext<'StringSelect'>;
104
110
  }
105
- export interface ComponentCommandInteractionMap {
106
- ActionRow: never;
111
+ export interface ContextComponentCommandInteractionMap {
107
112
  Button: ButtonInteraction;
108
113
  StringSelect: StringSelectMenuInteraction;
109
- TextInput: never;
110
114
  UserSelect: UserSelectMenuInteraction;
111
115
  RoleSelect: RoleSelectMenuInteraction;
112
116
  MentionableSelect: MentionableSelectMenuInteraction;
@@ -2,12 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ComponentContext = void 0;
4
4
  const v10_1 = require("discord-api-types/v10");
5
- const basecontex_1 = require("../commands/basecontex");
5
+ const basecontext_1 = require("../commands/basecontext");
6
6
  /**
7
7
  * Represents a context for interacting with components in a Discord bot.
8
8
  * @template Type - The type of component interaction.
9
9
  */
10
- class ComponentContext extends basecontex_1.BaseContext {
10
+ class ComponentContext extends basecontext_1.BaseContext {
11
11
  client;
12
12
  interaction;
13
13
  /**
@@ -20,17 +20,14 @@ class ComponentContext extends basecontex_1.BaseContext {
20
20
  this.client = client;
21
21
  this.interaction = interaction;
22
22
  }
23
- /**
24
- * Gets the proxy object.
25
- */
26
- get proxy() {
27
- return this.client.proxy;
28
- }
23
+ command;
24
+ metadata = {};
25
+ globalMetadata = {};
29
26
  /**
30
27
  * Gets the language object for the interaction's locale.
31
28
  */
32
29
  get t() {
33
- return this.client.langs.get(this.interaction?.locale ?? this.client.langs?.defaultLang ?? 'en-US');
30
+ return this.client.t(this.interaction?.locale ?? this.client.langs?.defaultLang ?? 'en-US');
34
31
  }
35
32
  /**
36
33
  * Gets the custom ID of the interaction.
@@ -82,6 +79,9 @@ class ComponentContext extends basecontex_1.BaseContext {
82
79
  deleteResponse() {
83
80
  return this.interaction.deleteResponse();
84
81
  }
82
+ modal(body) {
83
+ return this.interaction.modal(body);
84
+ }
85
85
  channel(mode = 'cache') {
86
86
  if (this.interaction?.channel && mode === 'cache')
87
87
  return this.client.cache.adapter.isAsync ? Promise.resolve(this.interaction.channel) : this.interaction.channel;
@@ -134,5 +134,23 @@ class ComponentContext extends basecontex_1.BaseContext {
134
134
  isComponent() {
135
135
  return true;
136
136
  }
137
+ isButton() {
138
+ return this.interaction.data.componentType === v10_1.ComponentType.Button;
139
+ }
140
+ isChannelSelectMenu() {
141
+ return this.interaction.componentType === v10_1.ComponentType.ChannelSelect;
142
+ }
143
+ isRoleSelectMenu() {
144
+ return this.interaction.componentType === v10_1.ComponentType.RoleSelect;
145
+ }
146
+ isMentionableSelectMenu() {
147
+ return this.interaction.componentType === v10_1.ComponentType.MentionableSelect;
148
+ }
149
+ isUserSelectMenu() {
150
+ return this.interaction.componentType === v10_1.ComponentType.UserSelect;
151
+ }
152
+ isStringSelectMenu() {
153
+ return this.interaction.componentType === v10_1.ComponentType.StringSelect;
154
+ }
137
155
  }
138
156
  exports.ComponentContext = ComponentContext;
@@ -1,10 +1,13 @@
1
1
  /// <reference types="node" />
2
2
  import type { ComponentCallback, ListenerOptions, ModalSubmitCallback } from '../builders/types';
3
3
  import { LimitedCollection } from '../collection';
4
- import type { UsingClient } from '../commands';
4
+ import { type UsingClient } from '../commands';
5
5
  import { BaseHandler, type Logger, type OnFailCallback } from '../common';
6
6
  import type { ComponentInteraction, ModalSubmitInteraction, StringSelectMenuInteraction } from '../structures';
7
- import { ComponentCommand, ModalCommand } from './command';
7
+ import { ComponentCommand } from './componentcommand';
8
+ import type { ComponentContext } from './componentcontext';
9
+ import { ModalCommand } from './modalcommand';
10
+ import type { ModalContext } from './modalcontext';
8
11
  type COMPONENTS = {
9
12
  components: {
10
13
  match: string | string[] | RegExp;
@@ -35,11 +38,13 @@ export declare class ComponentHandler extends BaseHandler {
35
38
  onModalSubmit(interaction: ModalSubmitInteraction): any;
36
39
  deleteValue(id: string, reason?: string): void;
37
40
  onMessageDelete(id: string): void;
38
- load(componentsDir: string): Promise<void>;
41
+ load(componentsDir: string, instances?: {
42
+ new (): ModalCommand | ComponentCommand;
43
+ }[]): Promise<void>;
39
44
  reload(path: string): Promise<any>;
40
- reloadAll(): Promise<void>;
41
- executeComponent(interaction: ComponentInteraction): Promise<void>;
42
- executeModal(interaction: ModalSubmitInteraction): Promise<void>;
45
+ reloadAll(stopIfFail?: boolean): Promise<void>;
46
+ executeComponent(context: ComponentContext): Promise<any>;
47
+ executeModal(context: ModalContext): Promise<any>;
43
48
  setHandlers({ callback }: {
44
49
  callback: ComponentHandler['callback'];
45
50
  }): void;
@@ -2,9 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ComponentHandler = void 0;
4
4
  const collection_1 = require("../collection");
5
+ const commands_1 = require("../commands");
5
6
  const common_1 = require("../common");
6
- const command_1 = require("./command");
7
- const componentcontext_1 = require("./componentcontext");
7
+ const componentcommand_1 = require("./componentcommand");
8
+ const modalcommand_1 = require("./modalcommand");
8
9
  class ComponentHandler extends common_1.BaseHandler {
9
10
  client;
10
11
  onFail = err => this.logger.warn('<Client>.components.onFail', err);
@@ -21,7 +22,7 @@ class ComponentHandler extends common_1.BaseHandler {
21
22
  this.values.set(messageId, {
22
23
  components: [],
23
24
  options,
24
- idle: options.idle
25
+ idle: options.idle && options.idle > 0
25
26
  ? setTimeout(() => {
26
27
  this.deleteValue(messageId);
27
28
  options.onStop?.('idle', () => {
@@ -29,7 +30,7 @@ class ComponentHandler extends common_1.BaseHandler {
29
30
  });
30
31
  }, options.idle)
31
32
  : undefined,
32
- timeout: options.timeout
33
+ timeout: options.timeout && options.timeout > 0
33
34
  ? setTimeout(() => {
34
35
  this.deleteValue(messageId);
35
36
  options.onStop?.('timeout', () => {
@@ -116,29 +117,38 @@ class ComponentHandler extends common_1.BaseHandler {
116
117
  onMessageDelete(id) {
117
118
  this.deleteValue(id, 'messageDelete');
118
119
  }
119
- async load(componentsDir) {
120
- const paths = await this.loadFilesK(await this.getFiles(componentsDir));
121
- for (let i = 0; i < paths.length; i++) {
120
+ async load(componentsDir, instances) {
121
+ const paths = instances?.map(x => {
122
+ const i = new x();
123
+ return { file: x, path: i.__filePath ?? '*' };
124
+ }) ?? (await this.loadFilesK(await this.getFiles(componentsDir)));
125
+ for (const value of paths) {
122
126
  let component;
123
127
  try {
124
- component = this.callback(paths[i].file);
128
+ component = this.callback(value.file);
125
129
  if (!component)
126
130
  continue;
127
131
  }
128
132
  catch (e) {
129
- if (e instanceof Error && e.message === 'paths[i].file is not a constructor') {
130
- this.logger.warn(`${paths[i].path
133
+ if (e instanceof Error && e.message.includes('is not a constructor')) {
134
+ this.logger.warn(`${value.path
131
135
  .split(process.cwd())
132
136
  .slice(1)
133
137
  .join(process.cwd())} doesn't export the class by \`export default <ComponentCommand>\``);
134
138
  }
135
139
  else
136
- this.logger.warn(e, paths[i]);
140
+ this.logger.warn(e, value);
137
141
  continue;
138
142
  }
139
- if (!(component instanceof command_1.ModalCommand) && !(component instanceof command_1.ComponentCommand))
143
+ if (!(component instanceof modalcommand_1.ModalCommand || component instanceof componentcommand_1.ComponentCommand))
140
144
  continue;
141
- component.__filePath = paths[i].path;
145
+ component.props ??= this.client.options.commands?.defaults?.props ?? {};
146
+ const is = component instanceof modalcommand_1.ModalCommand ? 'modals' : 'components';
147
+ component.onInternalError ??= this.client.options?.[is]?.defaults?.onInternalError;
148
+ component.onMiddlewaresError ??= this.client.options?.[is]?.defaults?.onMiddlewaresError;
149
+ component.onRunError ??= this.client.options?.[is]?.defaults?.onRunError;
150
+ component.onAfterRun ??= this.client.options?.[is]?.defaults?.onAfterRun;
151
+ component.__filePath = value.path;
142
152
  this.commands.push(component);
143
153
  }
144
154
  }
@@ -149,7 +159,7 @@ class ComponentHandler extends common_1.BaseHandler {
149
159
  x.__filePath?.endsWith(`${path}.ts`) ||
150
160
  x.__filePath?.endsWith(path) ||
151
161
  x.__filePath === path);
152
- if (!component || !component.__filePath)
162
+ if (!component?.__filePath)
153
163
  return null;
154
164
  delete require.cache[component.__filePath];
155
165
  const index = this.client.components.commands.findIndex(x => x.__filePath === component.__filePath);
@@ -162,25 +172,57 @@ class ComponentHandler extends common_1.BaseHandler {
162
172
  this.client.components.commands.push(command);
163
173
  return imported;
164
174
  }
165
- async reloadAll() {
166
- if (!this.client.components)
167
- return;
168
- for (const i of this.client.components.commands) {
169
- if (!i.__filePath)
170
- return this.logger.warn('Unknown command dont have __filePath property', i);
171
- await this.reload(i.__filePath);
175
+ async reloadAll(stopIfFail = true) {
176
+ for (const i of this.commands) {
177
+ try {
178
+ await this.reload(i.__filePath ?? '');
179
+ }
180
+ catch (e) {
181
+ if (stopIfFail) {
182
+ throw e;
183
+ }
184
+ }
172
185
  }
173
186
  }
174
- async executeComponent(interaction) {
187
+ async executeComponent(context) {
175
188
  for (const i of this.commands) {
176
189
  try {
177
- if (i.type === command_1.InteractionCommandType.COMPONENT && i.cType === interaction.componentType) {
178
- const context = new componentcontext_1.ComponentContext(this.client, interaction);
179
- const extended = this.client.options?.context?.(interaction) ?? {};
180
- Object.assign(context, extended);
181
- if (!(await i.filter(context)))
182
- continue;
183
- await i.run(context);
190
+ if (i.type === componentcommand_1.InteractionCommandType.COMPONENT &&
191
+ i.cType === context.interaction.componentType &&
192
+ (await i.filter(context))) {
193
+ context.command = i;
194
+ try {
195
+ const resultRunGlobalMiddlewares = await commands_1.BaseCommand.__runMiddlewares(context, (context.client.options?.globalMiddlewares ?? []), true);
196
+ if (resultRunGlobalMiddlewares.pass) {
197
+ return;
198
+ }
199
+ if ('error' in resultRunGlobalMiddlewares) {
200
+ return i.onMiddlewaresError?.(context, resultRunGlobalMiddlewares.error ?? 'Unknown error');
201
+ }
202
+ const resultRunMiddlewares = await commands_1.BaseCommand.__runMiddlewares(context, i.middlewares, false);
203
+ if (resultRunMiddlewares.pass) {
204
+ return;
205
+ }
206
+ if ('error' in resultRunMiddlewares) {
207
+ return i.onMiddlewaresError?.(context, resultRunMiddlewares.error ?? 'Unknown error');
208
+ }
209
+ try {
210
+ await i.run(context);
211
+ await i.onAfterRun?.(context, undefined);
212
+ }
213
+ catch (error) {
214
+ await i.onRunError?.(context, error);
215
+ await i.onAfterRun?.(context, error);
216
+ }
217
+ }
218
+ catch (error) {
219
+ try {
220
+ await i.onInternalError?.(this.client, error);
221
+ }
222
+ catch {
223
+ // supress error
224
+ }
225
+ }
184
226
  break;
185
227
  }
186
228
  }
@@ -189,11 +231,43 @@ class ComponentHandler extends common_1.BaseHandler {
189
231
  }
190
232
  }
191
233
  }
192
- async executeModal(interaction) {
234
+ async executeModal(context) {
193
235
  for (const i of this.commands) {
194
236
  try {
195
- if (i.type === command_1.InteractionCommandType.MODAL && (await i.filter(interaction))) {
196
- await i.run(interaction);
237
+ if (i.type === componentcommand_1.InteractionCommandType.MODAL && (await i.filter(context))) {
238
+ context.command = i;
239
+ try {
240
+ const resultRunGlobalMiddlewares = await commands_1.BaseCommand.__runMiddlewares(context, (context.client.options?.globalMiddlewares ?? []), true);
241
+ if (resultRunGlobalMiddlewares.pass) {
242
+ return;
243
+ }
244
+ if ('error' in resultRunGlobalMiddlewares) {
245
+ return i.onMiddlewaresError?.(context, resultRunGlobalMiddlewares.error ?? 'Unknown error');
246
+ }
247
+ const resultRunMiddlewares = await commands_1.BaseCommand.__runMiddlewares(context, i.middlewares, false);
248
+ if (resultRunMiddlewares.pass) {
249
+ return;
250
+ }
251
+ if ('error' in resultRunMiddlewares) {
252
+ return i.onMiddlewaresError?.(context, resultRunMiddlewares.error ?? 'Unknown error');
253
+ }
254
+ try {
255
+ await i.run(context);
256
+ await i.onAfterRun?.(context, undefined);
257
+ }
258
+ catch (error) {
259
+ await i.onRunError?.(context, error);
260
+ await i.onAfterRun?.(context, error);
261
+ }
262
+ }
263
+ catch (error) {
264
+ try {
265
+ await i.onInternalError?.(this.client, error);
266
+ }
267
+ catch {
268
+ // supress error
269
+ }
270
+ }
197
271
  break;
198
272
  }
199
273
  }
@@ -9,8 +9,10 @@ import type { TextInputComponent } from './TextInputComponent';
9
9
  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
- export * from './command';
12
+ export * from './componentcommand';
13
13
  export * from './componentcontext';
14
+ export * from './modalcommand';
15
+ export * from './modalcontext';
14
16
  /**
15
17
  * Return a new component instance based on the component type.
16
18
  *
@@ -23,8 +23,10 @@ const MentionableSelectMenuComponent_1 = require("./MentionableSelectMenuCompone
23
23
  const RoleSelectMenuComponent_1 = require("./RoleSelectMenuComponent");
24
24
  const StringSelectMenuComponent_1 = require("./StringSelectMenuComponent");
25
25
  const UserSelectMenuComponent_1 = require("./UserSelectMenuComponent");
26
- __exportStar(require("./command"), exports);
26
+ __exportStar(require("./componentcommand"), exports);
27
27
  __exportStar(require("./componentcontext"), exports);
28
+ __exportStar(require("./modalcommand"), exports);
29
+ __exportStar(require("./modalcontext"), exports);
28
30
  /**
29
31
  * Return a new component instance based on the component type.
30
32
  *
@@ -0,0 +1,16 @@
1
+ import type { ExtraProps, RegisteredMiddlewares, UsingClient } from '../commands';
2
+ import type { ModalContext } from './modalcontext';
3
+ export interface ModalCommand {
4
+ __filePath?: string;
5
+ }
6
+ export declare abstract class ModalCommand {
7
+ type: 1;
8
+ abstract filter(context: ModalContext): Promise<boolean> | boolean;
9
+ abstract run(context: ModalContext): any;
10
+ middlewares: (keyof RegisteredMiddlewares)[];
11
+ props: ExtraProps;
12
+ onAfterRun?(context: ModalContext, error: unknown | undefined): any;
13
+ onRunError?(context: ModalContext, error: unknown): any;
14
+ onMiddlewaresError?(context: ModalContext, error: string): any;
15
+ onInternalError?(client: UsingClient, error?: unknown): any;
16
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ModalCommand = void 0;
4
+ const componentcommand_1 = require("./componentcommand");
5
+ class ModalCommand {
6
+ type = componentcommand_1.InteractionCommandType.MODAL;
7
+ middlewares = [];
8
+ props;
9
+ }
10
+ exports.ModalCommand = ModalCommand;
@@ -0,0 +1,104 @@
1
+ import type { AllChannels, Guild, GuildMember, Message, ModalCommand, ModalSubmitInteraction, ReturnCache, WebhookMessage } from '..';
2
+ import type { CommandMetadata, ExtendContext, GlobalMetadata, RegisteredMiddlewares, UsingClient } from '../commands';
3
+ import { BaseContext } from '../commands/basecontext';
4
+ import type { InteractionCreateBodyRequest, InteractionMessageUpdateBodyRequest, ModalCreateBodyRequest, UnionToTuple, When } from '../common';
5
+ export interface ModalContext extends BaseContext, ExtendContext {
6
+ }
7
+ /**
8
+ * Represents a context for interacting with components in a Discord bot.
9
+ * @template Type - The type of component interaction.
10
+ */
11
+ export declare class ModalContext<M extends keyof RegisteredMiddlewares = never> extends BaseContext {
12
+ readonly client: UsingClient;
13
+ interaction: ModalSubmitInteraction;
14
+ /**
15
+ * Creates a new instance of the ComponentContext class.
16
+ * @param client - The UsingClient instance.
17
+ * @param interaction - The component interaction object.
18
+ */
19
+ constructor(client: UsingClient, interaction: ModalSubmitInteraction);
20
+ command: ModalCommand;
21
+ metadata: CommandMetadata<UnionToTuple<M>>;
22
+ globalMetadata: GlobalMetadata;
23
+ get customId(): string;
24
+ get components(): {
25
+ components: {
26
+ type: import("discord-api-types/v10").ComponentType;
27
+ customId: string;
28
+ value: string;
29
+ }[];
30
+ type: import("discord-api-types/v10").ComponentType.ActionRow;
31
+ }[];
32
+ /**
33
+ * Gets the language object for the interaction's locale.
34
+ */
35
+ get t(): import("..").__InternalParseLocale<import("..").DefaultLocale> & {
36
+ get(locale?: string | undefined): import("..").DefaultLocale;
37
+ };
38
+ /**
39
+ * Writes a response to the interaction.
40
+ * @param body - The body of the response.
41
+ * @param fetchReply - Whether to fetch the reply or not.
42
+ */
43
+ write<FR extends boolean = false>(body: InteractionCreateBodyRequest, fetchReply?: FR): Promise<When<FR, WebhookMessage, void>>;
44
+ /**
45
+ * Defers the reply to the interaction.
46
+ * @param ephemeral - Whether the reply should be ephemeral or not.
47
+ */
48
+ deferReply(ephemeral?: boolean): Promise<void>;
49
+ /**
50
+ * Edits the response of the interaction.
51
+ * @param body - The updated body of the response.
52
+ */
53
+ editResponse(body: InteractionMessageUpdateBodyRequest): Promise<WebhookMessage>;
54
+ /**
55
+ * Edits the response or replies to the interaction.
56
+ * @param body - The body of the response or updated body of the interaction.
57
+ * @param fetchReply - Whether to fetch the reply or not.
58
+ */
59
+ editOrReply<FR extends boolean = false>(body: InteractionCreateBodyRequest | InteractionMessageUpdateBodyRequest, fetchReply?: FR): Promise<When<FR, WebhookMessage | Message, void | WebhookMessage | Message>>;
60
+ /**
61
+ * Deletes the response of the interaction.
62
+ * @returns A promise that resolves when the response is deleted.
63
+ */
64
+ deleteResponse(): Promise<void | undefined>;
65
+ modal(body: ModalCreateBodyRequest): any;
66
+ /**
67
+ * Gets the channel of the interaction.
68
+ * @param mode - The mode to fetch the channel.
69
+ * @returns A promise that resolves to the channel.
70
+ */
71
+ channel(mode?: 'rest' | 'flow'): Promise<AllChannels>;
72
+ channel(mode?: 'cache'): ReturnCache<AllChannels>;
73
+ /**
74
+ * Gets the bot member in the guild of the interaction.
75
+ * @param mode - The mode to fetch the member.
76
+ * @returns A promise that resolves to the bot member.
77
+ */
78
+ me(mode?: 'rest' | 'flow'): Promise<GuildMember>;
79
+ me(mode?: 'cache'): ReturnCache<GuildMember | undefined>;
80
+ /**
81
+ * Gets the guild of the interaction.
82
+ * @param mode - The mode to fetch the guild.
83
+ * @returns A promise that resolves to the guild.
84
+ */
85
+ guild(mode?: 'rest' | 'flow'): Promise<Guild<'cached' | 'api'> | undefined>;
86
+ guild(mode?: 'cache'): ReturnCache<Guild<'cached'> | undefined>;
87
+ /**
88
+ * Gets the ID of the guild of the interaction.
89
+ */
90
+ get guildId(): string | undefined;
91
+ /**
92
+ * Gets the ID of the channel of the interaction.
93
+ */
94
+ get channelId(): string;
95
+ /**
96
+ * Gets the author of the interaction.
97
+ */
98
+ get author(): import("..").User;
99
+ /**
100
+ * Gets the member of the interaction.
101
+ */
102
+ get member(): import("..").InteractionGuildMember | undefined;
103
+ isModal(): this is ModalContext;
104
+ }