seyfert 1.3.3 → 1.4.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 (94) hide show
  1. package/lib/api/api.js +13 -7
  2. package/lib/builders/Attachment.d.ts +1 -4
  3. package/lib/builders/Attachment.js +4 -4
  4. package/lib/cache/adapters/workeradapter.js +7 -3
  5. package/lib/cache/resources/default/base.d.ts +1 -2
  6. package/lib/cache/resources/default/guild-based.d.ts +1 -2
  7. package/lib/client/base.d.ts +26 -4
  8. package/lib/client/base.js +42 -2
  9. package/lib/client/client.d.ts +3 -3
  10. package/lib/client/client.js +18 -6
  11. package/lib/client/httpclient.d.ts +7 -8
  12. package/lib/client/httpclient.js +92 -13
  13. package/lib/client/oninteractioncreate.d.ts +2 -2
  14. package/lib/client/oninteractioncreate.js +15 -7
  15. package/lib/client/onmessagecreate.js +74 -66
  16. package/lib/client/workerclient.d.ts +1 -1
  17. package/lib/client/workerclient.js +18 -7
  18. package/lib/commands/applications/chat.d.ts +1 -1
  19. package/lib/commands/applications/chat.js +2 -1
  20. package/lib/commands/applications/chatcontext.d.ts +1 -1
  21. package/lib/commands/applications/chatcontext.js +2 -2
  22. package/lib/commands/applications/menu.js +0 -48
  23. package/lib/commands/applications/menucontext.d.ts +1 -1
  24. package/lib/commands/applications/menucontext.js +3 -3
  25. package/lib/commands/applications/options.d.ts +3 -1
  26. package/lib/commands/basecontext.d.ts +26 -0
  27. package/lib/commands/{basecontex.js → basecontext.js} +24 -0
  28. package/lib/commands/handler.d.ts +6 -1
  29. package/lib/commands/handler.js +125 -3
  30. package/lib/common/bot/watcher.d.ts +1 -2
  31. package/lib/common/bot/watcher.js +9 -4
  32. package/lib/common/it/logger.d.ts +1 -1
  33. package/lib/common/it/logger.js +9 -8
  34. package/lib/common/it/utils.d.ts +2 -0
  35. package/lib/common/it/utils.js +19 -5
  36. package/lib/common/shorters/interaction.js +3 -3
  37. package/lib/common/shorters/messages.js +2 -2
  38. package/lib/common/shorters/webhook.js +2 -2
  39. package/lib/components/componentcommand.d.ts +21 -0
  40. package/lib/components/{command.js → componentcommand.js} +2 -5
  41. package/lib/components/componentcontext.d.ts +20 -16
  42. package/lib/components/componentcontext.js +27 -9
  43. package/lib/components/handler.d.ts +10 -5
  44. package/lib/components/handler.js +94 -17
  45. package/lib/components/index.d.ts +3 -1
  46. package/lib/components/index.js +3 -1
  47. package/lib/components/modalcommand.d.ts +15 -0
  48. package/lib/components/modalcommand.js +9 -0
  49. package/lib/components/modalcontext.d.ts +104 -0
  50. package/lib/components/modalcontext.js +132 -0
  51. package/lib/events/handler.d.ts +4 -1
  52. package/lib/events/handler.js +2 -7
  53. package/lib/events/hooks/application_command.d.ts +2 -2
  54. package/lib/events/hooks/auto_moderation.d.ts +5 -5
  55. package/lib/events/hooks/channel.d.ts +5 -5
  56. package/lib/events/hooks/custom.d.ts +3 -3
  57. package/lib/events/hooks/dispatch.d.ts +4 -4
  58. package/lib/events/hooks/entitlement.d.ts +4 -4
  59. package/lib/events/hooks/guild.d.ts +23 -23
  60. package/lib/events/hooks/guild.js +6 -6
  61. package/lib/events/hooks/integration.d.ts +4 -4
  62. package/lib/events/hooks/interactions.d.ts +2 -2
  63. package/lib/events/hooks/invite.d.ts +3 -3
  64. package/lib/events/hooks/message.d.ts +13 -13
  65. package/lib/events/hooks/message.js +1 -1
  66. package/lib/events/hooks/presence.d.ts +7 -3
  67. package/lib/events/hooks/presence.js +2 -2
  68. package/lib/events/hooks/stage.d.ts +7 -13
  69. package/lib/events/hooks/stage.js +2 -2
  70. package/lib/events/hooks/thread.d.ts +7 -7
  71. package/lib/events/hooks/thread.js +2 -2
  72. package/lib/events/hooks/typing.d.ts +2 -2
  73. package/lib/events/hooks/user.d.ts +2 -2
  74. package/lib/events/hooks/user.js +2 -2
  75. package/lib/events/hooks/voice.d.ts +5 -45
  76. package/lib/events/hooks/voice.js +4 -7
  77. package/lib/events/hooks/webhook.d.ts +2 -2
  78. package/lib/index.d.ts +1 -1
  79. package/lib/index.js +9 -4
  80. package/lib/langs/handler.d.ts +4 -1
  81. package/lib/langs/handler.js +3 -3
  82. package/lib/structures/Interaction.d.ts +3 -3
  83. package/lib/structures/Interaction.js +11 -6
  84. package/lib/structures/VoiceState.d.ts +6 -5
  85. package/lib/structures/VoiceState.js +6 -3
  86. package/lib/structures/channels.d.ts +1 -1
  87. package/lib/structures/channels.js +2 -1
  88. package/lib/websocket/discord/sharder.js +10 -3
  89. package/lib/websocket/discord/shared.d.ts +1 -0
  90. package/lib/websocket/discord/workermanager.d.ts +2 -3
  91. package/lib/websocket/discord/workermanager.js +4 -2
  92. package/package.json +3 -3
  93. package/lib/commands/basecontex.d.ts +0 -15
  94. package/lib/components/command.d.ts +0 -24
@@ -6,6 +6,7 @@ const node_path_1 = require("node:path");
6
6
  const common_1 = require("../common");
7
7
  const chat_1 = require("./applications/chat");
8
8
  const menu_1 = require("./applications/menu");
9
+ const node_fs_1 = require("node:fs");
9
10
  class CommandHandler extends common_1.BaseHandler {
10
11
  logger;
11
12
  client;
@@ -34,8 +35,129 @@ class CommandHandler extends common_1.BaseHandler {
34
35
  }
35
36
  }
36
37
  }
37
- async load(commandsDir, client) {
38
- const result = (await this.loadFilesK(await this.getFiles(commandsDir))).filter(x => x.file);
38
+ shouldUploadOption(option, cached) {
39
+ if (option.description !== cached.description)
40
+ return true;
41
+ if (option.type !== cached.type)
42
+ return true;
43
+ if (option.required !== cached.required)
44
+ return true;
45
+ if (option.name !== cached.name)
46
+ return true;
47
+ //TODO: locales
48
+ switch (option.type) {
49
+ case v10_1.ApplicationCommandOptionType.String:
50
+ return (option.min_length !== cached.min_length ||
51
+ option.max_length !== cached.max_length);
52
+ case v10_1.ApplicationCommandOptionType.Channel:
53
+ {
54
+ if (option.channel_types?.length !== cached.channel_types?.length)
55
+ return true;
56
+ if ('channel_types' in option && 'channel_types' in cached) {
57
+ if (!option.channel_types || !cached.channel_types)
58
+ return true;
59
+ return option.channel_types.some(ct => !cached.channel_types.includes(ct));
60
+ }
61
+ }
62
+ return;
63
+ case v10_1.ApplicationCommandOptionType.Subcommand:
64
+ case v10_1.ApplicationCommandOptionType.SubcommandGroup:
65
+ if (option.options?.length !==
66
+ cached.options?.length) {
67
+ return true;
68
+ }
69
+ if (option.options &&
70
+ cached.options)
71
+ for (const i of option.options) {
72
+ const cachedOption = cached.options.find(x => x.name === i.name);
73
+ if (!cachedOption)
74
+ return true;
75
+ if (this.shouldUploadOption(i, cachedOption))
76
+ return true;
77
+ }
78
+ break;
79
+ case v10_1.ApplicationCommandOptionType.Integer:
80
+ case v10_1.ApplicationCommandOptionType.Number:
81
+ return (option.min_value !== cached.min_value ||
82
+ option.max_value !== cached.max_value);
83
+ case v10_1.ApplicationCommandOptionType.Attachment:
84
+ case v10_1.ApplicationCommandOptionType.Boolean:
85
+ case v10_1.ApplicationCommandOptionType.Mentionable:
86
+ case v10_1.ApplicationCommandOptionType.Role:
87
+ case v10_1.ApplicationCommandOptionType.User:
88
+ break;
89
+ }
90
+ return false;
91
+ }
92
+ async shouldUpload(file) {
93
+ if (!(await node_fs_1.promises.access(file).then(() => true, () => false))) {
94
+ await node_fs_1.promises.writeFile(file, JSON.stringify(this.values.map(x => x.toJSON())));
95
+ return true;
96
+ }
97
+ const cachedCommands = JSON.parse((await node_fs_1.promises.readFile(file)).toString());
98
+ if (cachedCommands.length !== this.values.length)
99
+ return true;
100
+ for (const command of this.values.map(x => x.toJSON())) {
101
+ const cached = cachedCommands.find(x => {
102
+ if (x.name !== command.name)
103
+ return false;
104
+ if (command.guild_id)
105
+ return command.guild_id.every(id => x.guild_id?.includes(id));
106
+ return true;
107
+ });
108
+ if (!cached)
109
+ return true;
110
+ if (cached.description !== command.description)
111
+ return true;
112
+ if (cached.default_member_permissions !== command.default_member_permissions)
113
+ return true;
114
+ if (cached.type !== command.type)
115
+ return true;
116
+ if (cached.nsfw !== command.nsfw)
117
+ return true;
118
+ if (!!('options' in cached) !== !!('options' in command))
119
+ return true;
120
+ if (!!cached.contexts !== !!command.contexts)
121
+ return true;
122
+ if (!!cached.integration_types !== !!command.integration_types)
123
+ return true;
124
+ //TODO: locales
125
+ if ('contexts' in command && 'contexts' in cached) {
126
+ if (command.contexts?.length !== cached.contexts?.length)
127
+ return true;
128
+ if (command.contexts && cached.contexts) {
129
+ if (command.contexts.some(ctx => !cached.contexts.includes(ctx)))
130
+ return true;
131
+ }
132
+ }
133
+ if ('integration_types' in command && 'integration_types' in cached) {
134
+ if (command.integration_types?.length !== cached.integration_types?.length)
135
+ return true;
136
+ if (command.integration_types && cached.integration_types) {
137
+ if (command.integration_types.some(ctx => !cached.integration_types.includes(ctx)))
138
+ return true;
139
+ }
140
+ }
141
+ if ('options' in command && 'options' in cached) {
142
+ if (command.options.length !== cached.options.length)
143
+ return true;
144
+ for (const option of command.options) {
145
+ const cachedOption = cached.options.find(x => x.name === option.name);
146
+ if (!cachedOption)
147
+ return true;
148
+ if (this.shouldUploadOption(option, cachedOption))
149
+ return true;
150
+ }
151
+ }
152
+ }
153
+ return false;
154
+ }
155
+ async load(commandsDir, client, instances) {
156
+ const result = instances?.map(x => {
157
+ const i = new x();
158
+ return { name: i.name, file: x, path: i.__filePath ?? '*' };
159
+ }) ??
160
+ (await this.loadFilesK(await this.getFiles(commandsDir))).filter(x => x.file);
39
161
  this.values = [];
40
162
  for (const command of result) {
41
163
  let commandInstance;
@@ -45,7 +167,7 @@ class CommandHandler extends common_1.BaseHandler {
45
167
  continue;
46
168
  }
47
169
  catch (e) {
48
- if (e instanceof Error && e.message === 'command.file is not a constructor') {
170
+ if (e instanceof Error && e.message.includes('is not a constructor')) {
49
171
  this.logger.warn(`${command.path
50
172
  .split(process.cwd())
51
173
  .slice(1)
@@ -1,6 +1,5 @@
1
1
  /// <reference types="node" />
2
2
  import type { GatewayDispatchPayload, GatewaySendPayload } from 'discord-api-types/v10';
3
- import { Worker } from 'node:worker_threads';
4
3
  import { ApiHandler } from '../../api';
5
4
  import { ShardManager, type ShardManagerOptions } from '../../websocket';
6
5
  import { Logger } from '../it/logger';
@@ -9,7 +8,7 @@ import type { MakeRequired } from '../types/util';
9
8
  * Represents a watcher class that extends the ShardManager.
10
9
  */
11
10
  export declare class Watcher extends ShardManager {
12
- worker?: Worker;
11
+ worker?: import('node:worker_threads').Worker;
13
12
  logger: Logger;
14
13
  rest?: ApiHandler;
15
14
  options: MakeRequired<WatcherOptions, 'intents' | 'token' | 'handlePayload' | 'info'>;
@@ -1,13 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Watcher = void 0;
4
- const chokidar_1 = require("chokidar");
5
4
  const node_child_process_1 = require("node:child_process");
6
- const node_worker_threads_1 = require("node:worker_threads");
7
5
  const api_1 = require("../../api");
8
6
  const base_1 = require("../../client/base");
9
7
  const websocket_1 = require("../../websocket");
10
8
  const logger_1 = require("../it/logger");
9
+ const utils_1 = require("../it/utils");
11
10
  /**
12
11
  * Represents a watcher class that extends the ShardManager.
13
12
  */
@@ -43,11 +42,14 @@ class Watcher extends websocket_1.ShardManager {
43
42
  * Resets the worker instance.
44
43
  */
45
44
  resetWorker() {
45
+ const worker_threads = (0, utils_1.lazyLoadPackage)('node:worker_threads');
46
+ if (!worker_threads)
47
+ throw new Error('Cannot use worker_threads');
46
48
  if (this.worker) {
47
49
  this.worker.terminate();
48
50
  }
49
51
  this.build();
50
- this.worker = new node_worker_threads_1.Worker(this.options.filePath, {
52
+ this.worker = new worker_threads.Worker(this.options.filePath, {
51
53
  argv: this.options.argv,
52
54
  workerData: {
53
55
  __USING_WATCHER__: true,
@@ -87,7 +89,10 @@ class Watcher extends websocket_1.ShardManager {
87
89
  };
88
90
  this.connectQueue.concurrency = this.options.info.session_start_limit.max_concurrency;
89
91
  await super.spawnShards();
90
- const watcher = (0, chokidar_1.watch)(this.options.srcPath).on('ready', () => {
92
+ const chokidar = (0, utils_1.lazyLoadPackage)('chokidar');
93
+ if (!chokidar?.watch)
94
+ return this.logger.warn('No chokidar installed.');
95
+ const watcher = chokidar.watch(this.options.srcPath).on('ready', () => {
91
96
  this.logger.debug(`Watching ${this.options.srcPath}`);
92
97
  watcher.on('all', event => {
93
98
  this.logger.debug(`${event} event detected, building`);
@@ -13,7 +13,7 @@ export type LoggerOptions = {
13
13
  active?: boolean;
14
14
  saveOnFile?: boolean;
15
15
  };
16
- export type CustomCallback = (self: Logger, level: LogLevels, args: unknown[]) => unknown[];
16
+ export type CustomCallback = (self: Logger, level: LogLevels, args: unknown[]) => unknown[] | undefined;
17
17
  /**
18
18
  * Represents a logger utility for logging messages with various log levels.
19
19
  */
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Logger = exports.LogLevels = void 0;
4
4
  const node_fs_1 = require("node:fs");
5
- const promises_1 = require("node:fs/promises");
6
5
  const node_path_1 = require("node:path");
7
6
  const colors_1 = require("./colors");
8
7
  const utils_1 = require("./utils");
@@ -42,11 +41,11 @@ class Logger {
42
41
  Logger.__callback = cb;
43
42
  }
44
43
  static async clearLogs() {
45
- for (const i of await (0, promises_1.readdir)((0, node_path_1.join)(process.cwd(), Logger.dirname))) {
46
- if (this.streams[i])
47
- await new Promise(res => this.streams[i].close(res));
48
- await (0, promises_1.unlink)((0, node_path_1.join)(process.cwd(), Logger.dirname, i)).catch(() => { });
49
- delete this.streams[i];
44
+ for (const i of await node_fs_1.promises.readdir((0, node_path_1.join)(process.cwd(), Logger.dirname), { withFileTypes: true })) {
45
+ if (this.streams[i.name])
46
+ await new Promise(res => this.streams[i.name].close(res));
47
+ await node_fs_1.promises.unlink((0, node_path_1.join)(process.cwd(), Logger.dirname, i.name)).catch(() => { });
48
+ delete this.streams[i.name];
50
49
  }
51
50
  }
52
51
  /**
@@ -112,10 +111,10 @@ class Logger {
112
111
  let log;
113
112
  if (!Logger.__callback) {
114
113
  const color = Logger.colorFunctions.get(level) ?? Logger.noColor;
115
- const memoryData = process.memoryUsage();
114
+ const memoryData = process.memoryUsage?.();
116
115
  const date = new Date();
117
116
  log = [
118
- (0, colors_1.brightBlack)(formatMemoryUsage(memoryData.rss)),
117
+ (0, colors_1.brightBlack)(formatMemoryUsage(memoryData?.rss ?? 0)),
119
118
  (0, colors_1.bgBrightWhite)((0, colors_1.black)(`[${date.toLocaleDateString()} ${date.toLocaleTimeString()}]`)),
120
119
  color(Logger.prefixes.get(level) ?? 'DEBUG'),
121
120
  this.name ? `${this.name} >` : '>',
@@ -125,6 +124,8 @@ class Logger {
125
124
  else {
126
125
  log = Logger.__callback(this, level, args);
127
126
  }
127
+ if (!log)
128
+ return;
128
129
  this.__write(log);
129
130
  return console.log(...log);
130
131
  }
@@ -95,3 +95,5 @@ export type OnFailCallback = (error: unknown) => any;
95
95
  export declare function fakePromise<T = unknown | Promise<unknown>>(value: T): {
96
96
  then<R>(callback: (arg: Awaited<T>) => R): R;
97
97
  };
98
+ export declare function lazyLoadPackage<T>(mod: string): T | undefined;
99
+ export declare function isCloudfareWorker(): boolean;
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fakePromise = exports.magicImport = exports.ReplaceRegex = exports.toCamelCase = exports.toSnakeCase = exports.BaseHandler = exports.filterSplit = exports.MergeOptions = exports.isObject = exports.delay = exports.resolveColor = void 0;
4
- const promises_1 = require("node:fs/promises");
3
+ exports.isCloudfareWorker = exports.lazyLoadPackage = exports.fakePromise = exports.magicImport = exports.ReplaceRegex = exports.toCamelCase = exports.toSnakeCase = exports.BaseHandler = exports.filterSplit = exports.MergeOptions = exports.isObject = exports.delay = exports.resolveColor = void 0;
4
+ const node_fs_1 = require("node:fs");
5
5
  const node_path_1 = require("node:path");
6
- const promises_2 = require("node:timers/promises");
7
6
  const __1 = require("..");
8
7
  /**
9
8
  * Resolves the color to a numeric representation.
@@ -39,7 +38,7 @@ exports.resolveColor = resolveColor;
39
38
  * @returns A Promise that resolves after the specified time with the provided result.
40
39
  */
41
40
  function delay(time, result) {
42
- return (0, promises_2.setTimeout)(time, result);
41
+ return new Promise(r => setTimeout(r, time, result));
43
42
  }
44
43
  exports.delay = delay;
45
44
  /**
@@ -115,7 +114,7 @@ class BaseHandler {
115
114
  */
116
115
  async getFiles(dir) {
117
116
  const files = [];
118
- for (const i of await (0, promises_1.readdir)(dir, { withFileTypes: true })) {
117
+ for (const i of await node_fs_1.promises.readdir(dir, { withFileTypes: true })) {
119
118
  if (i.isDirectory()) {
120
119
  files.push(...(await this.getFiles((0, node_path_1.join)(dir, i.name))));
121
120
  }
@@ -254,3 +253,18 @@ function fakePromise(value) {
254
253
  };
255
254
  }
256
255
  exports.fakePromise = fakePromise;
256
+ function lazyLoadPackage(mod) {
257
+ try {
258
+ return require(mod);
259
+ }
260
+ catch (e) {
261
+ console.log(`Cannot import ${mod}`);
262
+ return;
263
+ }
264
+ }
265
+ exports.lazyLoadPackage = lazyLoadPackage;
266
+ function isCloudfareWorker() {
267
+ //@ts-expect-error
268
+ return process.platform === 'browser';
269
+ }
270
+ exports.isCloudfareWorker = isCloudfareWorker;
@@ -15,7 +15,7 @@ class InteractionShorter extends base_1.BaseShorter {
15
15
  body: __1.BaseInteraction.transformBodyRequest({
16
16
  type: body.type,
17
17
  data,
18
- }),
18
+ }, this.client),
19
19
  files: files ? await (0, __1.resolveFiles)(files) : undefined,
20
20
  });
21
21
  }
@@ -31,7 +31,7 @@ class InteractionShorter extends base_1.BaseShorter {
31
31
  .webhooks(this.client.applicationId)(token)
32
32
  .messages(messageId)
33
33
  .patch({
34
- body: __1.BaseInteraction.transformBody(data),
34
+ body: __1.BaseInteraction.transformBody(data, this.client),
35
35
  files: files ? await (0, __1.resolveFiles)(files) : undefined,
36
36
  });
37
37
  return new __1.WebhookMessage(this.client, apiMessage, this.client.applicationId, token);
@@ -54,7 +54,7 @@ class InteractionShorter extends base_1.BaseShorter {
54
54
  const apiMessage = await this.client.proxy
55
55
  .webhooks(this.client.applicationId)(token)
56
56
  .post({
57
- body: __1.BaseInteraction.transformBody(body),
57
+ body: __1.BaseInteraction.transformBody(body, this.client),
58
58
  files: files,
59
59
  });
60
60
  return new __1.WebhookMessage(this.client, apiMessage, this.client.applicationId, token);
@@ -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, 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, this.client),
29
29
  files: parsedFiles,
30
30
  })
31
31
  .then(async (message) => {
@@ -67,7 +67,7 @@ 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);
70
+ const transformedBody = structures_1.MessagesMethods.transformMessageBody(body, this.client);
71
71
  const parsedFiles = files ? await (0, builders_1.resolveFiles)(files) : [];
72
72
  return this.client.proxy
73
73
  .webhooks(webhookId)(token)
@@ -84,7 +84,7 @@ 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);
87
+ const transformedBody = structures_1.MessagesMethods.transformMessageBody(body, this.client);
88
88
  const parsedFiles = files ? await (0, builders_1.resolveFiles)(files) : [];
89
89
  return this.client.proxy
90
90
  .webhooks(webhookId)(token)
@@ -0,0 +1,21 @@
1
+ import type { ContextComponentCommandInteractionMap, ComponentContext } from './componentcontext';
2
+ import type { 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
+ get cType(): number;
16
+ onAfterRun?(context: ComponentContext, error: unknown | undefined): any;
17
+ onRunError?(context: ComponentContext, error: unknown): any;
18
+ onMiddlewaresError?(context: ComponentContext, error: string): any;
19
+ onInternalError?(client: UsingClient, error?: unknown): any;
20
+ middlewares: (keyof RegisteredMiddlewares)[];
21
+ }
@@ -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,
@@ -11,9 +11,6 @@ class ComponentCommand {
11
11
  get cType() {
12
12
  return v10_1.ComponentType[this.componentType];
13
13
  }
14
+ middlewares = [];
14
15
  }
15
16
  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
45
  reloadAll(): Promise<void>;
41
- executeComponent(interaction: ComponentInteraction): Promise<void>;
42
- executeModal(interaction: ModalSubmitInteraction): 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;