seyfert 3.0.1-dev-14657186698.0 → 3.0.1-dev-14685617998.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.
@@ -91,6 +91,8 @@ export interface BaseClientOptions {
91
91
  globalMiddlewares?: readonly (keyof RegisteredMiddlewares)[];
92
92
  commands?: {
93
93
  defaults?: {
94
+ onBeforeMiddlewares?: (context: CommandContext | MenuCommandContext<any, never>) => unknown;
95
+ onBeforeOptions?: Command['onBeforeOptions'];
94
96
  onRunError?: (context: MenuCommandContext<any, never> | CommandContext, error: unknown) => unknown;
95
97
  onPermissionsFail?: Command['onPermissionsFail'];
96
98
  onBotPermissionsFail?: (context: MenuCommandContext<any, never> | CommandContext, permissions: PermissionStrings) => unknown;
@@ -103,6 +105,7 @@ export interface BaseClientOptions {
103
105
  };
104
106
  components?: {
105
107
  defaults?: {
108
+ onBeforeMiddlewares?: ComponentCommand['onBeforeMiddlewares'];
106
109
  onRunError?: ComponentCommand['onRunError'];
107
110
  onInternalError?: ComponentCommand['onInternalError'];
108
111
  onMiddlewaresError?: ComponentCommand['onMiddlewaresError'];
@@ -111,6 +114,7 @@ export interface BaseClientOptions {
111
114
  };
112
115
  modals?: {
113
116
  defaults?: {
117
+ onBeforeMiddlewares?: ModalCommand['onBeforeMiddlewares'];
114
118
  onRunError?: ModalCommand['onRunError'];
115
119
  onInternalError?: ModalCommand['onInternalError'];
116
120
  onMiddlewaresError?: ModalCommand['onMiddlewaresError'];
@@ -89,6 +89,8 @@ export declare class BaseCommand {
89
89
  integration_types: BaseCommand["integrationTypes"];
90
90
  };
91
91
  reload(): Promise<void>;
92
+ onBeforeMiddlewares?(context: CommandContext): any;
93
+ onBeforeOptions?(context: CommandContext): any;
92
94
  run?(context: CommandContext): any;
93
95
  onAfterRun?(context: CommandContext, error: unknown | undefined): any;
94
96
  onRunError?(context: CommandContext, error: unknown): any;
@@ -37,6 +37,7 @@ export declare abstract class EntryPointCommand {
37
37
  integration_types: ApplicationIntegrationType[];
38
38
  };
39
39
  reload(): Promise<void>;
40
+ onBeforeMiddlewares?(context: EntryPointContext): any;
40
41
  abstract run?(context: EntryPointContext): any;
41
42
  onAfterRun?(context: EntryPointContext, error: unknown | undefined): any;
42
43
  onRunError(context: EntryPointContext<never>, error: unknown): any;
@@ -37,6 +37,7 @@ export declare abstract class ContextMenuCommand {
37
37
  integration_types: ApplicationIntegrationType[];
38
38
  };
39
39
  reload(): Promise<void>;
40
+ onBeforeMiddlewares?(context: MenuCommandContext<any>): any;
40
41
  abstract run?(context: MenuCommandContext<any>): any;
41
42
  onAfterRun?(context: MenuCommandContext<any>, error: unknown | undefined): any;
42
43
  onRunError?(context: MenuCommandContext<any, never>, error: unknown): any;
@@ -33,22 +33,23 @@ class HandleCommand {
33
33
  }
34
34
  }
35
35
  catch (error) {
36
- // pass
36
+ this.client.logger.error(`[${optionsResolver.fullCommandName}] Internal error:`, error);
37
37
  }
38
38
  }
39
39
  async contextMenu(command, interaction, context) {
40
- if (context.guildId && command.botPermissions) {
41
- const permissions = this.checkPermissions(interaction.appPermissions, command.botPermissions);
42
- if (permissions)
43
- return command.onBotPermissionsFail?.(context, permissions);
44
- }
45
- const resultGlobal = await this.runGlobalMiddlewares(command, context);
46
- if (typeof resultGlobal === 'boolean')
47
- return;
48
- const resultMiddle = await this.runMiddlewares(command, context);
49
- if (typeof resultMiddle === 'boolean')
50
- return;
51
40
  try {
41
+ if (context.guildId && command.botPermissions) {
42
+ const permissions = this.checkPermissions(interaction.appPermissions, command.botPermissions);
43
+ if (permissions)
44
+ return await command.onBotPermissionsFail?.(context, permissions);
45
+ }
46
+ await command.onBeforeMiddlewares?.(context);
47
+ const resultGlobal = await this.runGlobalMiddlewares(command, context);
48
+ if (typeof resultGlobal === 'boolean')
49
+ return;
50
+ const resultMiddle = await this.runMiddlewares(command, context);
51
+ if (typeof resultMiddle === 'boolean')
52
+ return;
52
53
  try {
53
54
  await command.run(context);
54
55
  await command.onAfterRun?.(context, undefined);
@@ -62,8 +63,8 @@ class HandleCommand {
62
63
  try {
63
64
  await command.onInternalError?.(this.client, command, error);
64
65
  }
65
- catch {
66
- // pass
66
+ catch (err) {
67
+ this.client.logger.error(`[${command.name}] Internal error:`, err);
67
68
  }
68
69
  }
69
70
  }
@@ -74,18 +75,19 @@ class HandleCommand {
74
75
  return this.contextMenu(command, interaction, context);
75
76
  }
76
77
  async entryPoint(command, interaction, context) {
77
- if (context.guildId && command.botPermissions) {
78
- const permissions = this.checkPermissions(interaction.appPermissions, command.botPermissions);
79
- if (permissions)
80
- return command.onBotPermissionsFail(context, permissions);
81
- }
82
- const resultGlobal = await this.runGlobalMiddlewares(command, context);
83
- if (typeof resultGlobal === 'boolean')
84
- return;
85
- const resultMiddle = await this.runMiddlewares(command, context);
86
- if (typeof resultMiddle === 'boolean')
87
- return;
88
78
  try {
79
+ if (context.guildId && command.botPermissions) {
80
+ const permissions = this.checkPermissions(interaction.appPermissions, command.botPermissions);
81
+ if (permissions)
82
+ return await command.onBotPermissionsFail(context, permissions);
83
+ }
84
+ await command.onBeforeMiddlewares?.(context);
85
+ const resultGlobal = await this.runGlobalMiddlewares(command, context);
86
+ if (typeof resultGlobal === 'boolean')
87
+ return;
88
+ const resultMiddle = await this.runMiddlewares(command, context);
89
+ if (typeof resultMiddle === 'boolean')
90
+ return;
89
91
  try {
90
92
  await command.run(context);
91
93
  await command.onAfterRun?.(context, undefined);
@@ -99,33 +101,35 @@ class HandleCommand {
99
101
  try {
100
102
  await command.onInternalError(this.client, command, error);
101
103
  }
102
- catch {
103
- // pass
104
+ catch (err) {
105
+ this.client.logger.error(`[${command.name}] Internal error:`, err);
104
106
  }
105
107
  }
106
108
  }
107
109
  async chatInput(command, interaction, resolver, context) {
108
- if (context.guildId) {
109
- if (command.botPermissions) {
110
- const permissions = this.checkPermissions(interaction.appPermissions, command.botPermissions);
111
- if (permissions)
112
- return command.onBotPermissionsFail?.(context, permissions);
113
- }
114
- if (command.defaultMemberPermissions) {
115
- const permissions = this.checkPermissions(interaction.member.permissions, command.defaultMemberPermissions);
116
- if (permissions)
117
- return command.onPermissionsFail?.(context, permissions);
118
- }
119
- }
120
- if (!(await this.runOptions(command, context, resolver)))
121
- return;
122
- const resultGlobal = await this.runGlobalMiddlewares(command, context);
123
- if (typeof resultGlobal === 'boolean')
124
- return;
125
- const resultMiddle = await this.runMiddlewares(command, context);
126
- if (typeof resultMiddle === 'boolean')
127
- return;
128
110
  try {
111
+ if (context.guildId) {
112
+ if (command.botPermissions) {
113
+ const permissions = this.checkPermissions(interaction.appPermissions, command.botPermissions);
114
+ if (permissions)
115
+ return await command.onBotPermissionsFail?.(context, permissions);
116
+ }
117
+ if (command.defaultMemberPermissions) {
118
+ const permissions = this.checkPermissions(interaction.member.permissions, command.defaultMemberPermissions);
119
+ if (permissions)
120
+ return await command.onPermissionsFail?.(context, permissions);
121
+ }
122
+ }
123
+ await command.onBeforeOptions?.(context);
124
+ if (!(await this.runOptions(command, context, resolver)))
125
+ return;
126
+ await command.onBeforeMiddlewares?.(context);
127
+ const resultGlobal = await this.runGlobalMiddlewares(command, context);
128
+ if (typeof resultGlobal === 'boolean')
129
+ return;
130
+ const resultMiddle = await this.runMiddlewares(command, context);
131
+ if (typeof resultMiddle === 'boolean')
132
+ return;
129
133
  try {
130
134
  await command.run(context);
131
135
  await command.onAfterRun?.(context, undefined);
@@ -139,8 +143,8 @@ class HandleCommand {
139
143
  try {
140
144
  await command.onInternalError?.(this.client, command, error);
141
145
  }
142
- catch {
143
- // pass
146
+ catch (err) {
147
+ this.client.logger.error(`[${command.name}] Internal error:`, err);
144
148
  }
145
149
  }
146
150
  }
@@ -261,16 +265,16 @@ class HandleCommand {
261
265
  members: {},
262
266
  attachments: {},
263
267
  };
264
- const args = this.argsParser(argsContent, command, message);
265
- const { options, errors } = await this.argsOptionsParser(command, rawMessage, args, resolved);
266
- const optionsResolver = this.makeResolver(self, options, parent, rawMessage.guild_id, resolved);
267
- const context = new _1.CommandContext(self, message, optionsResolver, shardId, command);
268
- //@ts-expect-error
269
- const extendContext = self.options?.context?.(message) ?? {};
270
- Object.assign(context, extendContext);
271
268
  try {
269
+ const args = this.argsParser(argsContent, command, message);
270
+ const { options, errors } = await this.argsOptionsParser(command, rawMessage, args, resolved);
271
+ const optionsResolver = this.makeResolver(self, options, parent, rawMessage.guild_id, resolved);
272
+ const context = new _1.CommandContext(self, message, optionsResolver, shardId, command);
273
+ //@ts-expect-error
274
+ const extendContext = self.options?.context?.(message) ?? {};
275
+ Object.assign(context, extendContext);
272
276
  if (errors.length) {
273
- return command.onOptionsError?.(context, Object.fromEntries(errors.map(x => {
277
+ return await command.onOptionsError?.(context, Object.fromEntries(errors.map(x => {
274
278
  return [
275
279
  x.name,
276
280
  {
@@ -287,19 +291,21 @@ class HandleCommand {
287
291
  const permissions = this.checkPermissions(memberPermissions, command.defaultMemberPermissions);
288
292
  const guild = await this.client.guilds.raw(rawMessage.guild_id);
289
293
  if (permissions && guild.owner_id !== rawMessage.author.id) {
290
- return command.onPermissionsFail?.(context, memberPermissions.keys(permissions));
294
+ return await command.onPermissionsFail?.(context, memberPermissions.keys(permissions));
291
295
  }
292
296
  }
293
297
  if (command.botPermissions) {
294
298
  const appPermissions = await self.members.permissions(rawMessage.guild_id, self.botId);
295
299
  const permissions = this.checkPermissions(appPermissions, command.botPermissions);
296
300
  if (permissions) {
297
- return command.onBotPermissionsFail?.(context, permissions);
301
+ return await command.onBotPermissionsFail?.(context, permissions);
298
302
  }
299
303
  }
300
304
  }
305
+ await command.onBeforeOptions?.(context);
301
306
  if (!(await this.runOptions(command, context, optionsResolver)))
302
307
  return;
308
+ await command.onBeforeMiddlewares?.(context);
303
309
  const resultGlobal = await this.runGlobalMiddlewares(command, context);
304
310
  if (typeof resultGlobal === 'boolean')
305
311
  return;
@@ -319,8 +325,8 @@ class HandleCommand {
319
325
  try {
320
326
  await command.onInternalError?.(this.client, command, error);
321
327
  }
322
- catch {
323
- // http 418
328
+ catch (err) {
329
+ this.client.logger.error(`[${command.name}] Internal error:`, err);
324
330
  }
325
331
  }
326
332
  }
@@ -445,8 +451,8 @@ class HandleCommand {
445
451
  try {
446
452
  await command.onInternalError?.(this.client, command, e);
447
453
  }
448
- catch {
449
- // http 418
454
+ catch (err) {
455
+ this.client.logger.error(`[${command.name}] Internal error:`, err);
450
456
  }
451
457
  }
452
458
  return false;
@@ -467,8 +473,8 @@ class HandleCommand {
467
473
  try {
468
474
  await command.onInternalError?.(this.client, command, e);
469
475
  }
470
- catch {
471
- // http 418
476
+ catch (err) {
477
+ this.client.logger.error(`[${command.name}] Internal error:`, err);
472
478
  }
473
479
  }
474
480
  return false;
@@ -487,17 +493,7 @@ class HandleCommand {
487
493
  async runOptions(command, context, resolver) {
488
494
  const [erroredOptions, result] = await command.__runOptions(context, resolver);
489
495
  if (erroredOptions) {
490
- try {
491
- await command.onOptionsError?.(context, result);
492
- }
493
- catch (e) {
494
- try {
495
- await command.onInternalError?.(this.client, command, e);
496
- }
497
- catch {
498
- // http 418
499
- }
500
- }
496
+ await command.onOptionsError?.(context, result);
501
497
  return false;
502
498
  }
503
499
  return true;
@@ -448,6 +448,7 @@ class CommandHandler extends common_1.BaseHandler {
448
448
  stablishContextCommandDefaults(commandInstance) {
449
449
  if (!(commandInstance instanceof menu_1.ContextMenuCommand))
450
450
  return false;
451
+ commandInstance.onBeforeMiddlewares ??= this.client.options.commands?.defaults?.onBeforeMiddlewares;
451
452
  commandInstance.onAfterRun ??= this.client.options.commands?.defaults?.onAfterRun;
452
453
  commandInstance.onBotPermissionsFail ??= this.client.options.commands?.defaults?.onBotPermissionsFail;
453
454
  commandInstance.onInternalError ??= this.client.options.commands?.defaults?.onInternalError;
@@ -458,6 +459,8 @@ class CommandHandler extends common_1.BaseHandler {
458
459
  stablishCommandDefaults(commandInstance) {
459
460
  if (!(commandInstance instanceof chat_1.Command))
460
461
  return false;
462
+ commandInstance.onBeforeMiddlewares ??= this.client.options.commands?.defaults?.onBeforeMiddlewares;
463
+ commandInstance.onBeforeOptions ??= this.client.options.commands?.defaults?.onBeforeOptions;
461
464
  commandInstance.onAfterRun ??= this.client.options.commands?.defaults?.onAfterRun;
462
465
  commandInstance.onBotPermissionsFail ??= this.client.options.commands?.defaults?.onBotPermissionsFail;
463
466
  commandInstance.onInternalError ??= this.client.options.commands?.defaults?.onInternalError;
@@ -470,6 +473,14 @@ class CommandHandler extends common_1.BaseHandler {
470
473
  }
471
474
  stablishSubCommandDefaults(commandInstance, option) {
472
475
  option.middlewares = (commandInstance.middlewares ?? []).concat(option.middlewares ?? []);
476
+ option.onBeforeMiddlewares =
477
+ option.onBeforeMiddlewares?.bind(option) ??
478
+ commandInstance.onBeforeMiddlewares?.bind(commandInstance) ??
479
+ this.client.options.commands?.defaults?.onBeforeMiddlewares;
480
+ option.onBeforeOptions =
481
+ option.onBeforeOptions?.bind(option) ??
482
+ commandInstance.onBeforeOptions?.bind(commandInstance) ??
483
+ this.client.options.commands?.defaults?.onBeforeOptions;
473
484
  option.onMiddlewaresError =
474
485
  option.onMiddlewaresError?.bind(option) ??
475
486
  commandInstance.onMiddlewaresError?.bind(commandInstance) ??
@@ -1,6 +1,6 @@
1
1
  import type { RawFile } from '../../api';
2
2
  import type { Attachment, AttachmentBuilder, Embed, Modal, PollBuilder, TopLevelBuilders } from '../../builders';
3
- import type { APIEmbed, APIInteractionResponseCallbackData, APIInteractionResponseChannelMessageWithSource, APIModalInteractionResponse, RESTAPIPollCreate, RESTPatchAPIChannelMessageJSONBody, RESTPatchAPIWebhookWithTokenMessageJSONBody, RESTPostAPIChannelMessageJSONBody, RESTPostAPIWebhookWithTokenJSONBody } from '../../types';
3
+ import type { APIEmbed, APIInteractionResponseCallbackData, APIInteractionResponseChannelMessageWithSource, APIModalInteractionResponse, MessageFlags, RESTAPIPollCreate, RESTPatchAPIChannelMessageJSONBody, RESTPatchAPIWebhookWithTokenMessageJSONBody, RESTPostAPIChannelMessageJSONBody, RESTPostAPIWebhookWithTokenJSONBody } from '../../types';
4
4
  import type { OmitInsert } from './util';
5
5
  export interface ResolverProps {
6
6
  embeds?: Embed[] | APIEmbed[] | undefined;
@@ -14,7 +14,9 @@ export type MessageCreateBodyRequest = OmitInsert<RESTPostAPIChannelMessageJSONB
14
14
  export type MessageUpdateBodyRequest = OmitInsert<RESTPatchAPIChannelMessageJSONBody, 'components' | 'embeds', ResolverProps>;
15
15
  export type MessageWebhookCreateBodyRequest = OmitInsert<RESTPostAPIWebhookWithTokenJSONBody, 'components' | 'embeds' | 'poll', SendResolverProps>;
16
16
  export type MessageWebhookUpdateBodyRequest = OmitInsert<RESTPatchAPIWebhookWithTokenMessageJSONBody, 'components' | 'embeds' | 'poll', ResolverProps>;
17
- export type InteractionMessageUpdateBodyRequest = OmitInsert<RESTPatchAPIWebhookWithTokenMessageJSONBody, 'components' | 'embeds' | 'poll', SendResolverProps>;
17
+ export type InteractionMessageUpdateBodyRequest = OmitInsert<RESTPatchAPIWebhookWithTokenMessageJSONBody, 'components' | 'embeds' | 'poll', SendResolverProps> & {
18
+ flags?: MessageFlags;
19
+ };
18
20
  export type ComponentInteractionMessageUpdate = OmitInsert<APIInteractionResponseCallbackData, 'components' | 'embeds', ResolverProps>;
19
21
  export type InteractionCreateBodyRequest = OmitInsert<APIInteractionResponseChannelMessageWithSource['data'], 'components' | 'embeds' | 'poll', SendResolverProps>;
20
22
  export type ModalCreateBodyRequest = APIModalInteractionResponse['data'] | Modal;
@@ -16,6 +16,7 @@ export declare abstract class ComponentCommand {
16
16
  middlewares: (keyof RegisteredMiddlewares)[];
17
17
  props: ExtraProps;
18
18
  get cType(): number;
19
+ onBeforeMiddlewares?(context: ComponentContext): any;
19
20
  onAfterRun?(context: ComponentContext, error: unknown | undefined): any;
20
21
  onRunError?(context: ComponentContext, error: unknown): any;
21
22
  onMiddlewaresError?(context: ComponentContext, error: string): any;
@@ -152,6 +152,7 @@ class ComponentHandler extends common_1.BaseHandler {
152
152
  component.onMiddlewaresError ??= this.client.options?.[is]?.defaults?.onMiddlewaresError;
153
153
  component.onRunError ??= this.client.options?.[is]?.defaults?.onRunError;
154
154
  component.onAfterRun ??= this.client.options?.[is]?.defaults?.onAfterRun;
155
+ component.onBeforeMiddlewares ??= this.client.options?.[is]?.defaults?.onBeforeMiddlewares;
155
156
  }
156
157
  set(instances) {
157
158
  for (const i of instances) {
@@ -237,19 +238,20 @@ class ComponentHandler extends common_1.BaseHandler {
237
238
  }
238
239
  async execute(i, context) {
239
240
  try {
241
+ await i.onBeforeMiddlewares?.(context);
240
242
  const resultRunGlobalMiddlewares = await commands_1.BaseCommand.__runMiddlewares(context, (context.client.options?.globalMiddlewares ?? []), true);
241
243
  if (resultRunGlobalMiddlewares.pass) {
242
244
  return;
243
245
  }
244
246
  if ('error' in resultRunGlobalMiddlewares) {
245
- return i.onMiddlewaresError?.(context, resultRunGlobalMiddlewares.error ?? 'Unknown error');
247
+ return await i.onMiddlewaresError?.(context, resultRunGlobalMiddlewares.error ?? 'Unknown error');
246
248
  }
247
249
  const resultRunMiddlewares = await commands_1.BaseCommand.__runMiddlewares(context, i.middlewares, false);
248
250
  if (resultRunMiddlewares.pass) {
249
251
  return;
250
252
  }
251
253
  if ('error' in resultRunMiddlewares) {
252
- return i.onMiddlewaresError?.(context, resultRunMiddlewares.error ?? 'Unknown error');
254
+ return await i.onMiddlewaresError?.(context, resultRunMiddlewares.error ?? 'Unknown error');
253
255
  }
254
256
  try {
255
257
  await i.run(context);
@@ -264,9 +266,8 @@ class ComponentHandler extends common_1.BaseHandler {
264
266
  try {
265
267
  await i.onInternalError?.(this.client, error);
266
268
  }
267
- catch (e) {
268
- // supress error
269
- this.logger.error(e);
269
+ catch (err) {
270
+ this.client.logger.error(`[${i.customId ?? 'Component/Modal command'}] Internal error:`, err);
270
271
  }
271
272
  }
272
273
  }
@@ -10,6 +10,7 @@ export declare abstract class ModalCommand {
10
10
  abstract run(context: ModalContext): any;
11
11
  middlewares: (keyof RegisteredMiddlewares)[];
12
12
  props: ExtraProps;
13
+ onBeforeMiddlewares?(context: ModalContext): any;
13
14
  onAfterRun?(context: ModalContext, error: unknown | undefined): any;
14
15
  onRunError?(context: ModalContext, error: unknown): any;
15
16
  onMiddlewaresError?(context: ModalContext, error: string): any;
@@ -277,8 +277,8 @@ class Interaction extends BaseInteraction {
277
277
  }
278
278
  async editOrReply(body, fetchReply) {
279
279
  if (await this.replied) {
280
- const { content, embeds, allowed_mentions, components, files, attachments, poll } = body;
281
- return this.editResponse({ content, embeds, allowed_mentions, components, files, attachments, poll });
280
+ const { content, embeds, allowed_mentions, components, files, attachments, poll, flags } = body;
281
+ return this.editResponse({ content, embeds, allowed_mentions, components, files, attachments, poll, flags });
282
282
  }
283
283
  return this.write(body, fetchReply);
284
284
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "seyfert",
3
- "version": "3.0.1-dev-14657186698.0",
3
+ "version": "3.0.1-dev-14685617998.0",
4
4
  "description": "The most advanced framework for discord bots",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",