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
@@ -6,6 +6,9 @@ class BaseContext {
6
6
  constructor(client) {
7
7
  this.client = client;
8
8
  }
9
+ /**
10
+ * Gets the proxy object.
11
+ */
9
12
  get proxy() {
10
13
  return this.client.proxy;
11
14
  }
@@ -24,5 +27,26 @@ class BaseContext {
24
27
  isComponent() {
25
28
  return false;
26
29
  }
30
+ isModal() {
31
+ return false;
32
+ }
33
+ isButton() {
34
+ return false;
35
+ }
36
+ isChannelSelectMenu() {
37
+ return false;
38
+ }
39
+ isRoleSelectMenu() {
40
+ return false;
41
+ }
42
+ isMentionableSelectMenu() {
43
+ return false;
44
+ }
45
+ isUserSelectMenu() {
46
+ return false;
47
+ }
48
+ isStringSelectMenu() {
49
+ return false;
50
+ }
27
51
  }
28
52
  exports.BaseContext = BaseContext;
@@ -1,18 +1,9 @@
1
- import { ApplicationCommandType, type LocaleString } from 'discord-api-types/v10';
1
+ import { ApplicationCommandType, ApplicationIntegrationType, InteractionContextType, type LocaleString } from 'discord-api-types/v10';
2
2
  import type { FlatObjectKeys, PermissionStrings } from '../common';
3
3
  import type { CommandOption, OptionsRecord, SubCommand } from './applications/chat';
4
- import type { DefaultLocale, IgnoreCommand, MiddlewareContext } from './applications/shared';
4
+ import type { DefaultLocale, ExtraProps, IgnoreCommand, MiddlewareContext } from './applications/shared';
5
5
  export interface RegisteredMiddlewares {
6
6
  }
7
- export declare enum IntegrationTypes {
8
- GUILD_INSTALL = 0,
9
- USER_INSTALL = 1
10
- }
11
- export declare enum InteractionContextTypes {
12
- GUILD = 0,
13
- BOT_DM = 1,
14
- PRIVATE_CHANNEL = 2
15
- }
16
7
  type DeclareOptions = {
17
8
  name: string;
18
9
  description: string;
@@ -20,10 +11,11 @@ type DeclareOptions = {
20
11
  defaultMemberPermissions?: PermissionStrings | bigint;
21
12
  guildId?: string[];
22
13
  nsfw?: boolean;
23
- integrationTypes?: (keyof typeof IntegrationTypes)[];
24
- contexts?: (keyof typeof InteractionContextTypes)[];
14
+ integrationTypes?: (keyof typeof ApplicationIntegrationType)[];
15
+ contexts?: (keyof typeof InteractionContextType)[];
25
16
  ignore?: IgnoreCommand;
26
17
  aliases?: string[];
18
+ props?: ExtraProps;
27
19
  } | (Omit<{
28
20
  name: string;
29
21
  description: string;
@@ -31,8 +23,9 @@ type DeclareOptions = {
31
23
  defaultMemberPermissions?: PermissionStrings | bigint;
32
24
  guildId?: string[];
33
25
  nsfw?: boolean;
34
- integrationTypes?: (keyof typeof IntegrationTypes)[];
35
- contexts?: (keyof typeof InteractionContextTypes)[];
26
+ integrationTypes?: (keyof typeof ApplicationIntegrationType)[];
27
+ contexts?: (keyof typeof InteractionContextType)[];
28
+ props?: ExtraProps;
36
29
  }, 'type' | 'description'> & {
37
30
  type: ApplicationCommandType.User | ApplicationCommandType.Message;
38
31
  });
@@ -116,8 +109,9 @@ export declare function Declare(declare: DeclareOptions): <T extends new (...arg
116
109
  new (...args: any[]): {
117
110
  name: string;
118
111
  nsfw: boolean | undefined;
119
- contexts: InteractionContextTypes[] | undefined;
120
- integrationTypes: IntegrationTypes[] | undefined;
112
+ props: ExtraProps | undefined;
113
+ contexts: (string | InteractionContextType)[];
114
+ integrationTypes: ApplicationIntegrationType[];
121
115
  defaultMemberPermissions: bigint | undefined;
122
116
  botPermissions: bigint | undefined;
123
117
  description: string;
@@ -1,18 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Declare = exports.Middlewares = exports.AutoLoad = exports.Options = exports.Group = exports.Groups = exports.GroupsT = exports.LocalesT = exports.Locales = exports.InteractionContextTypes = exports.IntegrationTypes = void 0;
3
+ exports.Declare = exports.Middlewares = exports.AutoLoad = exports.Options = exports.Group = exports.Groups = exports.GroupsT = exports.LocalesT = exports.Locales = void 0;
4
4
  const v10_1 = require("discord-api-types/v10");
5
- var IntegrationTypes;
6
- (function (IntegrationTypes) {
7
- IntegrationTypes[IntegrationTypes["GUILD_INSTALL"] = 0] = "GUILD_INSTALL";
8
- IntegrationTypes[IntegrationTypes["USER_INSTALL"] = 1] = "USER_INSTALL";
9
- })(IntegrationTypes || (exports.IntegrationTypes = IntegrationTypes = {}));
10
- var InteractionContextTypes;
11
- (function (InteractionContextTypes) {
12
- InteractionContextTypes[InteractionContextTypes["GUILD"] = 0] = "GUILD";
13
- InteractionContextTypes[InteractionContextTypes["BOT_DM"] = 1] = "BOT_DM";
14
- InteractionContextTypes[InteractionContextTypes["PRIVATE_CHANNEL"] = 2] = "PRIVATE_CHANNEL";
15
- })(InteractionContextTypes || (exports.InteractionContextTypes = InteractionContextTypes = {}));
16
5
  function Locales({ name: names, description: descriptions, }) {
17
6
  return (target) => class extends target {
18
7
  name_localizations = names ? Object.fromEntries(names) : undefined;
@@ -91,8 +80,12 @@ function Declare(declare) {
91
80
  return (target) => class extends target {
92
81
  name = declare.name;
93
82
  nsfw = declare.nsfw;
94
- contexts = declare.contexts?.map(i => InteractionContextTypes[i]);
95
- integrationTypes = declare.integrationTypes?.map(i => IntegrationTypes[i]);
83
+ props = declare.props;
84
+ contexts = declare.contexts?.map(i => v10_1.InteractionContextType[i]) ??
85
+ Object.values(v10_1.InteractionContextType).filter(x => typeof x === 'number');
86
+ integrationTypes = declare.integrationTypes?.map(i => v10_1.ApplicationIntegrationType[i]) ?? [
87
+ v10_1.ApplicationIntegrationType.GuildInstall,
88
+ ];
96
89
  defaultMemberPermissions = Array.isArray(declare.defaultMemberPermissions)
97
90
  ? declare.defaultMemberPermissions?.reduce((acc, prev) => acc | v10_1.PermissionFlagsBits[prev], BigInt(0))
98
91
  : declare.defaultMemberPermissions;
@@ -1,3 +1,4 @@
1
+ import { type APIApplicationCommandOption } from 'discord-api-types/v10';
1
2
  import type { Logger } from '../common';
2
3
  import { BaseHandler } from '../common';
3
4
  import { Command, SubCommand } from './applications/chat';
@@ -11,7 +12,11 @@ export declare class CommandHandler extends BaseHandler {
11
12
  constructor(logger: Logger, client: UsingClient);
12
13
  reload(resolve: string | Command): Promise<void>;
13
14
  reloadAll(stopIfFail?: boolean): Promise<void>;
14
- load(commandsDir: string, client: UsingClient): Promise<(Command | ContextMenuCommand)[]>;
15
+ protected shouldUploadOption(option: APIApplicationCommandOption, cached: APIApplicationCommandOption): boolean | undefined;
16
+ shouldUpload(file: string): Promise<boolean>;
17
+ load(commandsDir: string, client: UsingClient, instances?: {
18
+ new (): Command | ContextMenuCommand;
19
+ }[]): Promise<(Command | ContextMenuCommand)[]>;
15
20
  private __parseCommandLocales;
16
21
  setHandlers({ onCommand, onSubCommand, }: {
17
22
  onCommand?: CommandHandler['onCommand'];
@@ -6,6 +6,7 @@ const node_path_1 = require("node:path");
6
6
  const common_1 = require("../common");
7
7
  const chat_1 = require("./applications/chat");
8
8
  const menu_1 = require("./applications/menu");
9
+ const node_fs_1 = require("node:fs");
9
10
  class CommandHandler extends common_1.BaseHandler {
10
11
  logger;
11
12
  client;
@@ -34,8 +35,129 @@ class CommandHandler extends common_1.BaseHandler {
34
35
  }
35
36
  }
36
37
  }
37
- async load(commandsDir, client) {
38
- const result = (await this.loadFilesK(await this.getFiles(commandsDir))).filter(x => x.file);
38
+ shouldUploadOption(option, cached) {
39
+ if (option.description !== cached.description)
40
+ return true;
41
+ if (option.type !== cached.type)
42
+ return true;
43
+ if (option.required !== cached.required)
44
+ return true;
45
+ if (option.name !== cached.name)
46
+ return true;
47
+ //TODO: locales
48
+ switch (option.type) {
49
+ case v10_1.ApplicationCommandOptionType.String:
50
+ return (option.min_length !== cached.min_length ||
51
+ option.max_length !== cached.max_length);
52
+ case v10_1.ApplicationCommandOptionType.Channel:
53
+ {
54
+ if (option.channel_types?.length !== cached.channel_types?.length)
55
+ return true;
56
+ if ('channel_types' in option && 'channel_types' in cached) {
57
+ if (!(option.channel_types && cached.channel_types))
58
+ return true;
59
+ return option.channel_types.some(ct => !cached.channel_types.includes(ct));
60
+ }
61
+ }
62
+ return;
63
+ case v10_1.ApplicationCommandOptionType.Subcommand:
64
+ case v10_1.ApplicationCommandOptionType.SubcommandGroup:
65
+ if (option.options?.length !==
66
+ cached.options?.length) {
67
+ return true;
68
+ }
69
+ if (option.options &&
70
+ cached.options)
71
+ for (const i of option.options) {
72
+ const cachedOption = cached.options.find(x => x.name === i.name);
73
+ if (!cachedOption)
74
+ return true;
75
+ if (this.shouldUploadOption(i, cachedOption))
76
+ return true;
77
+ }
78
+ break;
79
+ case v10_1.ApplicationCommandOptionType.Integer:
80
+ case v10_1.ApplicationCommandOptionType.Number:
81
+ return (option.min_value !== cached.min_value ||
82
+ option.max_value !== cached.max_value);
83
+ case v10_1.ApplicationCommandOptionType.Attachment:
84
+ case v10_1.ApplicationCommandOptionType.Boolean:
85
+ case v10_1.ApplicationCommandOptionType.Mentionable:
86
+ case v10_1.ApplicationCommandOptionType.Role:
87
+ case v10_1.ApplicationCommandOptionType.User:
88
+ break;
89
+ }
90
+ return false;
91
+ }
92
+ async shouldUpload(file) {
93
+ if (!(await node_fs_1.promises.access(file).then(() => true, () => false))) {
94
+ await node_fs_1.promises.writeFile(file, JSON.stringify(this.values.map(x => x.toJSON())));
95
+ return true;
96
+ }
97
+ const cachedCommands = JSON.parse((await node_fs_1.promises.readFile(file)).toString());
98
+ if (cachedCommands.length !== this.values.length)
99
+ return true;
100
+ for (const command of this.values.map(x => x.toJSON())) {
101
+ const cached = cachedCommands.find(x => {
102
+ if (x.name !== command.name)
103
+ return false;
104
+ if (command.guild_id)
105
+ return command.guild_id.every(id => x.guild_id?.includes(id));
106
+ return true;
107
+ });
108
+ if (!cached)
109
+ return true;
110
+ if (cached.description !== command.description)
111
+ return true;
112
+ if (cached.default_member_permissions !== command.default_member_permissions)
113
+ return true;
114
+ if (cached.type !== command.type)
115
+ return true;
116
+ if (cached.nsfw !== command.nsfw)
117
+ return true;
118
+ if (!!('options' in cached) !== !!('options' in command))
119
+ return true;
120
+ if (!!cached.contexts !== !!command.contexts)
121
+ return true;
122
+ if (!!cached.integration_types !== !!command.integration_types)
123
+ return true;
124
+ //TODO: locales
125
+ if ('contexts' in command && 'contexts' in cached) {
126
+ if (command.contexts.length !== cached.contexts.length)
127
+ return true;
128
+ if (command.contexts && cached.contexts) {
129
+ if (command.contexts.some(ctx => !cached.contexts.includes(ctx)))
130
+ return true;
131
+ }
132
+ }
133
+ if ('integration_types' in command && 'integration_types' in cached) {
134
+ if (command.integration_types.length !== cached.integration_types.length)
135
+ return true;
136
+ if (command.integration_types && cached.integration_types) {
137
+ if (command.integration_types.some(ctx => !cached.integration_types.includes(ctx)))
138
+ return true;
139
+ }
140
+ }
141
+ if ('options' in command && 'options' in cached) {
142
+ if (command.options.length !== cached.options.length)
143
+ return true;
144
+ for (const option of command.options) {
145
+ const cachedOption = cached.options.find(x => x.name === option.name);
146
+ if (!cachedOption)
147
+ return true;
148
+ if (this.shouldUploadOption(option, cachedOption))
149
+ return true;
150
+ }
151
+ }
152
+ }
153
+ return false;
154
+ }
155
+ async load(commandsDir, client, instances) {
156
+ const result = instances?.map(x => {
157
+ const i = new x();
158
+ return { name: i.name, file: x, path: i.__filePath ?? '*' };
159
+ }) ??
160
+ (await this.loadFilesK(await this.getFiles(commandsDir))).filter(x => x.file);
39
161
  this.values = [];
40
162
  for (const command of result) {
41
163
  let commandInstance;
@@ -45,7 +167,7 @@ class CommandHandler extends common_1.BaseHandler {
45
167
  continue;
46
168
  }
47
169
  catch (e) {
48
- if (e instanceof Error && e.message === 'command.file is not a constructor') {
170
+ if (e instanceof Error && e.message.includes('is not a constructor')) {
49
171
  this.logger.warn(`${command.path
50
172
  .split(process.cwd())
51
173
  .slice(1)
@@ -58,20 +180,23 @@ class CommandHandler extends common_1.BaseHandler {
58
180
  if (commandInstance instanceof menu_1.ContextMenuCommand) {
59
181
  this.values.push(commandInstance);
60
182
  commandInstance.__filePath = command.path;
183
+ this.__parseCommandLocales(commandInstance);
184
+ commandInstance.props ??= client.options.commands?.defaults?.props ?? {};
61
185
  continue;
62
186
  }
63
187
  if (!(commandInstance instanceof chat_1.Command)) {
64
188
  continue;
65
189
  }
66
- commandInstance.onAfterRun ??= client.options?.commands?.defaults?.onAfterRun;
67
- commandInstance.onBotPermissionsFail ??= client.options?.commands?.defaults?.onBotPermissionsFail;
68
- commandInstance.onInternalError ??= client.options?.commands?.defaults?.onInternalError;
69
- commandInstance.onMiddlewaresError ??= client.options?.commands?.defaults?.onMiddlewaresError;
70
- commandInstance.onOptionsError ??= client.options?.commands?.defaults?.onOptionsError;
71
- commandInstance.onPermissionsFail ??= client.options?.commands?.defaults?.onPermissionsFail;
72
- commandInstance.onRunError ??= client.options?.commands?.defaults?.onRunError;
190
+ commandInstance.onAfterRun ??= client.options.commands?.defaults?.onAfterRun;
191
+ commandInstance.onBotPermissionsFail ??= client.options.commands?.defaults?.onBotPermissionsFail;
192
+ commandInstance.onInternalError ??= client.options.commands?.defaults?.onInternalError;
193
+ commandInstance.onMiddlewaresError ??= client.options.commands?.defaults?.onMiddlewaresError;
194
+ commandInstance.onOptionsError ??= client.options.commands?.defaults?.onOptionsError;
195
+ commandInstance.onPermissionsFail ??= client.options.commands?.defaults?.onPermissionsFail;
196
+ commandInstance.onRunError ??= client.options.commands?.defaults?.onRunError;
73
197
  commandInstance.__filePath = command.path;
74
198
  commandInstance.options ??= [];
199
+ commandInstance.props ??= client.options.commands?.defaults?.props ?? {};
75
200
  if (commandInstance.__autoload) {
76
201
  //@AutoLoad
77
202
  const options = await this.getFiles((0, node_path_1.dirname)(command.path));
@@ -97,86 +222,93 @@ class CommandHandler extends common_1.BaseHandler {
97
222
  option.onMiddlewaresError =
98
223
  option.onMiddlewaresError?.bind(option) ??
99
224
  commandInstance.onMiddlewaresError?.bind(commandInstance) ??
100
- this.client.options?.commands?.defaults?.onMiddlewaresError;
225
+ this.client.options.commands?.defaults?.onMiddlewaresError;
101
226
  option.onRunError =
102
227
  option.onRunError?.bind(option) ??
103
228
  commandInstance.onRunError?.bind(commandInstance) ??
104
- this.client.options?.commands?.defaults?.onRunError;
229
+ this.client.options.commands?.defaults?.onRunError;
105
230
  option.onOptionsError =
106
231
  option.onOptionsError?.bind(option) ??
107
232
  commandInstance.onOptionsError?.bind(commandInstance) ??
108
- this.client.options?.commands?.defaults?.onOptionsError;
233
+ this.client.options.commands?.defaults?.onOptionsError;
109
234
  option.onInternalError =
110
235
  option.onInternalError?.bind(option) ??
111
236
  commandInstance.onInternalError?.bind(commandInstance) ??
112
- this.client.options?.commands?.defaults?.onInternalError;
237
+ this.client.options.commands?.defaults?.onInternalError;
113
238
  option.onAfterRun =
114
239
  option.onAfterRun?.bind(option) ??
115
240
  commandInstance.onAfterRun?.bind(commandInstance) ??
116
- this.client.options?.commands?.defaults?.onAfterRun;
241
+ this.client.options.commands?.defaults?.onAfterRun;
117
242
  option.onBotPermissionsFail =
118
243
  option.onBotPermissionsFail?.bind(option) ??
119
244
  commandInstance.onBotPermissionsFail?.bind(commandInstance) ??
120
- this.client.options?.commands?.defaults?.onBotPermissionsFail;
245
+ this.client.options.commands?.defaults?.onBotPermissionsFail;
121
246
  option.onPermissionsFail =
122
247
  option.onPermissionsFail?.bind(option) ??
123
248
  commandInstance.onPermissionsFail?.bind(commandInstance) ??
124
- this.client.options?.commands?.defaults?.onPermissionsFail;
249
+ this.client.options.commands?.defaults?.onPermissionsFail;
250
+ option.botPermissions ??= commandInstance.botPermissions;
251
+ option.defaultMemberPermissions ??= commandInstance.defaultMemberPermissions;
252
+ option.contexts ??= commandInstance.contexts;
253
+ option.integrationTypes ??= commandInstance.integrationTypes;
254
+ option.props ??= commandInstance.props;
125
255
  }
126
256
  }
127
257
  this.values.push(commandInstance);
128
- this.__parseCommandLocales(commandInstance, client);
258
+ this.__parseCommandLocales(commandInstance);
129
259
  for (const i of commandInstance.options ?? []) {
130
260
  if (i instanceof chat_1.SubCommand) {
131
- this.__parseCommandLocales(i, client);
261
+ this.__parseCommandLocales(i);
132
262
  }
133
263
  }
134
264
  }
135
265
  return this.values;
136
266
  }
137
- __parseCommandLocales(command, client) {
267
+ __parseCommandLocales(command) {
138
268
  if (command.__t) {
139
269
  command.name_localizations = {};
140
270
  command.description_localizations = {};
141
- for (const locale of Object.keys(client.langs.values)) {
271
+ for (const locale of Object.keys(this.client.langs.values)) {
142
272
  const locales = this.client.langs.aliases.find(x => x[0] === locale)?.[1] ?? [];
143
273
  if (Object.values(v10_1.Locale).includes(locale))
144
274
  locales.push(locale);
145
275
  if (command.__t.name) {
146
276
  for (const i of locales) {
147
- const valueName = client.langs.getKey(locale, command.__t.name);
277
+ const valueName = this.client.langs.getKey(locale, command.__t.name);
148
278
  if (valueName)
149
279
  command.name_localizations[i] = valueName;
150
280
  }
151
281
  }
152
282
  if (command.__t.description) {
153
283
  for (const i of locales) {
154
- const valueKey = client.langs.getKey(locale, command.__t.description);
284
+ const valueKey = this.client.langs.getKey(locale, command.__t.description);
155
285
  if (valueKey)
156
286
  command.description_localizations[i] = valueKey;
157
287
  }
158
288
  }
159
289
  }
160
290
  }
291
+ if (command instanceof menu_1.ContextMenuCommand)
292
+ return;
161
293
  for (const options of command.options ?? []) {
162
294
  if (options instanceof chat_1.SubCommand || !options.locales)
163
295
  continue;
164
296
  options.name_localizations = {};
165
297
  options.description_localizations = {};
166
- for (const locale of Object.keys(client.langs.values)) {
298
+ for (const locale of Object.keys(this.client.langs.values)) {
167
299
  const locales = this.client.langs.aliases.find(x => x[0] === locale)?.[1] ?? [];
168
300
  if (Object.values(v10_1.Locale).includes(locale))
169
301
  locales.push(locale);
170
302
  if (options.locales.name) {
171
303
  for (const i of locales) {
172
- const valueName = client.langs.getKey(locale, options.locales.name);
304
+ const valueName = this.client.langs.getKey(locale, options.locales.name);
173
305
  if (valueName)
174
306
  options.name_localizations[i] = valueName;
175
307
  }
176
308
  }
177
309
  if (options.locales.description) {
178
310
  for (const i of locales) {
179
- const valueKey = client.langs.getKey(locale, options.locales.description);
311
+ const valueKey = this.client.langs.getKey(locale, options.locales.description);
180
312
  if (valueKey)
181
313
  options.description_localizations[i] = valueKey;
182
314
  }
@@ -185,7 +317,7 @@ class CommandHandler extends common_1.BaseHandler {
185
317
  }
186
318
  if (command instanceof chat_1.Command && command.__tGroups) {
187
319
  command.groups = {};
188
- for (const locale of Object.keys(client.langs.values)) {
320
+ for (const locale of Object.keys(this.client.langs.values)) {
189
321
  const locales = this.client.langs.aliases.find(x => x[0] === locale)?.[1] ?? [];
190
322
  if (Object.values(v10_1.Locale).includes(locale))
191
323
  locales.push(locale);
@@ -197,7 +329,7 @@ class CommandHandler extends common_1.BaseHandler {
197
329
  };
198
330
  if (command.__tGroups[group].name) {
199
331
  for (const i of locales) {
200
- const valueName = client.langs.getKey(locale, command.__tGroups[group].name);
332
+ const valueName = this.client.langs.getKey(locale, command.__tGroups[group].name);
201
333
  if (valueName) {
202
334
  command.groups[group].name.push([i, valueName]);
203
335
  }
@@ -205,7 +337,7 @@ class CommandHandler extends common_1.BaseHandler {
205
337
  }
206
338
  if (command.__tGroups[group].description) {
207
339
  for (const i of locales) {
208
- const valueKey = client.langs.getKey(locale, command.__tGroups[group].description);
340
+ const valueKey = this.client.langs.getKey(locale, command.__tGroups[group].description);
209
341
  if (valueKey) {
210
342
  command.groups[group].description.push([i, valueKey]);
211
343
  }
@@ -1,6 +1,5 @@
1
1
  /// <reference types="node" />
2
2
  import type { GatewayDispatchPayload, GatewaySendPayload } from 'discord-api-types/v10';
3
- import { Worker } from 'node:worker_threads';
4
3
  import { ApiHandler } from '../../api';
5
4
  import { ShardManager, type ShardManagerOptions } from '../../websocket';
6
5
  import { Logger } from '../it/logger';
@@ -9,7 +8,7 @@ import type { MakeRequired } from '../types/util';
9
8
  * Represents a watcher class that extends the ShardManager.
10
9
  */
11
10
  export declare class Watcher extends ShardManager {
12
- worker?: Worker;
11
+ worker?: import('node:worker_threads').Worker;
13
12
  logger: Logger;
14
13
  rest?: ApiHandler;
15
14
  options: MakeRequired<WatcherOptions, 'intents' | 'token' | 'handlePayload' | 'info'>;
@@ -1,13 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Watcher = void 0;
4
- const chokidar_1 = require("chokidar");
5
4
  const node_child_process_1 = require("node:child_process");
6
- const node_worker_threads_1 = require("node:worker_threads");
7
5
  const api_1 = require("../../api");
8
6
  const base_1 = require("../../client/base");
9
7
  const websocket_1 = require("../../websocket");
10
8
  const logger_1 = require("../it/logger");
9
+ const utils_1 = require("../it/utils");
11
10
  /**
12
11
  * Represents a watcher class that extends the ShardManager.
13
12
  */
@@ -43,11 +42,14 @@ class Watcher extends websocket_1.ShardManager {
43
42
  * Resets the worker instance.
44
43
  */
45
44
  resetWorker() {
45
+ const worker_threads = (0, utils_1.lazyLoadPackage)('node:worker_threads');
46
+ if (!worker_threads)
47
+ throw new Error('Cannot use worker_threads');
46
48
  if (this.worker) {
47
49
  this.worker.terminate();
48
50
  }
49
51
  this.build();
50
- this.worker = new node_worker_threads_1.Worker(this.options.filePath, {
52
+ this.worker = new worker_threads.Worker(this.options.filePath, {
51
53
  argv: this.options.argv,
52
54
  workerData: {
53
55
  __USING_WATCHER__: true,
@@ -87,7 +89,10 @@ class Watcher extends websocket_1.ShardManager {
87
89
  };
88
90
  this.connectQueue.concurrency = this.options.info.session_start_limit.max_concurrency;
89
91
  await super.spawnShards();
90
- const watcher = (0, chokidar_1.watch)(this.options.srcPath).on('ready', () => {
92
+ const chokidar = (0, utils_1.lazyLoadPackage)('chokidar');
93
+ if (!chokidar?.watch)
94
+ return this.logger.warn('No chokidar installed.');
95
+ const watcher = chokidar.watch(this.options.srcPath).on('ready', () => {
91
96
  this.logger.debug(`Watching ${this.options.srcPath}`);
92
97
  watcher.on('all', event => {
93
98
  this.logger.debug(`${event} event detected, building`);
@@ -2,6 +2,7 @@ export * from './it/constants';
2
2
  export * from './it/utils';
3
3
  export * from './it/colors';
4
4
  export * from './it/logger';
5
+ export * from './it/formatter';
5
6
  export * from './shorters/channels';
6
7
  export * from './shorters/emojis';
7
8
  export * from './shorters/guilds';
@@ -16,9 +16,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./it/constants"), exports);
18
18
  __exportStar(require("./it/utils"), exports);
19
- //
20
19
  __exportStar(require("./it/colors"), exports);
21
20
  __exportStar(require("./it/logger"), exports);
21
+ __exportStar(require("./it/formatter"), exports);
22
+ //
22
23
  __exportStar(require("./shorters/channels"), exports);
23
24
  __exportStar(require("./shorters/emojis"), exports);
24
25
  __exportStar(require("./shorters/guilds"), exports);
@@ -31,6 +32,7 @@ __exportStar(require("./shorters/users"), exports);
31
32
  __exportStar(require("./shorters/threads"), exports);
32
33
  __exportStar(require("./shorters/webhook"), exports);
33
34
  __exportStar(require("./shorters/interaction"), exports);
35
+ //
34
36
  __exportStar(require("./types/options"), exports);
35
37
  __exportStar(require("./types/resolvables"), exports);
36
38
  __exportStar(require("./types/util"), exports);