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
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateShardInfo = exports.WorkerClient = void 0;
4
4
  const v10_1 = require("discord-api-types/v10");
5
5
  const node_crypto_1 = require("node:crypto");
6
- const node_worker_threads_1 = require("node:worker_threads");
7
6
  const __1 = require("..");
8
7
  const cache_1 = require("../cache");
9
8
  const common_1 = require("../common");
@@ -13,7 +12,9 @@ const websocket_1 = require("../websocket");
13
12
  const base_1 = require("./base");
14
13
  const oninteractioncreate_1 = require("./oninteractioncreate");
15
14
  const onmessagecreate_1 = require("./onmessagecreate");
15
+ const collectors_1 = require("./collectors");
16
16
  let workerData;
17
+ let manager;
17
18
  try {
18
19
  workerData = {
19
20
  debug: process.env.SEYFERT_WORKER_DEBUG === 'true',
@@ -31,12 +32,19 @@ class WorkerClient extends base_1.BaseClient {
31
32
  logger = new __1.Logger({
32
33
  name: `[Worker #${workerData.workerId}]`,
33
34
  });
34
- events = new events_1.EventHandler(this.logger);
35
+ collectors = new collectors_1.Collectors();
36
+ events = new events_1.EventHandler(this);
35
37
  me;
36
38
  promises = new Map();
37
39
  shards = new Map();
38
40
  constructor(options) {
39
41
  super(options);
42
+ this.options = (0, common_1.MergeOptions)({
43
+ commands: {
44
+ argsParser: onmessagecreate_1.defaultArgsParser,
45
+ optionsParser: onmessagecreate_1.defaultOptionsParser,
46
+ },
47
+ }, this.options);
40
48
  if (!process.env.SEYFERT_SPAWNING) {
41
49
  throw new Error('WorkerClient cannot spawn without manager');
42
50
  }
@@ -44,7 +52,11 @@ class WorkerClient extends base_1.BaseClient {
44
52
  type: 'WORKER_START',
45
53
  workerId: workerData.workerId,
46
54
  });
47
- (node_worker_threads_1.parentPort ?? process).on('message', (data) => this.handleManagerMessages(data));
55
+ const worker_threads = (0, common_1.lazyLoadPackage)('node:worker_threads');
56
+ if (worker_threads?.parentPort) {
57
+ manager = worker_threads?.parentPort;
58
+ }
59
+ (manager ?? process).on('message', (data) => this.handleManagerMessages(data));
48
60
  this.setServices({
49
61
  cache: {
50
62
  adapter: new cache_1.WorkerAdapter(workerData),
@@ -82,7 +94,7 @@ class WorkerClient extends base_1.BaseClient {
82
94
  this.events = undefined;
83
95
  }
84
96
  else if (typeof rest.handlers.events === 'function') {
85
- this.events = new events_1.EventHandler(this.logger);
97
+ this.events = new events_1.EventHandler(this);
86
98
  this.events.setHandlers({
87
99
  callback: rest.handlers.events,
88
100
  });
@@ -105,8 +117,8 @@ class WorkerClient extends base_1.BaseClient {
105
117
  }
106
118
  }
107
119
  postMessage(body) {
108
- if (node_worker_threads_1.parentPort)
109
- return node_worker_threads_1.parentPort.postMessage(body);
120
+ if (manager)
121
+ return manager.postMessage(body);
110
122
  return process.send(body);
111
123
  }
112
124
  async handleManagerMessages(data) {
@@ -161,9 +173,12 @@ class WorkerClient extends base_1.BaseClient {
161
173
  info: data.info,
162
174
  compress: data.compress,
163
175
  debugger: this.debugger,
176
+ properties: {
177
+ ...websocket_1.properties,
178
+ ...this.options.gateway?.properties,
179
+ },
164
180
  async handlePayload(shardId, payload) {
165
181
  await handlePayload?.(shardId, payload);
166
- await self.cache.onPacket(payload);
167
182
  await onPacket?.(payload, shardId);
168
183
  self.postMessage({
169
184
  workerId: workerData.workerId,
@@ -227,8 +242,8 @@ class WorkerClient extends base_1.BaseClient {
227
242
  let result;
228
243
  try {
229
244
  // biome-ignore lint/security/noGlobalEval: yes
230
- result = await eval(`
231
- (${data.func})(this)
245
+ result = await eval(`
246
+ (${data.func})(this)
232
247
  `);
233
248
  }
234
249
  catch (e) {
@@ -284,67 +299,55 @@ class WorkerClient extends base_1.BaseClient {
284
299
  async onPacket(packet, shardId) {
285
300
  await this.events?.execute('RAW', packet, this, shardId);
286
301
  switch (packet.t) {
287
- case 'GUILD_MEMBER_UPDATE':
288
- case 'PRESENCE_UPDATE':
289
- case 'MESSAGE_UPDATE':
290
- case 'MESSAGE_DELETE_BULK':
291
- case 'MESSAGE_DELETE':
302
+ case 'GUILD_CREATE': {
303
+ if (this.__handleGuilds?.has(packet.d.id)) {
304
+ this.__handleGuilds.delete(packet.d.id);
305
+ if (!this.__handleGuilds.size && [...this.shards.values()].every(shard => shard.data.session_id)) {
306
+ this.postMessage({
307
+ type: 'WORKER_READY',
308
+ workerId: this.workerId,
309
+ });
310
+ await this.events?.runEvent('WORKER_READY', this, this.me, -1);
311
+ }
312
+ if (!this.__handleGuilds.size)
313
+ delete this.__handleGuilds;
314
+ return this.cache.onPacket(packet);
315
+ }
292
316
  await this.events?.execute(packet.t, packet, this, shardId);
293
- await this.cache.onPacket(packet);
294
317
  break;
295
- case 'GUILD_DELETE':
296
- case 'CHANNEL_UPDATE':
318
+ }
319
+ default: {
297
320
  await this.events?.execute(packet.t, packet, this, shardId);
298
- break;
299
- //rest of the events
300
- default:
301
- {
302
- switch (packet.t) {
303
- case 'READY':
304
- for (const g of packet.d.guilds) {
305
- this.__handleGuilds?.add(g.id);
306
- }
307
- this.botId = packet.d.user.id;
308
- this.applicationId = packet.d.application.id;
309
- this.me = new structures_1.ClientUser(this, packet.d.user, packet.d.application);
310
- if (!this.__handleGuilds?.size ||
311
- !((workerData.intents & v10_1.GatewayIntentBits.Guilds) === v10_1.GatewayIntentBits.Guilds)) {
312
- if ([...this.shards.values()].every(shard => shard.data.session_id)) {
313
- this.postMessage({
314
- type: 'WORKER_READY',
315
- workerId: this.workerId,
316
- });
317
- await this.events?.runEvent('WORKER_READY', this, this.me, -1);
318
- }
319
- delete this.__handleGuilds;
320
- }
321
- this.debugger?.debug(`#${shardId} [${packet.d.user.username}](${this.botId}) is online...`);
322
- break;
323
- case 'INTERACTION_CREATE':
324
- await (0, oninteractioncreate_1.onInteractionCreate)(this, packet.d, shardId);
325
- break;
326
- case 'MESSAGE_CREATE':
327
- await (0, onmessagecreate_1.onMessageCreate)(this, packet.d, shardId);
328
- break;
329
- case 'GUILD_CREATE': {
330
- if (this.__handleGuilds?.has(packet.d.id)) {
331
- this.__handleGuilds.delete(packet.d.id);
332
- if (!this.__handleGuilds.size && [...this.shards.values()].every(shard => shard.data.session_id)) {
333
- this.postMessage({
334
- type: 'WORKER_READY',
335
- workerId: this.workerId,
336
- });
337
- await this.events?.runEvent('WORKER_READY', this, this.me, -1);
338
- }
339
- if (!this.__handleGuilds.size)
340
- delete this.__handleGuilds;
341
- return;
321
+ switch (packet.t) {
322
+ case 'READY':
323
+ for (const g of packet.d.guilds) {
324
+ this.__handleGuilds?.add(g.id);
325
+ }
326
+ this.botId = packet.d.user.id;
327
+ this.applicationId = packet.d.application.id;
328
+ this.me = new structures_1.ClientUser(this, packet.d.user, packet.d.application);
329
+ if (!(this.__handleGuilds?.size &&
330
+ (workerData.intents & v10_1.GatewayIntentBits.Guilds) === v10_1.GatewayIntentBits.Guilds)) {
331
+ if ([...this.shards.values()].every(shard => shard.data.session_id)) {
332
+ this.postMessage({
333
+ type: 'WORKER_READY',
334
+ workerId: this.workerId,
335
+ });
336
+ await this.events?.runEvent('WORKER_READY', this, this.me, -1);
342
337
  }
338
+ delete this.__handleGuilds;
343
339
  }
344
- }
345
- await this.events?.execute(packet.t, packet, this, shardId);
340
+ this.debugger?.debug(`#${shardId} [${packet.d.user.username}](${this.botId}) is online...`);
341
+ break;
342
+ case 'INTERACTION_CREATE':
343
+ await (0, oninteractioncreate_1.onInteractionCreate)(this, packet.d, shardId);
344
+ break;
345
+ case 'MESSAGE_CREATE':
346
+ await (0, onmessagecreate_1.onMessageCreate)(this, packet.d, shardId);
347
+ break;
346
348
  }
347
349
  break;
350
+ }
348
351
  }
349
352
  }
350
353
  }
@@ -229,8 +229,8 @@ export declare class LimitedCollection<K, V> {
229
229
  private resetTimeout;
230
230
  private stopTimeout;
231
231
  private startTimeout;
232
- keys(): () => IterableIterator<K>;
233
- values(): () => IterableIterator<LimitedCollectionData<V>>;
232
+ keys(): IterableIterator<K>;
233
+ values(): IterableIterator<LimitedCollectionData<V>>;
234
234
  entries(): IterableIterator<[K, LimitedCollectionData<V>]>;
235
235
  clear(): void;
236
236
  private clearExpired;
package/lib/collection.js CHANGED
@@ -365,10 +365,10 @@ class LimitedCollection {
365
365
  }, expireOn - Date.now());
366
366
  }
367
367
  keys() {
368
- return this.data.keys;
368
+ return this.data.keys();
369
369
  }
370
370
  values() {
371
- return this.data.values;
371
+ return this.data.values();
372
372
  }
373
373
  entries() {
374
374
  return this.data.entries();
@@ -1,11 +1,11 @@
1
- import { ApplicationCommandOptionType, ApplicationCommandType, type APIApplicationCommandBasicOption, type APIApplicationCommandOption, type LocaleString } from 'discord-api-types/v10';
1
+ import { ApplicationCommandOptionType, ApplicationCommandType, type ApplicationIntegrationType, type InteractionContextType, type APIApplicationCommandBasicOption, type APIApplicationCommandOption, type LocaleString } from 'discord-api-types/v10';
2
2
  import type { PermissionStrings, SeyfertNumberOption, SeyfertStringOption } from '../..';
3
3
  import type { Attachment } from '../../builders';
4
4
  import { type FlatObjectKeys } from '../../common';
5
5
  import type { AllChannels, AutocompleteInteraction, GuildRole, InteractionGuildMember, User } from '../../structures';
6
- import type { Groups, IntegrationTypes, InteractionContextTypes, RegisteredMiddlewares } from '../decorators';
6
+ import type { Groups, RegisteredMiddlewares } from '../decorators';
7
7
  import type { CommandContext } from './chatcontext';
8
- import type { DefaultLocale, IgnoreCommand, OKFunction, OnOptionsReturnObject, StopFunction, UsingClient } from './shared';
8
+ import type { DefaultLocale, ExtraProps, IgnoreCommand, OKFunction, OnOptionsReturnObject, StopFunction, UsingClient } from './shared';
9
9
  export interface ReturnOptionsTypes {
10
10
  1: never;
11
11
  2: never;
@@ -64,7 +64,7 @@ type ContextOptionsAux<T extends OptionsRecord> = {
64
64
  [K in KeysWithoutRequired<T>]?: T[K]['value'] extends (...args: any) => any ? Parameters<Parameters<T[K]['value']>[1]>[0] : T[K] extends SeyfertStringOption | SeyfertNumberOption ? T[K]['choices'] extends NonNullable<SeyfertStringOption['choices'] | SeyfertNumberOption['choices']> ? T[K]['choices'][number]['value'] : ReturnOptionsTypes[T[K]['type']] : ReturnOptionsTypes[T[K]['type']];
65
65
  };
66
66
  export type ContextOptions<T extends OptionsRecord> = ContextOptionsAux<T>;
67
- declare class BaseCommand {
67
+ export declare class BaseCommand {
68
68
  middlewares: (keyof RegisteredMiddlewares)[];
69
69
  __filePath?: string;
70
70
  __t?: {
@@ -78,14 +78,15 @@ declare class BaseCommand {
78
78
  nsfw?: boolean;
79
79
  description: string;
80
80
  defaultMemberPermissions?: bigint;
81
- integrationTypes?: IntegrationTypes[];
82
- contexts?: InteractionContextTypes[];
81
+ integrationTypes: ApplicationIntegrationType[];
82
+ contexts: InteractionContextType[];
83
83
  botPermissions?: bigint;
84
84
  name_localizations?: Partial<Record<LocaleString, string>>;
85
85
  description_localizations?: Partial<Record<LocaleString, string>>;
86
86
  options?: CommandOption[] | SubCommand[];
87
87
  ignore?: IgnoreCommand;
88
88
  aliases?: string[];
89
+ props: ExtraProps;
89
90
  toJSON(): {
90
91
  name: BaseCommand['name'];
91
92
  type: BaseCommand['type'];
@@ -127,8 +128,8 @@ export declare class Command extends BaseCommand {
127
128
  description_localizations: Partial<Record<"id" | "en-US" | "en-GB" | "bg" | "zh-CN" | "zh-TW" | "hr" | "cs" | "da" | "nl" | "fi" | "fr" | "de" | "el" | "hi" | "hu" | "it" | "ja" | "ko" | "lt" | "no" | "pl" | "pt-BR" | "ro" | "ru" | "es-ES" | "es-419" | "sv-SE" | "th" | "tr" | "uk" | "vi", string>> | undefined;
128
129
  guild_id: string[] | undefined;
129
130
  default_member_permissions: string;
130
- contexts: InteractionContextTypes[] | undefined;
131
- integration_types: IntegrationTypes[] | undefined;
131
+ contexts: InteractionContextType[];
132
+ integration_types: ApplicationIntegrationType[];
132
133
  };
133
134
  }
134
135
  export declare abstract class SubCommand extends BaseCommand {
@@ -145,8 +146,8 @@ export declare abstract class SubCommand extends BaseCommand {
145
146
  description_localizations: Partial<Record<"id" | "en-US" | "en-GB" | "bg" | "zh-CN" | "zh-TW" | "hr" | "cs" | "da" | "nl" | "fi" | "fr" | "de" | "el" | "hi" | "hu" | "it" | "ja" | "ko" | "lt" | "no" | "pl" | "pt-BR" | "ro" | "ru" | "es-ES" | "es-419" | "sv-SE" | "th" | "tr" | "uk" | "vi", string>> | undefined;
146
147
  guild_id: string[] | undefined;
147
148
  default_member_permissions: string;
148
- contexts: InteractionContextTypes[] | undefined;
149
- integration_types: IntegrationTypes[] | undefined;
149
+ contexts: InteractionContextType[];
150
+ integration_types: ApplicationIntegrationType[];
150
151
  };
151
152
  abstract run(context: CommandContext<any>): any;
152
153
  }
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SubCommand = exports.Command = void 0;
3
+ exports.SubCommand = exports.Command = exports.BaseCommand = void 0;
4
4
  const v10_1 = require("discord-api-types/v10");
5
5
  const common_1 = require("../../common");
6
+ const node_util_1 = require("node:util");
6
7
  class BaseCommand {
7
8
  middlewares = [];
8
9
  __filePath;
@@ -14,14 +15,15 @@ class BaseCommand {
14
15
  nsfw;
15
16
  description;
16
17
  defaultMemberPermissions;
17
- integrationTypes;
18
- contexts;
18
+ integrationTypes = [];
19
+ contexts = [];
19
20
  botPermissions;
20
21
  name_localizations;
21
22
  description_localizations;
22
23
  options;
23
24
  ignore;
24
25
  aliases;
26
+ props = {};
25
27
  /** @internal */
26
28
  async __runOptions(ctx, resolver) {
27
29
  if (!this?.options?.length) {
@@ -33,8 +35,17 @@ class BaseCommand {
33
35
  try {
34
36
  const option = this.options.find(x => x.name === i.name);
35
37
  const value = resolver.getHoisted(i.name)?.value !== undefined
36
- ? await new Promise((res, rej) => option.value?.({ context: ctx, value: resolver.getValue(i.name) }, res, rej) ||
37
- res(resolver.getValue(i.name)))
38
+ ? await new Promise(
39
+ // biome-ignore lint/suspicious/noAsyncPromiseExecutor: yes
40
+ async (res, rej) => {
41
+ try {
42
+ (await option.value?.({ context: ctx, value: resolver.getValue(i.name) }, res, rej)) ||
43
+ res(resolver.getValue(i.name));
44
+ }
45
+ catch (e) {
46
+ rej(e);
47
+ }
48
+ })
38
49
  : undefined;
39
50
  if (value === undefined) {
40
51
  if (option.required) {
@@ -42,6 +53,7 @@ class BaseCommand {
42
53
  data[i.name] = {
43
54
  failed: true,
44
55
  value: `${i.name} is required but returned no value`,
56
+ parseError: undefined,
45
57
  };
46
58
  continue;
47
59
  }
@@ -57,7 +69,8 @@ class BaseCommand {
57
69
  errored = true;
58
70
  data[i.name] = {
59
71
  failed: true,
60
- value: e instanceof Error ? e.message : `${e}`,
72
+ value: e instanceof Error ? e.message : typeof e === 'string' ? e : (0, node_util_1.inspect)(e),
73
+ parseError: undefined,
61
74
  };
62
75
  }
63
76
  }
@@ -83,6 +96,7 @@ class BaseCommand {
83
96
  return;
84
97
  }
85
98
  // biome-ignore lint/style/noArguments: yes
99
+ // biome-ignore lint/correctness/noUndeclaredVariables: xd
86
100
  if (arguments.length) {
87
101
  // @ts-expect-error
88
102
  context[global ? 'globalMetadata' : 'metadata'][middlewares[index]] = obj;
@@ -115,7 +129,7 @@ class BaseCommand {
115
129
  const data = {
116
130
  name: this.name,
117
131
  type: this.type,
118
- nsfw: this.nsfw || false,
132
+ nsfw: !!this.nsfw,
119
133
  description: this.description,
120
134
  name_localizations: this.name_localizations,
121
135
  description_localizations: this.description_localizations,
@@ -137,6 +151,7 @@ class BaseCommand {
137
151
  Object.setPrototypeOf(this, __tempCommand.prototype);
138
152
  }
139
153
  }
154
+ exports.BaseCommand = BaseCommand;
140
155
  class Command extends BaseCommand {
141
156
  type = v10_1.ApplicationCommandType.ChatInput;
142
157
  groups;
@@ -179,7 +194,7 @@ class SubCommand extends BaseCommand {
179
194
  toJSON() {
180
195
  return {
181
196
  ...super.toJSON(),
182
- options: (this.options ?? []).map(x => ({ ...x, autocomplete: 'autocomplete' in x })),
197
+ options: this.options?.map(x => ({ ...x, autocomplete: 'autocomplete' in x })) ?? [],
183
198
  };
184
199
  }
185
200
  }
@@ -2,7 +2,7 @@ import type { AllChannels, Guild, InferWithPrefix, ReturnCache, WebhookMessage }
2
2
  import type { If, UnionToTuple, When } from '../../common';
3
3
  import type { InteractionCreateBodyRequest, InteractionMessageUpdateBodyRequest } from '../../common/types/write';
4
4
  import { Message, type ChatInputCommandInteraction, type GuildMember, type InteractionGuildMember } from '../../structures';
5
- import { BaseContext } from '../basecontex';
5
+ import { BaseContext } from '../basecontext';
6
6
  import type { RegisteredMiddlewares } from '../decorators';
7
7
  import type { OptionResolver } from '../optionresolver';
8
8
  import type { Command, ContextOptions, OptionsRecord, SubCommand } from './chat';
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CommandContext = void 0;
4
4
  const v10_1 = require("discord-api-types/v10");
5
5
  const structures_1 = require("../../structures");
6
- const basecontex_1 = require("../basecontex");
7
- class CommandContext extends basecontex_1.BaseContext {
6
+ const basecontext_1 = require("../basecontext");
7
+ class CommandContext extends basecontext_1.BaseContext {
8
8
  client;
9
9
  resolver;
10
10
  shardId;
@@ -1,8 +1,8 @@
1
- import type { ApplicationCommandType, LocaleString } from 'discord-api-types/v10';
1
+ import type { ApplicationCommandType, ApplicationIntegrationType, InteractionContextType, LocaleString } from 'discord-api-types/v10';
2
2
  import { type PermissionStrings } from '../../common';
3
- import type { IntegrationTypes, InteractionContextTypes, RegisteredMiddlewares } from '../decorators';
3
+ import type { RegisteredMiddlewares } from '../decorators';
4
4
  import type { MenuCommandContext } from './menucontext';
5
- import type { UsingClient } from './shared';
5
+ import type { ExtraProps, UsingClient } from './shared';
6
6
  export declare abstract class ContextMenuCommand {
7
7
  middlewares: (keyof RegisteredMiddlewares)[];
8
8
  __filePath?: string;
@@ -14,14 +14,15 @@ export declare abstract class ContextMenuCommand {
14
14
  name: string;
15
15
  type: ApplicationCommandType.User | ApplicationCommandType.Message;
16
16
  nsfw?: boolean;
17
- integrationTypes?: IntegrationTypes[];
18
- contexts?: InteractionContextTypes[];
17
+ integrationTypes: ApplicationIntegrationType[];
18
+ contexts: InteractionContextType[];
19
19
  description: string;
20
20
  defaultMemberPermissions?: bigint;
21
21
  botPermissions?: bigint;
22
22
  dm?: boolean;
23
23
  name_localizations?: Partial<Record<LocaleString, string>>;
24
24
  description_localizations?: Partial<Record<LocaleString, string>>;
25
+ props: ExtraProps;
25
26
  toJSON(): {
26
27
  name: string;
27
28
  type: ApplicationCommandType.User | ApplicationCommandType.Message;
@@ -32,8 +33,8 @@ export declare abstract class ContextMenuCommand {
32
33
  guild_id: string[] | undefined;
33
34
  dm_permission: boolean | undefined;
34
35
  default_member_permissions: string | undefined;
35
- contexts: InteractionContextTypes[] | undefined;
36
- integration_types: IntegrationTypes[] | undefined;
36
+ contexts: InteractionContextType[];
37
+ integration_types: ApplicationIntegrationType[];
37
38
  };
38
39
  reload(): Promise<void>;
39
40
  abstract run?(context: MenuCommandContext<any>): any;
@@ -10,62 +10,15 @@ class ContextMenuCommand {
10
10
  name;
11
11
  type;
12
12
  nsfw;
13
- integrationTypes;
14
- contexts;
13
+ integrationTypes = [];
14
+ contexts = [];
15
15
  description;
16
16
  defaultMemberPermissions;
17
17
  botPermissions;
18
18
  dm;
19
19
  name_localizations;
20
20
  description_localizations;
21
- /** @internal */
22
- static __runMiddlewares(context, middlewares, global) {
23
- if (!middlewares.length) {
24
- return Promise.resolve({});
25
- }
26
- let index = 0;
27
- return new Promise(res => {
28
- let running = true;
29
- const pass = () => {
30
- if (!running) {
31
- return;
32
- }
33
- running = false;
34
- return res({ pass: true });
35
- };
36
- function next(obj) {
37
- if (!running) {
38
- return;
39
- }
40
- // biome-ignore lint/style/noArguments: yes
41
- if (arguments.length) {
42
- // @ts-expect-error
43
- context[global ? 'globalMetadata' : 'metadata'][middlewares[index]] = obj;
44
- }
45
- if (++index >= middlewares.length) {
46
- running = false;
47
- return res({});
48
- }
49
- context.client.middlewares[middlewares[index]]({ context, next, stop, pass });
50
- }
51
- const stop = err => {
52
- if (!running) {
53
- return;
54
- }
55
- running = false;
56
- return res({ error: err });
57
- };
58
- context.client.middlewares[middlewares[0]]({ context, next, stop, pass });
59
- });
60
- }
61
- /** @internal */
62
- __runMiddlewares(context) {
63
- return ContextMenuCommand.__runMiddlewares(context, this.middlewares, false);
64
- }
65
- /** @internal */
66
- __runGlobalMiddlewares(context) {
67
- return ContextMenuCommand.__runMiddlewares(context, (context.client.options?.globalMiddlewares ?? []), true);
68
- }
21
+ props = {};
69
22
  toJSON() {
70
23
  return {
71
24
  name: this.name,
@@ -1,7 +1,7 @@
1
1
  import type { ContextMenuCommand, ReturnCache, WebhookMessage } from '../..';
2
2
  import { type InteractionCreateBodyRequest, type InteractionMessageUpdateBodyRequest, type ModalCreateBodyRequest, type UnionToTuple, type When } from '../../common';
3
3
  import { Message, User, type AllChannels, type Guild, type GuildMember, type MessageCommandInteraction, type UserCommandInteraction } from '../../structures';
4
- import { BaseContext } from '../basecontex';
4
+ import { BaseContext } from '../basecontext';
5
5
  import type { RegisteredMiddlewares } from '../decorators';
6
6
  import type { CommandMetadata, ExtendContext, GlobalMetadata, UsingClient } from './shared';
7
7
  export type InteractionTarget<T> = T extends MessageCommandInteraction ? Message : User;
@@ -4,8 +4,8 @@ exports.MenuCommandContext = void 0;
4
4
  const v10_1 = require("discord-api-types/v10");
5
5
  const common_1 = require("../../common");
6
6
  const structures_1 = require("../../structures");
7
- const basecontex_1 = require("../basecontex");
8
- class MenuCommandContext extends basecontex_1.BaseContext {
7
+ const basecontext_1 = require("../basecontext");
8
+ class MenuCommandContext extends basecontext_1.BaseContext {
9
9
  client;
10
10
  interaction;
11
11
  shardId;
@@ -33,7 +33,7 @@ class MenuCommandContext extends basecontex_1.BaseContext {
33
33
  }
34
34
  }
35
35
  get t() {
36
- return this.client.langs.get(this.interaction.locale ?? this.client.langs.defaultLang ?? 'en-US');
36
+ return this.client.t(this.interaction.locale ?? this.client.langs.defaultLang ?? 'en-US');
37
37
  }
38
38
  get fullCommandName() {
39
39
  return this.command.name;
@@ -3,6 +3,8 @@ import type { AutocompleteCallback, MenuCommandContext, OnAutocompleteErrorCallb
3
3
  import type { MessageCommandInteraction, UserCommandInteraction } from '../../structures';
4
4
  import type { CommandContext } from './chatcontext';
5
5
  import type { MiddlewareContext } from './shared';
6
+ import type { ModalContext } from '../../components';
7
+ import type { ComponentContext } from '../../components/componentcontext';
6
8
  export type SeyfertBasicOption<T extends keyof __TypesWrapper, D = {}> = __TypesWrapper[T] & D;
7
9
  export type SeyfertStringOption = SeyfertBasicOption<'String'> & {
8
10
  autocomplete?: AutocompleteCallback;
@@ -63,4 +65,4 @@ export declare function createNumberOption<T extends SeyfertNumberOption = Seyfe
63
65
  export declare function createAttachmentOption<T extends SeyfertAttachmentOption = SeyfertAttachmentOption>(data: T): T & {
64
66
  readonly type: ApplicationCommandOptionType.Attachment;
65
67
  };
66
- export declare function createMiddleware<T = any, C extends CommandContext | MenuCommandContext<MessageCommandInteraction<boolean> | UserCommandInteraction<boolean>> = CommandContext | MenuCommandContext<MessageCommandInteraction<boolean> | UserCommandInteraction<boolean>>>(data: MiddlewareContext<T, C>): MiddlewareContext<T, C>;
68
+ export declare function createMiddleware<T = any, C extends CommandContext | MenuCommandContext<MessageCommandInteraction<boolean> | UserCommandInteraction<boolean>> | ComponentContext | ModalContext = CommandContext | MenuCommandContext<MessageCommandInteraction<boolean> | UserCommandInteraction<boolean>> | ComponentContext | ModalContext>(data: MiddlewareContext<T, C>): MiddlewareContext<T, C>;
@@ -1,3 +1,4 @@
1
+ import type { ChannelType } from 'discord-api-types/v10';
1
2
  import type { BaseClient } from '../../client/base';
2
3
  import type { IsStrictlyUndefined } from '../../common';
3
4
  import type { RegisteredMiddlewares } from '../decorators';
@@ -14,6 +15,8 @@ export interface DefaultLocale {
14
15
  }
15
16
  export interface ExtendContext {
16
17
  }
18
+ export interface ExtraProps {
19
+ }
17
20
  export interface UsingClient extends BaseClient {
18
21
  }
19
22
  export type ParseClient<T extends BaseClient> = T;
@@ -32,12 +35,21 @@ export type CommandMetadata<T extends readonly (keyof RegisteredMiddlewares)[]>
32
35
  ] ? first extends keyof RegisteredMiddlewares ? (MetadataMiddleware<RegisteredMiddlewares[first]> extends never ? {} : {
33
36
  [key in first]: MetadataMiddleware<RegisteredMiddlewares[first]>;
34
37
  }) & (rest extends readonly (keyof RegisteredMiddlewares)[] ? CommandMetadata<rest> : {}) : {} : {};
38
+ export type MessageCommandOptionErrors = ['CHANNEL_TYPES', type: ChannelType[]] | ['STRING_MIN_LENGTH', min: number] | ['STRING_MAX_LENGTH', max: number] | ['STRING_INVALID_CHOICE', choices: readonly {
39
+ name: string;
40
+ value: string;
41
+ }[]] | ['NUMBER_NAN', value: string | undefined] | ['NUMBER_MIN_VALUE', min: number] | ['NUMBER_MAX_VALUE', max: number] | ['NUMBER_INVALID_CHOICE', choices: readonly {
42
+ name: string;
43
+ value: number;
44
+ }[]] | ['OPTION_REQUIRED'] | ['UNKNOWN', error: unknown];
35
45
  export type OnOptionsReturnObject = Record<string, {
36
46
  failed: false;
37
47
  value: unknown;
38
48
  } | {
39
49
  failed: true;
40
50
  value: string;
51
+ parseError: //only for text command
52
+ MessageCommandOptionErrors | undefined;
41
53
  }>;
42
54
  export declare enum IgnoreCommand {
43
55
  Slash = 0,
@@ -0,0 +1,26 @@
1
+ import type { ModalContext } from '../components';
2
+ import type { ContextComponentCommandInteractionMap, ComponentContext } from '../components/componentcontext';
3
+ import type { MessageCommandInteraction, UserCommandInteraction } from '../structures';
4
+ import type { CommandContext } from './applications/chatcontext';
5
+ import type { MenuCommandContext } from './applications/menucontext';
6
+ import type { UsingClient } from './applications/shared';
7
+ export declare class BaseContext {
8
+ readonly client: UsingClient;
9
+ constructor(client: UsingClient);
10
+ /**
11
+ * Gets the proxy object.
12
+ */
13
+ get proxy(): import("..").APIRoutes;
14
+ isChat(): this is CommandContext;
15
+ isMenu(): this is MenuCommandContext<UserCommandInteraction | MessageCommandInteraction>;
16
+ isMenuUser(): this is MenuCommandContext<UserCommandInteraction>;
17
+ isMenuMessage(): this is MenuCommandContext<MessageCommandInteraction>;
18
+ isComponent(): this is ComponentContext<keyof ContextComponentCommandInteractionMap>;
19
+ isModal(): this is ModalContext;
20
+ isButton(): this is ComponentContext<'Button'>;
21
+ isChannelSelectMenu(): this is ComponentContext<'ChannelSelect'>;
22
+ isRoleSelectMenu(): this is ComponentContext<'RoleSelect'>;
23
+ isMentionableSelectMenu(): this is ComponentContext<'MentionableSelect'>;
24
+ isUserSelectMenu(): this is ComponentContext<'UserSelect'>;
25
+ isStringSelectMenu(): this is ComponentContext<'StringSelect'>;
26
+ }