seyfert 2.0.0 → 2.1.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 (81) hide show
  1. package/lib/api/Routes/interactions.d.ts +8 -2
  2. package/lib/api/Routes/skus.d.ts +11 -0
  3. package/lib/api/Routes/skus.js +2 -0
  4. package/lib/api/api.d.ts +1 -1
  5. package/lib/api/api.js +14 -12
  6. package/lib/api/shared.d.ts +1 -1
  7. package/lib/api/utils/constants.d.ts +1 -1
  8. package/lib/api/utils/constants.js +1 -1
  9. package/lib/builders/Attachment.d.ts +1 -1
  10. package/lib/builders/Attachment.js +12 -12
  11. package/lib/cache/index.d.ts +4 -1
  12. package/lib/cache/index.js +11 -3
  13. package/lib/client/base.d.ts +3 -3
  14. package/lib/client/base.js +8 -3
  15. package/lib/client/client.d.ts +4 -0
  16. package/lib/client/client.js +30 -14
  17. package/lib/client/httpclient.js +2 -2
  18. package/lib/client/workerclient.d.ts +3 -2
  19. package/lib/client/workerclient.js +23 -11
  20. package/lib/commands/applications/entryPoint.d.ts +46 -0
  21. package/lib/commands/applications/entryPoint.js +56 -0
  22. package/lib/commands/applications/entrycontext.d.ts +40 -0
  23. package/lib/commands/applications/entrycontext.js +85 -0
  24. package/lib/commands/applications/options.d.ts +3 -2
  25. package/lib/commands/decorators.d.ts +11 -17
  26. package/lib/commands/decorators.js +3 -0
  27. package/lib/commands/handle.d.ts +6 -5
  28. package/lib/commands/handle.js +42 -0
  29. package/lib/commands/handler.d.ts +6 -4
  30. package/lib/commands/handler.js +6 -1
  31. package/lib/commands/index.d.ts +2 -0
  32. package/lib/commands/index.js +2 -0
  33. package/lib/commands/optionresolver.js +1 -1
  34. package/lib/common/bot/watcher.d.ts +1 -1
  35. package/lib/common/it/utils.d.ts +10 -3
  36. package/lib/common/it/utils.js +10 -0
  37. package/lib/common/shorters/interaction.d.ts +1 -1
  38. package/lib/common/types/util.d.ts +1 -1
  39. package/lib/common/types/write.d.ts +2 -2
  40. package/lib/deps/mixer.js +6 -1
  41. package/lib/events/handler.js +3 -3
  42. package/lib/events/hooks/custom.d.ts +1 -0
  43. package/lib/events/hooks/custom.js +5 -1
  44. package/lib/events/hooks/subscriptions.d.ts +35 -0
  45. package/lib/events/hooks/subscriptions.js +16 -0
  46. package/lib/structures/Interaction.d.ts +24 -4
  47. package/lib/structures/Interaction.js +54 -5
  48. package/lib/structures/Message.d.ts +0 -3
  49. package/lib/structures/Message.js +0 -3
  50. package/lib/structures/channels.js +2 -2
  51. package/lib/structures/extra/BaseGuild.d.ts +11 -1
  52. package/lib/structures/extra/BaseGuild.js +27 -0
  53. package/lib/types/gateway.d.ts +19 -2
  54. package/lib/types/payloads/_interactions/_applicationCommands/chatInput.d.ts +6 -1
  55. package/lib/types/payloads/_interactions/applicationCommands.d.ts +41 -6
  56. package/lib/types/payloads/_interactions/applicationCommands.js +28 -1
  57. package/lib/types/payloads/_interactions/responses.d.ts +74 -2
  58. package/lib/types/payloads/_interactions/responses.js +4 -0
  59. package/lib/types/payloads/channel.d.ts +44 -4
  60. package/lib/types/payloads/channel.js +5 -1
  61. package/lib/types/payloads/monetization.d.ts +29 -1
  62. package/lib/types/payloads/monetization.js +10 -1
  63. package/lib/types/rest/channel.d.ts +4 -17
  64. package/lib/types/rest/interactions.d.ts +30 -8
  65. package/lib/types/rest/monetization.d.ts +22 -1
  66. package/lib/types/rest/webhook.d.ts +2 -2
  67. package/lib/types/utils/index.d.ts +16 -5
  68. package/lib/types/utils/index.js +15 -4
  69. package/lib/websocket/SharedTypes.d.ts +9 -3
  70. package/lib/websocket/constants/index.d.ts +3 -2
  71. package/lib/websocket/constants/index.js +11 -1
  72. package/lib/websocket/discord/shard.d.ts +3 -2
  73. package/lib/websocket/discord/shard.js +25 -11
  74. package/lib/websocket/discord/sharder.js +59 -1
  75. package/lib/websocket/discord/shared.d.ts +21 -1
  76. package/lib/websocket/discord/socket/custom.d.ts +1 -1
  77. package/lib/websocket/discord/socket/custom.js +51 -34
  78. package/lib/websocket/discord/worker.d.ts +2 -1
  79. package/lib/websocket/discord/workermanager.d.ts +2 -1
  80. package/lib/websocket/discord/workermanager.js +30 -13
  81. package/package.json +8 -3
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EntryPointCommand = void 0;
4
+ const common_1 = require("../../common");
5
+ const types_1 = require("../../types");
6
+ class EntryPointCommand {
7
+ middlewares = [];
8
+ __filePath;
9
+ __t;
10
+ name;
11
+ type = types_1.ApplicationCommandType.PrimaryEntryPoint;
12
+ nsfw;
13
+ integrationTypes = [];
14
+ contexts = [];
15
+ description;
16
+ botPermissions;
17
+ dm;
18
+ handler;
19
+ name_localizations;
20
+ description_localizations;
21
+ props = {};
22
+ toJSON() {
23
+ return {
24
+ handler: this.handler,
25
+ name: this.name,
26
+ type: this.type,
27
+ nsfw: this.nsfw,
28
+ default_member_permissions: null,
29
+ guild_id: null,
30
+ description: this.description,
31
+ name_localizations: this.name_localizations,
32
+ description_localizations: this.description_localizations,
33
+ dm_permission: this.dm,
34
+ contexts: this.contexts,
35
+ integration_types: this.integrationTypes,
36
+ };
37
+ }
38
+ async reload() {
39
+ delete require.cache[this.__filePath];
40
+ const __tempCommand = await (0, common_1.magicImport)(this.__filePath).then(x => x.default ?? x);
41
+ Object.setPrototypeOf(this, __tempCommand.prototype);
42
+ }
43
+ onRunError(context, error) {
44
+ context.client.logger.fatal(`${this.name}.<onRunError>`, context.author.id, error);
45
+ }
46
+ onMiddlewaresError(context, error) {
47
+ context.client.logger.fatal(`${this.name}.<onMiddlewaresError>`, context.author.id, error);
48
+ }
49
+ onBotPermissionsFail(context, permissions) {
50
+ context.client.logger.fatal(`${this.name}.<onBotPermissionsFail>`, context.author.id, permissions);
51
+ }
52
+ onInternalError(client, command, error) {
53
+ client.logger.fatal(command.name, error);
54
+ }
55
+ }
56
+ exports.EntryPointCommand = EntryPointCommand;
@@ -0,0 +1,40 @@
1
+ import type { ReturnCache } from '../..';
2
+ import type { InteractionCreateBodyRequest, InteractionMessageUpdateBodyRequest, ModalCreateBodyRequest, UnionToTuple, When } from '../../common';
3
+ import type { AllChannels, EntryPointInteraction } from '../../structures';
4
+ import { BaseContext } from '../basecontext';
5
+ import type { RegisteredMiddlewares } from '../decorators';
6
+ import type { CommandMetadata, ExtendContext, GlobalMetadata, UsingClient } from './shared';
7
+ import type { GuildMemberStructure, GuildStructure, MessageStructure, WebhookMessageStructure } from '../../client/transformers';
8
+ import type { EntryPointCommand } from './entryPoint';
9
+ export interface EntryPointContext<M extends keyof RegisteredMiddlewares = never> extends BaseContext, ExtendContext {
10
+ }
11
+ export declare class EntryPointContext<M extends keyof RegisteredMiddlewares = never> extends BaseContext {
12
+ readonly client: UsingClient;
13
+ readonly interaction: EntryPointInteraction;
14
+ readonly shardId: number;
15
+ readonly command: EntryPointCommand;
16
+ constructor(client: UsingClient, interaction: EntryPointInteraction, shardId: number, command: EntryPointCommand);
17
+ metadata: CommandMetadata<UnionToTuple<M>>;
18
+ globalMetadata: GlobalMetadata;
19
+ get t(): import("../..").__InternalParseLocale<import("./shared").DefaultLocale> & {
20
+ get(locale?: string): import("./shared").DefaultLocale;
21
+ };
22
+ get fullCommandName(): string;
23
+ write<FR extends boolean = false>(body: InteractionCreateBodyRequest, fetchReply?: FR): Promise<When<FR, WebhookMessageStructure, void | WebhookMessageStructure>>;
24
+ modal(body: ModalCreateBodyRequest): Promise<void>;
25
+ deferReply(ephemeral?: boolean): Promise<void>;
26
+ editResponse(body: InteractionMessageUpdateBodyRequest): Promise<import("../..").WebhookMessage>;
27
+ deleteResponse(): Promise<void | undefined>;
28
+ editOrReply<FR extends boolean = false>(body: InteractionCreateBodyRequest | InteractionMessageUpdateBodyRequest, fetchReply?: FR): Promise<When<FR, WebhookMessageStructure | MessageStructure, void | WebhookMessageStructure | MessageStructure>>;
29
+ fetchResponse(): Promise<import("../..").WebhookMessage | undefined>;
30
+ channel(mode?: 'rest' | 'flow'): Promise<AllChannels>;
31
+ channel(mode?: 'cache'): ReturnCache<AllChannels>;
32
+ me(mode?: 'rest' | 'flow'): Promise<GuildMemberStructure>;
33
+ me(mode?: 'cache'): ReturnCache<GuildMemberStructure | undefined>;
34
+ guild(mode?: 'rest' | 'flow'): Promise<GuildStructure<'cached' | 'api'> | undefined>;
35
+ guild(mode?: 'cache'): ReturnCache<GuildStructure<'cached'> | undefined>;
36
+ get guildId(): string | undefined;
37
+ get channelId(): string;
38
+ get author(): import("../..").User;
39
+ get member(): import("../..").InteractionGuildMember | undefined;
40
+ }
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EntryPointContext = void 0;
4
+ const types_1 = require("../../types");
5
+ const basecontext_1 = require("../basecontext");
6
+ class EntryPointContext extends basecontext_1.BaseContext {
7
+ client;
8
+ interaction;
9
+ shardId;
10
+ command;
11
+ constructor(client, interaction, shardId, command) {
12
+ super(client);
13
+ this.client = client;
14
+ this.interaction = interaction;
15
+ this.shardId = shardId;
16
+ this.command = command;
17
+ }
18
+ metadata = {};
19
+ globalMetadata = {};
20
+ get t() {
21
+ return this.client.t(this.interaction.locale ?? this.client.langs.defaultLang ?? 'en-US');
22
+ }
23
+ get fullCommandName() {
24
+ return this.command.name;
25
+ }
26
+ write(body, fetchReply) {
27
+ return this.interaction.write(body, fetchReply);
28
+ }
29
+ modal(body) {
30
+ return this.interaction.modal(body);
31
+ }
32
+ deferReply(ephemeral = false) {
33
+ return this.interaction.deferReply(ephemeral ? types_1.MessageFlags.Ephemeral : undefined);
34
+ }
35
+ editResponse(body) {
36
+ return this.interaction.editResponse(body);
37
+ }
38
+ deleteResponse() {
39
+ return this.interaction.deleteResponse();
40
+ }
41
+ editOrReply(body, fetchReply) {
42
+ return this.interaction.editOrReply(body, fetchReply);
43
+ }
44
+ fetchResponse() {
45
+ return this.interaction.fetchResponse();
46
+ }
47
+ channel(mode = 'cache') {
48
+ if (this.interaction.channel && mode === 'cache')
49
+ return this.client.cache.adapter.isAsync ? Promise.resolve(this.interaction.channel) : this.interaction.channel;
50
+ return this.client.channels.fetch(this.channelId, mode === 'rest');
51
+ }
52
+ me(mode = 'cache') {
53
+ if (!this.guildId)
54
+ return mode === 'cache' ? (this.client.cache.adapter.isAsync ? Promise.resolve() : undefined) : Promise.resolve();
55
+ switch (mode) {
56
+ case 'cache':
57
+ return this.client.cache.members?.get(this.client.botId, this.guildId);
58
+ default:
59
+ return this.client.members.fetch(this.guildId, this.client.botId, mode === 'rest');
60
+ }
61
+ }
62
+ guild(mode = 'cache') {
63
+ if (!this.guildId)
64
+ return (mode === 'cache' ? (this.client.cache.adapter.isAsync ? Promise.resolve() : undefined) : Promise.resolve());
65
+ switch (mode) {
66
+ case 'cache':
67
+ return this.client.cache.guilds?.get(this.guildId);
68
+ default:
69
+ return this.client.guilds.fetch(this.guildId, mode === 'rest');
70
+ }
71
+ }
72
+ get guildId() {
73
+ return this.interaction.guildId;
74
+ }
75
+ get channelId() {
76
+ return this.interaction.channelId;
77
+ }
78
+ get author() {
79
+ return this.interaction.user;
80
+ }
81
+ get member() {
82
+ return this.interaction.member;
83
+ }
84
+ }
85
+ exports.EntryPointContext = EntryPointContext;
@@ -1,5 +1,5 @@
1
1
  import { ApplicationCommandOptionType, type APIApplicationCommandOptionChoice, type ChannelType } from '../../types';
2
- import type { AutocompleteCallback, MenuCommandContext, OnAutocompleteErrorCallback, ReturnOptionsTypes, __TypesWrapper } from '..';
2
+ import type { AutocompleteCallback, EntryPointContext, MenuCommandContext, OnAutocompleteErrorCallback, ReturnOptionsTypes, __TypesWrapper } from '..';
3
3
  import type { MessageCommandInteraction, UserCommandInteraction } from '../../structures';
4
4
  import type { CommandContext } from './chatcontext';
5
5
  import type { MiddlewareContext } from './shared';
@@ -65,4 +65,5 @@ export declare function createNumberOption<T extends SeyfertNumberOption = Seyfe
65
65
  export declare function createAttachmentOption<T extends SeyfertAttachmentOption = SeyfertAttachmentOption>(data: T): T & {
66
66
  readonly type: ApplicationCommandOptionType.Attachment;
67
67
  };
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>;
68
+ export type AnyContext = CommandContext | MenuCommandContext<MessageCommandInteraction<boolean> | UserCommandInteraction<boolean>> | ComponentContext | ModalContext | EntryPointContext;
69
+ export declare function createMiddleware<T = any, C extends AnyContext = AnyContext>(data: MiddlewareContext<T, C>): MiddlewareContext<T, C>;
@@ -1,10 +1,16 @@
1
- import { ApplicationCommandType, ApplicationIntegrationType, InteractionContextType, type LocaleString } from '../types';
1
+ import { ApplicationCommandType, ApplicationIntegrationType, type EntryPointCommandHandlerType, InteractionContextType, type LocaleString } from '../types';
2
2
  import type { FlatObjectKeys, PermissionStrings } from '../common';
3
3
  import type { CommandOption, OptionsRecord, SubCommand } from './applications/chat';
4
4
  import type { DefaultLocale, ExtraProps, IgnoreCommand, MiddlewareContext } from './applications/shared';
5
5
  export interface RegisteredMiddlewares {
6
6
  }
7
- type DeclareOptions = {
7
+ export type CommandDeclareOptions = DecoratorDeclareOptions | (Omit<DecoratorDeclareOptions, 'description'> & {
8
+ type: ApplicationCommandType.User | ApplicationCommandType.Message;
9
+ }) | (Omit<DecoratorDeclareOptions, 'ignore' | 'aliases' | 'guildId'> & {
10
+ type: ApplicationCommandType.PrimaryEntryPoint;
11
+ handler: EntryPointCommandHandlerType;
12
+ });
13
+ export interface DecoratorDeclareOptions {
8
14
  name: string;
9
15
  description: string;
10
16
  botPermissions?: PermissionStrings | bigint;
@@ -16,19 +22,7 @@ type DeclareOptions = {
16
22
  ignore?: IgnoreCommand;
17
23
  aliases?: string[];
18
24
  props?: ExtraProps;
19
- } | (Omit<{
20
- name: string;
21
- description: string;
22
- botPermissions?: PermissionStrings | bigint;
23
- defaultMemberPermissions?: PermissionStrings | bigint;
24
- guildId?: string[];
25
- nsfw?: boolean;
26
- integrationTypes?: (keyof typeof ApplicationIntegrationType)[];
27
- contexts?: (keyof typeof InteractionContextType)[];
28
- props?: ExtraProps;
29
- }, 'type' | 'description'> & {
30
- type: ApplicationCommandType.User | ApplicationCommandType.Message;
31
- });
25
+ }
32
26
  export declare function Locales({ name: names, description: descriptions, }: {
33
27
  name?: [language: LocaleString, value: string][];
34
28
  description?: [language: LocaleString, value: string][];
@@ -121,7 +115,7 @@ export declare function Middlewares(cbs: readonly (keyof RegisteredMiddlewares)[
121
115
  middlewares: readonly never[];
122
116
  };
123
117
  } & T;
124
- export declare function Declare(declare: DeclareOptions): <T extends {
118
+ export declare function Declare(declare: CommandDeclareOptions): <T extends {
125
119
  new (...args: any[]): {};
126
120
  }>(target: T) => {
127
121
  new (...args: any[]): {
@@ -137,6 +131,6 @@ export declare function Declare(declare: DeclareOptions): <T extends {
137
131
  guildId?: string[];
138
132
  ignore?: IgnoreCommand;
139
133
  aliases?: string[];
134
+ handler?: EntryPointCommandHandlerType;
140
135
  };
141
136
  } & T;
142
- export {};
@@ -97,6 +97,7 @@ function Declare(declare) {
97
97
  guildId;
98
98
  ignore;
99
99
  aliases;
100
+ handler;
100
101
  constructor(...args) {
101
102
  super(...args);
102
103
  if ('description' in declare)
@@ -109,6 +110,8 @@ function Declare(declare) {
109
110
  this.ignore = declare.ignore;
110
111
  if ('aliases' in declare)
111
112
  this.aliases = declare.aliases;
113
+ if ('handler' in declare)
114
+ this.handler = declare.handler;
112
115
  // check if all properties are valid
113
116
  }
114
117
  };
@@ -1,6 +1,6 @@
1
1
  import { type APIApplicationCommandInteraction, type APIInteraction, type GatewayMessageCreateDispatchData, type APIApplicationCommandInteractionDataOption, ApplicationCommandOptionType } from '../types';
2
- import { Command, type ContextOptionsResolved, type UsingClient, type CommandAutocompleteOption, type ContextMenuCommand, MenuCommandContext, CommandContext, SubCommand, type CommandOption, type MessageCommandOptionErrors } from '.';
3
- import { AutocompleteInteraction, type ComponentInteraction, type ModalSubmitInteraction, type ChatInputCommandInteraction, type MessageCommandInteraction, type UserCommandInteraction, type __InternalReplyFunction } from '../structures';
2
+ import { Command, type ContextOptionsResolved, type UsingClient, type CommandAutocompleteOption, type ContextMenuCommand, MenuCommandContext, CommandContext, SubCommand, type CommandOption, type MessageCommandOptionErrors, EntryPointContext, type EntryPointCommand } from '.';
3
+ import { AutocompleteInteraction, type ComponentInteraction, type ModalSubmitInteraction, type ChatInputCommandInteraction, type MessageCommandInteraction, type UserCommandInteraction, type __InternalReplyFunction, type EntryPointInteraction } from '../structures';
4
4
  import type { PermissionsBitField } from '../structures/extra/Permissions';
5
5
  import type { MakeRequired } from '../common';
6
6
  import { type MessageStructure, Transformers, type OptionResolverStructure } from '../client/transformers';
@@ -18,6 +18,7 @@ export declare class HandleCommand {
18
18
  autocomplete(interaction: AutocompleteInteraction, optionsResolver: OptionResolverStructure, command?: CommandAutocompleteOption): Promise<void>;
19
19
  contextMenuMessage(command: ContextMenuCommand, interaction: MessageCommandInteraction, context: MenuCommandContext<MessageCommandInteraction>): Promise<any>;
20
20
  contextMenuUser(command: ContextMenuCommand, interaction: UserCommandInteraction, context: MenuCommandContext<UserCommandInteraction>): Promise<any>;
21
+ entryPoint(command: EntryPointCommand, interaction: EntryPointInteraction, context: EntryPointContext): Promise<any>;
21
22
  chatInput(command: Command | SubCommand, interaction: ChatInputCommandInteraction, resolver: OptionResolverStructure, context: CommandContext): Promise<any>;
22
23
  modal(interaction: ModalSubmitInteraction): Promise<void>;
23
24
  messageComponent(interaction: ComponentInteraction): Promise<void>;
@@ -30,7 +31,7 @@ export declare class HandleCommand {
30
31
  getCommandFromContent(commandRaw: string[]): CommandFromContent;
31
32
  makeResolver(...args: Parameters<(typeof Transformers)['OptionResolver']>): import("./optionresolver").OptionResolver;
32
33
  getParentMessageCommand(rawParentName: string): Command | ContextMenuCommand | undefined;
33
- getCommand<T extends Command | ContextMenuCommand>(data: {
34
+ getCommand<T extends Command | ContextMenuCommand | EntryPointCommand>(data: {
34
35
  guild_id?: string;
35
36
  name: string;
36
37
  }): T | undefined;
@@ -39,11 +40,11 @@ export declare class HandleCommand {
39
40
  fetchUser(_option: CommandOptionWithType, query: string): Promise<import("../types").APIUser | null>;
40
41
  fetchMember(_option: CommandOptionWithType, query: string, guildId: string): Promise<import("../types").APIGuildMember | null>;
41
42
  fetchRole(_option: CommandOptionWithType, query: string, guildId?: string): Promise<import("../types").APIRole | null | undefined>;
42
- runGlobalMiddlewares(command: Command | ContextMenuCommand | SubCommand, context: CommandContext<{}, never> | MenuCommandContext<any>): Promise<false | {
43
+ runGlobalMiddlewares(command: Command | ContextMenuCommand | SubCommand | EntryPointCommand, context: CommandContext<{}, never> | MenuCommandContext<any> | EntryPointContext): Promise<false | {
43
44
  error?: string;
44
45
  pass?: boolean;
45
46
  }>;
46
- runMiddlewares(command: Command | ContextMenuCommand | SubCommand, context: CommandContext<{}, never> | MenuCommandContext<any>): Promise<false | {
47
+ runMiddlewares(command: Command | ContextMenuCommand | SubCommand | EntryPointCommand, context: CommandContext<{}, never> | MenuCommandContext<any> | EntryPointContext): Promise<false | {
47
48
  error?: string;
48
49
  pass?: boolean;
49
50
  }>;
@@ -70,6 +70,37 @@ class HandleCommand {
70
70
  }
71
71
  }
72
72
  }
73
+ async entryPoint(command, interaction, context) {
74
+ if (command.botPermissions && interaction.appPermissions) {
75
+ const permissions = this.checkPermissions(interaction.appPermissions, command.botPermissions);
76
+ if (permissions)
77
+ return command.onBotPermissionsFail?.(context, permissions);
78
+ }
79
+ const resultGlobal = await this.runGlobalMiddlewares(command, context);
80
+ if (typeof resultGlobal === 'boolean')
81
+ return;
82
+ const resultMiddle = await this.runMiddlewares(command, context);
83
+ if (typeof resultMiddle === 'boolean')
84
+ return;
85
+ try {
86
+ try {
87
+ await command.run(context);
88
+ await command.onAfterRun?.(context, undefined);
89
+ }
90
+ catch (error) {
91
+ await command.onRunError(context, error);
92
+ await command.onAfterRun?.(context, error);
93
+ }
94
+ }
95
+ catch (error) {
96
+ try {
97
+ await command.onInternalError(this.client, command, error);
98
+ }
99
+ catch {
100
+ // pass
101
+ }
102
+ }
103
+ }
73
104
  async chatInput(command, interaction, resolver, context) {
74
105
  if (command.botPermissions && interaction.appPermissions) {
75
106
  const permissions = this.checkPermissions(interaction.appPermissions, command.botPermissions);
@@ -145,6 +176,17 @@ class HandleCommand {
145
176
  this.contextMenuUser(data.command, data.interaction, data.context);
146
177
  break;
147
178
  }
179
+ case types_1.ApplicationCommandType.PrimaryEntryPoint: {
180
+ const command = this.client.commands?.entryPoint;
181
+ if (!command?.run)
182
+ return;
183
+ const interaction = structures_1.BaseInteraction.from(this.client, body, __reply);
184
+ const context = new _1.EntryPointContext(this.client, interaction, shardId, command);
185
+ const extendContext = this.client.options?.context?.(interaction) ?? {};
186
+ Object.assign(context, extendContext);
187
+ await this.entryPoint(command, interaction, context);
188
+ break;
189
+ }
148
190
  case types_1.ApplicationCommandType.ChatInput: {
149
191
  const parentCommand = this.getCommand(body.data);
150
192
  const optionsResolver = this.makeResolver(this.client, body.data.options ?? [], parentCommand, body.guild_id, body.data.resolved);
@@ -4,10 +4,12 @@ import { BaseHandler } from '../common';
4
4
  import { Command, type CommandOption, SubCommand } from './applications/chat';
5
5
  import { ContextMenuCommand } from './applications/menu';
6
6
  import type { UsingClient } from './applications/shared';
7
+ import type { EntryPointCommand } from '.';
7
8
  export declare class CommandHandler extends BaseHandler {
8
9
  protected logger: Logger;
9
10
  protected client: UsingClient;
10
11
  values: (Command | ContextMenuCommand)[];
12
+ entryPoint: EntryPointCommand | null;
11
13
  protected filter: (path: string) => boolean;
12
14
  constructor(logger: Logger, client: UsingClient);
13
15
  reload(resolve: string | Command): Promise<void>;
@@ -17,8 +19,8 @@ export declare class CommandHandler extends BaseHandler {
17
19
  shouldUpload(file: string, guildId?: string): Promise<boolean>;
18
20
  set(commands: SeteableCommand[]): void;
19
21
  load(commandsDir: string, client: UsingClient): Promise<(Command | ContextMenuCommand)[]>;
20
- parseLocales(command: Command | SubCommand | ContextMenuCommand): Command | ContextMenuCommand | SubCommand;
21
- parseGlobalLocales(command: Command | SubCommand | ContextMenuCommand): void;
22
+ parseLocales(command: InstanceType<HandleableCommand>): Command | ContextMenuCommand | EntryPointCommand | SubCommand;
23
+ parseGlobalLocales(command: InstanceType<HandleableCommand>): void;
22
24
  parseCommandOptionLocales(option: MakeRequired<CommandOption, 'locales'>): void;
23
25
  parseCommandLocales(command: Command): void;
24
26
  parseContextMenuLocales(command: ContextMenuCommand): ContextMenuCommand;
@@ -29,12 +31,12 @@ export declare class CommandHandler extends BaseHandler {
29
31
  }> | false;
30
32
  stablishSubCommandDefaults(commandInstance: Command, option: SubCommand): SubCommand;
31
33
  onFile(file: FileLoaded): HandleableCommand[] | undefined;
32
- onCommand(file: HandleableCommand): Command | SubCommand | ContextMenuCommand | false;
34
+ onCommand(file: HandleableCommand): InstanceType<HandleableCommand> | false;
33
35
  onSubCommand(file: HandleableSubCommand): SubCommand | false;
34
36
  }
35
37
  export type FileLoaded<T = null> = {
36
38
  default?: NulleableCoalising<T, HandleableCommand>;
37
39
  } & Record<string, NulleableCoalising<T, HandleableCommand>>;
38
- export type HandleableCommand = new () => Command | SubCommand | ContextMenuCommand;
40
+ export type HandleableCommand = new () => Command | SubCommand | ContextMenuCommand | EntryPointCommand;
39
41
  export type SeteableCommand = new () => Extract<InstanceType<HandleableCommand>, SubCommand>;
40
42
  export type HandleableSubCommand = new () => SubCommand;
@@ -11,6 +11,7 @@ class CommandHandler extends common_1.BaseHandler {
11
11
  logger;
12
12
  client;
13
13
  values = [];
14
+ entryPoint = null;
14
15
  filter = (path) => path.endsWith('.js') || (!path.endsWith('.d.ts') && path.endsWith('.ts'));
15
16
  constructor(logger, client) {
16
17
  super(logger);
@@ -287,8 +288,12 @@ class CommandHandler extends common_1.BaseHandler {
287
288
  }
288
289
  }
289
290
  this.stablishContextCommandDefaults(commandInstance);
290
- this.values.push(commandInstance);
291
291
  this.parseLocales(commandInstance);
292
+ if ('handler' in commandInstance && commandInstance.handler) {
293
+ this.entryPoint = commandInstance;
294
+ }
295
+ else
296
+ this.values.push(commandInstance);
292
297
  }
293
298
  }
294
299
  return this.values;
@@ -4,5 +4,7 @@ export * from './applications/chatcontext';
4
4
  export * from './applications/menu';
5
5
  export * from './applications/menucontext';
6
6
  export * from './applications/options';
7
+ export * from './applications/entryPoint';
8
+ export * from './applications/entrycontext';
7
9
  export * from './decorators';
8
10
  export * from './optionresolver';
@@ -21,5 +21,7 @@ __exportStar(require("./applications/chatcontext"), exports);
21
21
  __exportStar(require("./applications/menu"), exports);
22
22
  __exportStar(require("./applications/menucontext"), exports);
23
23
  __exportStar(require("./applications/options"), exports);
24
+ __exportStar(require("./applications/entryPoint"), exports);
25
+ __exportStar(require("./applications/entrycontext"), exports);
24
26
  __exportStar(require("./decorators"), exports);
25
27
  __exportStar(require("./optionresolver"), exports);
@@ -43,7 +43,7 @@ class OptionResolver {
43
43
  return this.hoistedOptions.find(option => option.focused)?.value;
44
44
  }
45
45
  getAutocomplete() {
46
- return (this.getCommand()?.options).find(option => option.name === this.hoistedOptions.find(x => x.focused)?.name);
46
+ return this.getCommand()?.options?.find(option => option.name === this.hoistedOptions.find(x => x.focused)?.name);
47
47
  }
48
48
  getParent() {
49
49
  return this.parent?.name;
@@ -1,7 +1,7 @@
1
1
  import type { GatewayDispatchPayload, GatewaySendPayload } from '../../types';
2
2
  import type { ShardManager, ShardManagerOptions } from '../../websocket';
3
3
  import type { MakePartial } from '../types/util';
4
- export interface WatcherOptions extends MakePartial<Omit<ShardManager['options'], 'handlePayload' | 'info' | 'token' | 'intents'>, 'compress' | 'presence' | 'properties' | 'shardEnd' | 'shardStart' | 'spawnShardDelay' | 'totalShards' | 'url' | 'version'> {
4
+ export interface WatcherOptions extends MakePartial<Omit<ShardManager['options'], 'handlePayload' | 'info' | 'token' | 'intents'>, 'compress' | 'presence' | 'properties' | 'shardEnd' | 'shardStart' | 'spawnShardDelay' | 'totalShards' | 'url' | 'version' | 'resharding' | 'debug'> {
5
5
  filePath: string;
6
6
  transpileCommand: string;
7
7
  srcPath: string;
@@ -1,6 +1,13 @@
1
1
  import { type EmojiResolvable, type TypeArray, type ColorResolvable, type Logger, type ObjectToLower, type ObjectToSnake } from '..';
2
2
  import { type APIPartialEmoji } from '../../types';
3
- import type { Cache } from '../..';
3
+ import type { Cache } from '../../cache';
4
+ /**
5
+ * Calculates the shard ID for a guild based on its ID.
6
+ * @param guildId The ID of the guild.
7
+ * @param shards The number of shards to calculate the ID for.
8
+ * @returns The shard ID.
9
+ */
10
+ export declare function calculateShardId(guildId: string, shards?: number): number;
4
11
  /**
5
12
  * Resolves the color to a numeric representation.
6
13
  * @param color The color to resolve.
@@ -33,9 +40,9 @@ export declare function MergeOptions<T>(defaults: any, ...options: any[]): T;
33
40
  * @param func The predicate function used to test elements of the array.
34
41
  * @returns An object containing two arrays: one with elements that passed the test and one with elements that did not.
35
42
  */
36
- export declare function filterSplit<Element, Predicate extends (value: Element) => boolean>(arr: Element[], func: Predicate): {
43
+ export declare function filterSplit<Element, Never = Element>(arr: (Element | Never)[], func: (value: Element | Never) => boolean): {
37
44
  expect: Element[];
38
- never: Element[];
45
+ never: Never[];
39
46
  };
40
47
  /**
41
48
  * Represents a base handler class.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ReplaceRegex = exports.BaseHandler = void 0;
4
+ exports.calculateShardId = calculateShardId;
4
5
  exports.resolveColor = resolveColor;
5
6
  exports.delay = delay;
6
7
  exports.isObject = isObject;
@@ -21,6 +22,15 @@ const node_fs_1 = require("node:fs");
21
22
  const node_path_1 = require("node:path");
22
23
  const __1 = require("..");
23
24
  const types_1 = require("../../types");
25
+ /**
26
+ * Calculates the shard ID for a guild based on its ID.
27
+ * @param guildId The ID of the guild.
28
+ * @param shards The number of shards to calculate the ID for.
29
+ * @returns The shard ID.
30
+ */
31
+ function calculateShardId(guildId, shards) {
32
+ return Number((BigInt(guildId) >> 22n) % BigInt(shards ?? 1));
33
+ }
24
34
  /**
25
35
  * Resolves the color to a numeric representation.
26
36
  * @param color The color to resolve.
@@ -2,7 +2,7 @@ import { type ReplyInteractionBody } from '../..';
2
2
  import type { InteractionMessageUpdateBodyRequest, MessageWebhookCreateBodyRequest } from '../types/write';
3
3
  import { BaseShorter } from './base';
4
4
  export declare class InteractionShorter extends BaseShorter {
5
- reply(id: string, token: string, body: ReplyInteractionBody): Promise<never>;
5
+ reply(id: string, token: string, body: ReplyInteractionBody): Promise<import("../../types").RESTPostAPIInteractionCallbackResult>;
6
6
  fetchResponse(token: string, messageId: string): Promise<import("../..").WebhookMessage | undefined>;
7
7
  fetchOriginal(token: string): Promise<import("../..").WebhookMessage | undefined>;
8
8
  editMessage(token: string, messageId: string, body: InteractionMessageUpdateBodyRequest): Promise<import("../..").WebhookMessage>;
@@ -7,7 +7,7 @@ export type MakePartial<T, K extends keyof T> = Omit<T, K> & {
7
7
  [P in K]?: T[P];
8
8
  };
9
9
  export type DeepPartial<T> = {
10
- [K in keyof T]?: T[K] extends Record<any, any> ? DeepPartial<T[K]> : T[K] extends (infer I)[] ? DeepPartial<I>[] : T[K];
10
+ [K in keyof T]?: T[K] extends Record<any, any> ? DeepPartial<T[K]> : T[K] extends (infer I)[] ? DeepPartial<I>[] : Partial<T[K]>;
11
11
  };
12
12
  export type OmitInsert<T, K extends keyof T, I> = I extends [] ? Omit<T, K> & I[number] : Omit<T, K> & I;
13
13
  export type IntentStrings = (keyof typeof GatewayIntentBits)[];
@@ -13,8 +13,8 @@ export interface SendResolverProps extends ResolverProps {
13
13
  export type MessageCreateBodyRequest = OmitInsert<RESTPostAPIChannelMessageJSONBody, 'components' | 'embeds' | 'poll', SendResolverProps>;
14
14
  export type MessageUpdateBodyRequest = OmitInsert<RESTPatchAPIChannelMessageJSONBody, 'components' | 'embeds', ResolverProps>;
15
15
  export type MessageWebhookCreateBodyRequest = OmitInsert<RESTPostAPIWebhookWithTokenJSONBody, 'components' | 'embeds' | 'poll', SendResolverProps>;
16
- export type MessageWebhookUpdateBodyRequest = OmitInsert<RESTPatchAPIWebhookWithTokenMessageJSONBody, 'components' | 'embeds', ResolverProps>;
17
- export type InteractionMessageUpdateBodyRequest = OmitInsert<RESTPatchAPIWebhookWithTokenMessageJSONBody, 'components' | 'embeds', ResolverProps>;
16
+ export type MessageWebhookUpdateBodyRequest = OmitInsert<RESTPatchAPIWebhookWithTokenMessageJSONBody, 'components' | 'embeds' | 'poll', ResolverProps>;
17
+ export type InteractionMessageUpdateBodyRequest = OmitInsert<RESTPatchAPIWebhookWithTokenMessageJSONBody, 'components' | 'embeds' | 'poll', SendResolverProps>;
18
18
  export type ComponentInteractionMessageUpdate = OmitInsert<APIInteractionResponseCallbackData, 'components' | 'embeds', ResolverProps>;
19
19
  export type InteractionCreateBodyRequest = OmitInsert<APIInteractionResponseChannelMessageWithSource['data'], 'components' | 'embeds' | 'poll', SendResolverProps>;
20
20
  export type ModalCreateBodyRequest = APIModalInteractionResponse['data'] | Modal;
package/lib/deps/mixer.js CHANGED
@@ -26,6 +26,7 @@ function getDescriptors(c) {
26
26
  * @returns The mixed class.
27
27
  */
28
28
  function Mixin(...args) {
29
+ const ignoreOverwriteToString = Object.keys(Object.getOwnPropertyDescriptors(args[0].prototype)).includes('toString');
29
30
  function MixedClass(...constructorArgs) {
30
31
  for (const i of args) {
31
32
  const descriptors = getDescriptors(i);
@@ -35,10 +36,14 @@ function Mixin(...args) {
35
36
  for (const descriptorK in j) {
36
37
  if (descriptorK === 'constructor')
37
38
  continue;
38
- if (descriptorK in MixedClass.prototype)
39
+ if (descriptorK in MixedClass.prototype && descriptorK !== 'toString')
39
40
  continue;
40
41
  const descriptor = j[descriptorK];
41
42
  if (descriptor.value) {
43
+ if (descriptorK === 'toString' && ignoreOverwriteToString) {
44
+ MixedClass.prototype[descriptorK] = args[0].prototype.toString;
45
+ continue;
46
+ }
42
47
  MixedClass.prototype[descriptorK] = descriptor.value;
43
48
  continue;
44
49
  }
@@ -111,7 +111,7 @@ class EventHandler extends common_1.BaseHandler {
111
111
  const Event = this.values[name];
112
112
  if (!Event) {
113
113
  return runCache
114
- ? this.client.cache.onPacket?.({
114
+ ? this.client.cache.onPacket({
115
115
  t: name,
116
116
  d: packet,
117
117
  })
@@ -120,7 +120,7 @@ class EventHandler extends common_1.BaseHandler {
120
120
  try {
121
121
  if (Event.data.once && Event.fired) {
122
122
  return runCache
123
- ? this.client.cache.onPacket?.({
123
+ ? this.client.cache.onPacket({
124
124
  t: name,
125
125
  d: packet,
126
126
  })
@@ -129,7 +129,7 @@ class EventHandler extends common_1.BaseHandler {
129
129
  Event.fired = true;
130
130
  const hook = await RawEvents[name]?.(client, packet);
131
131
  if (runCache)
132
- await this.client.cache.onPacket?.({
132
+ await this.client.cache.onPacket({
133
133
  t: name,
134
134
  d: packet,
135
135
  });
@@ -2,3 +2,4 @@ import type { ClientUserStructure } from '../../client/transformers';
2
2
  import type { UsingClient } from '../../commands';
3
3
  export declare const BOT_READY: (_self: UsingClient, me: ClientUserStructure) => import("../..").ClientUser;
4
4
  export declare const WORKER_READY: (_self: UsingClient, me: ClientUserStructure) => import("../..").ClientUser;
5
+ export declare const WORKER_SHARDS_CONNECTED: (_self: UsingClient, me: ClientUserStructure) => import("../..").ClientUser;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WORKER_READY = exports.BOT_READY = void 0;
3
+ exports.WORKER_SHARDS_CONNECTED = exports.WORKER_READY = exports.BOT_READY = void 0;
4
4
  const BOT_READY = (_self, me) => {
5
5
  return me;
6
6
  };
@@ -9,3 +9,7 @@ const WORKER_READY = (_self, me) => {
9
9
  return me;
10
10
  };
11
11
  exports.WORKER_READY = WORKER_READY;
12
+ const WORKER_SHARDS_CONNECTED = (_self, me) => {
13
+ return me;
14
+ };
15
+ exports.WORKER_SHARDS_CONNECTED = WORKER_SHARDS_CONNECTED;