seyfert 2.1.1-dev-11464165753.0 → 2.1.1-dev-11520718826.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.
- package/lib/client/base.d.ts +4 -12
- package/lib/client/base.js +15 -10
- package/lib/client/client.js +1 -1
- package/lib/client/workerclient.js +2 -2
- package/lib/commands/applications/options.d.ts +6 -1
- package/lib/commands/applications/shared.d.ts +4 -0
- package/lib/commands/handler.d.ts +3 -2
- package/lib/commands/handler.js +54 -28
- package/package.json +2 -2
package/lib/client/base.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ApiHandler } from '../api';
|
|
2
2
|
import type { Adapter } from '../cache';
|
|
3
3
|
import { Cache } from '../cache';
|
|
4
|
-
import type { Command, CommandContext, ContextMenuCommand, ExtraProps, MenuCommandContext, RegisteredMiddlewares, SubCommand, UsingClient } from '../commands';
|
|
4
|
+
import type { Command, CommandContext, ContextMenuCommand, ExtendedRC, ExtendedRCLocations, ExtraProps, MenuCommandContext, RegisteredMiddlewares, SubCommand, UsingClient } from '../commands';
|
|
5
5
|
import { type InferWithPrefix, type MiddlewareContext } from '../commands/applications/shared';
|
|
6
6
|
import { CommandHandler } from '../commands/handler';
|
|
7
7
|
import { ApplicationShorter, ChannelShorter, EmojiShorter, GuildShorter, InteractionShorter, Logger, type MakeRequired, MemberShorter, MessageShorter, ReactionShorter, RoleShorter, TemplateShorter, ThreadShorter, UsersShorter, WebhookShorter } from '../common';
|
|
@@ -68,13 +68,7 @@ export declare class BaseClient {
|
|
|
68
68
|
getRC<T extends InternalRuntimeConfigHTTP | InternalRuntimeConfig = InternalRuntimeConfigHTTP | InternalRuntimeConfig>(): Promise<{
|
|
69
69
|
debug: boolean;
|
|
70
70
|
} & Omit<T, "debug" | "locations"> & {
|
|
71
|
-
|
|
72
|
-
langs: string | undefined;
|
|
73
|
-
events: string | undefined;
|
|
74
|
-
components: string | undefined;
|
|
75
|
-
commands: string | undefined;
|
|
76
|
-
base: string;
|
|
77
|
-
output: string;
|
|
71
|
+
locations: MakeRequired<Partial<Record<"components" | "events" | "base" | "output" | "commands" | "langs" | "templates", string>>, "base" | "output">;
|
|
78
72
|
}>;
|
|
79
73
|
}
|
|
80
74
|
export interface BaseClientOptions {
|
|
@@ -127,7 +121,7 @@ export interface StartOptions {
|
|
|
127
121
|
};
|
|
128
122
|
token: string;
|
|
129
123
|
}
|
|
130
|
-
interface RC extends
|
|
124
|
+
interface RC extends ExtendedRC {
|
|
131
125
|
debug?: boolean;
|
|
132
126
|
locations: {
|
|
133
127
|
base: string;
|
|
@@ -137,9 +131,7 @@ interface RC extends Variables {
|
|
|
137
131
|
templates?: string;
|
|
138
132
|
events?: string;
|
|
139
133
|
components?: string;
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
export interface Variables {
|
|
134
|
+
} & ExtendedRCLocations;
|
|
143
135
|
token: string;
|
|
144
136
|
intents?: number;
|
|
145
137
|
applicationId?: string;
|
package/lib/client/base.js
CHANGED
|
@@ -260,21 +260,21 @@ class BaseClient {
|
|
|
260
260
|
await this.syncCachePath(cachePath);
|
|
261
261
|
}
|
|
262
262
|
async loadCommands(dir) {
|
|
263
|
-
dir ??= await this.getRC().then(x => x.commands);
|
|
263
|
+
dir ??= await this.getRC().then(x => x.locations.commands);
|
|
264
264
|
if (dir && this.commands) {
|
|
265
265
|
await this.commands.load(dir, this);
|
|
266
266
|
this.logger.info('CommandHandler loaded');
|
|
267
267
|
}
|
|
268
268
|
}
|
|
269
269
|
async loadComponents(dir) {
|
|
270
|
-
dir ??= await this.getRC().then(x => x.components);
|
|
270
|
+
dir ??= await this.getRC().then(x => x.locations.components);
|
|
271
271
|
if (dir && this.components) {
|
|
272
272
|
await this.components.load(dir);
|
|
273
273
|
this.logger.info('ComponentHandler loaded');
|
|
274
274
|
}
|
|
275
275
|
}
|
|
276
276
|
async loadLangs(dir) {
|
|
277
|
-
dir ??= await this.getRC().then(x => x.langs);
|
|
277
|
+
dir ??= await this.getRC().then(x => x.locations.langs);
|
|
278
278
|
if (dir && this.langs) {
|
|
279
279
|
await this.langs.load(dir);
|
|
280
280
|
this.logger.info('LangsHandler loaded');
|
|
@@ -293,16 +293,21 @@ class BaseClient {
|
|
|
293
293
|
throw e.errors.find((err) => !err.stack?.includes('ERR_MODULE_NOT_FOUND')) ?? e.errors[0];
|
|
294
294
|
})));
|
|
295
295
|
const { locations, debug, ...env } = seyfertConfig;
|
|
296
|
+
const locationsFullPaths = {
|
|
297
|
+
base: locations.base,
|
|
298
|
+
output: locations.output,
|
|
299
|
+
};
|
|
300
|
+
for (const i in locations) {
|
|
301
|
+
const key = i;
|
|
302
|
+
const location = locations[i];
|
|
303
|
+
if (!location || locationsFullPaths[key])
|
|
304
|
+
continue;
|
|
305
|
+
locationsFullPaths[key] = (0, node_path_1.join)(process.cwd(), locations.output, location);
|
|
306
|
+
}
|
|
296
307
|
const obj = {
|
|
297
308
|
debug: !!debug,
|
|
298
309
|
...env,
|
|
299
|
-
|
|
300
|
-
langs: locations.langs ? (0, node_path_1.join)(process.cwd(), locations.output, locations.langs) : undefined,
|
|
301
|
-
events: 'events' in locations && locations.events ? (0, node_path_1.join)(process.cwd(), locations.output, locations.events) : undefined,
|
|
302
|
-
components: locations.components ? (0, node_path_1.join)(process.cwd(), locations.output, locations.components) : undefined,
|
|
303
|
-
commands: locations.commands ? (0, node_path_1.join)(process.cwd(), locations.output, locations.commands) : undefined,
|
|
304
|
-
base: (0, node_path_1.join)(process.cwd(), locations.base),
|
|
305
|
-
output: (0, node_path_1.join)(process.cwd(), locations.output),
|
|
310
|
+
locations: locationsFullPaths,
|
|
306
311
|
};
|
|
307
312
|
return obj;
|
|
308
313
|
}
|
package/lib/client/client.js
CHANGED
|
@@ -34,7 +34,7 @@ class Client extends base_1.BaseClient {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
async loadEvents(dir) {
|
|
37
|
-
dir ??= await this.getRC().then(x => x.events);
|
|
37
|
+
dir ??= await this.getRC().then(x => ('events' in x.locations ? x.locations.events : undefined));
|
|
38
38
|
if (dir && this.events) {
|
|
39
39
|
await this.events.load(dir);
|
|
40
40
|
this.logger.info('EventHandler loaded');
|
|
@@ -129,7 +129,7 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
129
129
|
this.cache.intents = workerData.intents;
|
|
130
130
|
}
|
|
131
131
|
async loadEvents(dir) {
|
|
132
|
-
dir ??= await this.getRC().then(x => x.events);
|
|
132
|
+
dir ??= await this.getRC().then(x => ('events' in x.locations ? x.locations.events : undefined));
|
|
133
133
|
if (dir && this.events) {
|
|
134
134
|
await this.events.load(dir);
|
|
135
135
|
this.logger.info('EventHandler loaded');
|
|
@@ -503,7 +503,7 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
503
503
|
});
|
|
504
504
|
await this.events?.runEvent('WORKER_SHARDS_CONNECTED', this, this.me, -1);
|
|
505
505
|
}
|
|
506
|
-
if (!this.__handleGuilds
|
|
506
|
+
if (!this.__handleGuilds?.length) {
|
|
507
507
|
if ([...this.shards.values()].every(shard => shard.data.session_id)) {
|
|
508
508
|
this.postMessage({
|
|
509
509
|
type: 'WORKER_READY',
|
|
@@ -4,6 +4,7 @@ import type { ModalContext } from '../../components';
|
|
|
4
4
|
import type { ComponentContext } from '../../components/componentcontext';
|
|
5
5
|
import type { MessageCommandInteraction, UserCommandInteraction } from '../../structures';
|
|
6
6
|
import { type APIApplicationCommandBasicOption, type APIApplicationCommandOptionChoice, ApplicationCommandOptionType, type ChannelType } from '../../types';
|
|
7
|
+
import type { LocalizationMap } from '../../types/payloads';
|
|
7
8
|
import type { CommandContext } from './chatcontext';
|
|
8
9
|
import type { DefaultLocale, MiddlewareContext, OKFunction, StopFunction } from './shared';
|
|
9
10
|
export interface SeyfertBasicOption<T extends keyof ReturnOptionsTypes, R = true | false> {
|
|
@@ -35,7 +36,11 @@ export interface SeyfertBaseChoiceableOption<T extends keyof ReturnOptionsTypes,
|
|
|
35
36
|
export type SeyfertChoice<T extends string | number> = {
|
|
36
37
|
readonly name: string;
|
|
37
38
|
readonly value: T;
|
|
38
|
-
|
|
39
|
+
name_localizations?: LocalizationMap | null;
|
|
40
|
+
locales?: FlatObjectKeys<DefaultLocale>;
|
|
41
|
+
} | (APIApplicationCommandOptionChoice<T> & {
|
|
42
|
+
locales?: FlatObjectKeys<DefaultLocale>;
|
|
43
|
+
});
|
|
39
44
|
export type ChoiceableTypes = ApplicationCommandOptionType.String | ApplicationCommandOptionType.Integer | ApplicationCommandOptionType.Number;
|
|
40
45
|
export interface ChoiceableValues {
|
|
41
46
|
[ApplicationCommandOptionType.String]: string;
|
|
@@ -19,6 +19,10 @@ export interface ExtraProps {
|
|
|
19
19
|
}
|
|
20
20
|
export interface UsingClient extends BaseClient {
|
|
21
21
|
}
|
|
22
|
+
export interface ExtendedRC {
|
|
23
|
+
}
|
|
24
|
+
export interface ExtendedRCLocations {
|
|
25
|
+
}
|
|
22
26
|
export type ParseClient<T extends BaseClient> = T;
|
|
23
27
|
export type ParseGlobalMiddlewares<T extends Record<string, MiddlewareContext>> = {
|
|
24
28
|
[K in keyof T]: MetadataMiddleware<T[K]>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EntryPointCommand } from '.';
|
|
2
|
-
import type { Logger,
|
|
2
|
+
import type { Logger, NulleableCoalising, OmitInsert } from '../common';
|
|
3
3
|
import { BaseHandler } from '../common';
|
|
4
4
|
import { type APIApplicationCommandOption, type LocalizationMap } from '../types';
|
|
5
5
|
import { Command, type CommandOption, SubCommand } from './applications/chat';
|
|
@@ -15,13 +15,14 @@ export declare class CommandHandler extends BaseHandler {
|
|
|
15
15
|
reload(resolve: string | Command): Promise<void>;
|
|
16
16
|
reloadAll(stopIfFail?: boolean): Promise<void>;
|
|
17
17
|
protected shouldUploadLocales(locales?: LocalizationMap | null, cachedLocales?: LocalizationMap | null): boolean;
|
|
18
|
+
protected shoudUploadChoices(option: APIApplicationCommandOption, cached: APIApplicationCommandOption): boolean;
|
|
18
19
|
protected shouldUploadOption(option: APIApplicationCommandOption, cached: APIApplicationCommandOption): boolean;
|
|
19
20
|
shouldUpload(file: string, guildId?: string): Promise<boolean>;
|
|
20
21
|
set(commands: SeteableCommand[]): void;
|
|
21
22
|
load(commandsDir: string, client: UsingClient): Promise<(Command | ContextMenuCommand)[]>;
|
|
22
23
|
parseLocales(command: InstanceType<HandleableCommand>): Command | ContextMenuCommand | SubCommand | EntryPointCommand;
|
|
23
24
|
parseGlobalLocales(command: InstanceType<HandleableCommand>): void;
|
|
24
|
-
parseCommandOptionLocales(option:
|
|
25
|
+
parseCommandOptionLocales(option: CommandOption): void;
|
|
25
26
|
parseCommandLocales(command: Command): void;
|
|
26
27
|
parseContextMenuLocales(command: ContextMenuCommand): ContextMenuCommand;
|
|
27
28
|
parseSubCommandLocales(command: SubCommand): SubCommand;
|
package/lib/commands/handler.js
CHANGED
|
@@ -47,21 +47,35 @@ class CommandHandler extends common_1.BaseHandler {
|
|
|
47
47
|
return true;
|
|
48
48
|
if (locales && !cachedLocales)
|
|
49
49
|
return true;
|
|
50
|
-
if (locales && cachedLocales)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
if (!(locales && cachedLocales))
|
|
51
|
+
return true;
|
|
52
|
+
const localesEntries = Object.entries(locales);
|
|
53
|
+
const cachedLocalesEntries = Object.entries(cachedLocales);
|
|
54
|
+
if (localesEntries.length !== cachedLocalesEntries.length)
|
|
55
|
+
return true;
|
|
56
|
+
for (const [key, value] of localesEntries) {
|
|
57
|
+
const cached = cachedLocalesEntries.find(x => x[0] === key);
|
|
58
|
+
if (!cached)
|
|
59
|
+
return true;
|
|
60
|
+
if (value !== cached[1])
|
|
54
61
|
return true;
|
|
55
|
-
for (const [key, value] of localesEntries) {
|
|
56
|
-
const cached = cachedLocalesEntries.find(x => x[0] === key);
|
|
57
|
-
if (!cached)
|
|
58
|
-
return true;
|
|
59
|
-
if (value !== cached[1])
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
62
|
}
|
|
63
63
|
return false;
|
|
64
64
|
}
|
|
65
|
+
shoudUploadChoices(option, cached) {
|
|
66
|
+
const optionChoiceable = option;
|
|
67
|
+
const cachedChoiceable = cached;
|
|
68
|
+
if (!(optionChoiceable.choices?.length && cachedChoiceable.choices?.length))
|
|
69
|
+
return false;
|
|
70
|
+
if (optionChoiceable.choices.length !== cachedChoiceable.choices.length)
|
|
71
|
+
return true;
|
|
72
|
+
return !optionChoiceable.choices.every((choice, index) => {
|
|
73
|
+
const cachedChoice = cachedChoiceable.choices[index];
|
|
74
|
+
return (choice.name === cachedChoice.name &&
|
|
75
|
+
choice.value === cachedChoice.value &&
|
|
76
|
+
!this.shouldUploadLocales(choice.name_localizations, cachedChoice.name_localizations));
|
|
77
|
+
});
|
|
78
|
+
}
|
|
65
79
|
shouldUploadOption(option, cached) {
|
|
66
80
|
if (option.description !== cached.description)
|
|
67
81
|
return true;
|
|
@@ -79,7 +93,9 @@ class CommandHandler extends common_1.BaseHandler {
|
|
|
79
93
|
switch (option.type) {
|
|
80
94
|
case types_1.ApplicationCommandOptionType.String:
|
|
81
95
|
return (option.min_length !== cached.min_length ||
|
|
82
|
-
option.max_length !== cached.max_length
|
|
96
|
+
option.max_length !== cached.max_length ||
|
|
97
|
+
!!option.autocomplete !== !!cached.autocomplete ||
|
|
98
|
+
this.shoudUploadChoices(option, cached));
|
|
83
99
|
case types_1.ApplicationCommandOptionType.Channel:
|
|
84
100
|
{
|
|
85
101
|
if (option.channel_types?.length !== cached.channel_types?.length)
|
|
@@ -113,7 +129,9 @@ class CommandHandler extends common_1.BaseHandler {
|
|
|
113
129
|
case types_1.ApplicationCommandOptionType.Integer:
|
|
114
130
|
case types_1.ApplicationCommandOptionType.Number:
|
|
115
131
|
return (option.min_value !== cached.min_value ||
|
|
116
|
-
option.max_value !== cached.max_value
|
|
132
|
+
option.max_value !== cached.max_value ||
|
|
133
|
+
!!option.autocomplete !== !!cached.autocomplete ||
|
|
134
|
+
this.shoudUploadChoices(option, cached));
|
|
117
135
|
case types_1.ApplicationCommandOptionType.Attachment:
|
|
118
136
|
case types_1.ApplicationCommandOptionType.Boolean:
|
|
119
137
|
case types_1.ApplicationCommandOptionType.Mentionable:
|
|
@@ -272,7 +290,7 @@ class CommandHandler extends common_1.BaseHandler {
|
|
|
272
290
|
}
|
|
273
291
|
for (const fileSubCommand of fileSubCommands) {
|
|
274
292
|
const subCommand = this.onSubCommand(fileSubCommand);
|
|
275
|
-
if (subCommand
|
|
293
|
+
if (subCommand instanceof chat_1.SubCommand) {
|
|
276
294
|
subCommand.__filePath = option;
|
|
277
295
|
commandInstance.options.push(subCommand);
|
|
278
296
|
}
|
|
@@ -308,16 +326,14 @@ class CommandHandler extends common_1.BaseHandler {
|
|
|
308
326
|
this.parseContextMenuLocales(command);
|
|
309
327
|
return command;
|
|
310
328
|
}
|
|
311
|
-
if (command instanceof chat_1.Command
|
|
329
|
+
if (command instanceof chat_1.Command) {
|
|
312
330
|
this.parseCommandLocales(command);
|
|
313
331
|
for (const option of command.options ?? []) {
|
|
314
332
|
if (option instanceof chat_1.SubCommand) {
|
|
315
333
|
this.parseSubCommandLocales(option);
|
|
316
334
|
continue;
|
|
317
335
|
}
|
|
318
|
-
|
|
319
|
-
if (option.locales)
|
|
320
|
-
this.parseCommandOptionLocales(option);
|
|
336
|
+
this.parseCommandOptionLocales(option);
|
|
321
337
|
}
|
|
322
338
|
}
|
|
323
339
|
if (command instanceof chat_1.SubCommand) {
|
|
@@ -327,8 +343,8 @@ class CommandHandler extends common_1.BaseHandler {
|
|
|
327
343
|
}
|
|
328
344
|
parseGlobalLocales(command) {
|
|
329
345
|
if (command.__t) {
|
|
330
|
-
command.name_localizations
|
|
331
|
-
command.description_localizations
|
|
346
|
+
command.name_localizations ??= {};
|
|
347
|
+
command.description_localizations ??= {};
|
|
332
348
|
for (const locale of Object.keys(this.client.langs.values)) {
|
|
333
349
|
const locales = this.client.langs.aliases.find(x => x[0] === locale)?.[1] ?? [];
|
|
334
350
|
if (Object.values(types_1.Locale).includes(locale))
|
|
@@ -351,30 +367,42 @@ class CommandHandler extends common_1.BaseHandler {
|
|
|
351
367
|
}
|
|
352
368
|
}
|
|
353
369
|
parseCommandOptionLocales(option) {
|
|
354
|
-
option.name_localizations
|
|
355
|
-
option.description_localizations
|
|
370
|
+
option.name_localizations ??= {};
|
|
371
|
+
option.description_localizations ??= {};
|
|
356
372
|
for (const locale of Object.keys(this.client.langs.values)) {
|
|
357
373
|
const locales = this.client.langs.aliases.find(x => x[0] === locale)?.[1] ?? [];
|
|
358
374
|
if (Object.values(types_1.Locale).includes(locale))
|
|
359
375
|
locales.push(locale);
|
|
360
|
-
if (option.locales
|
|
376
|
+
if (option.locales?.name) {
|
|
361
377
|
for (const i of locales) {
|
|
362
378
|
const valueName = this.client.langs.getKey(locale, option.locales.name);
|
|
363
379
|
if (valueName)
|
|
364
380
|
option.name_localizations[i] = valueName;
|
|
365
381
|
}
|
|
366
382
|
}
|
|
367
|
-
if (option.locales
|
|
383
|
+
if (option.locales?.description) {
|
|
368
384
|
for (const i of locales) {
|
|
369
385
|
const valueKey = this.client.langs.getKey(locale, option.locales.description);
|
|
370
386
|
if (valueKey)
|
|
371
387
|
option.description_localizations[i] = valueKey;
|
|
372
388
|
}
|
|
373
389
|
}
|
|
390
|
+
if ('choices' in option && option.choices?.length) {
|
|
391
|
+
for (const c of option.choices) {
|
|
392
|
+
c.name_localizations ??= {};
|
|
393
|
+
if (!c.locales)
|
|
394
|
+
continue;
|
|
395
|
+
for (const i of locales) {
|
|
396
|
+
const valueKey = this.client.langs.getKey(locale, c.locales);
|
|
397
|
+
if (valueKey)
|
|
398
|
+
c.name_localizations[i] = valueKey;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
374
402
|
}
|
|
375
403
|
}
|
|
376
404
|
parseCommandLocales(command) {
|
|
377
|
-
command.groups
|
|
405
|
+
command.groups ??= {};
|
|
378
406
|
for (const locale of Object.keys(this.client.langs.values)) {
|
|
379
407
|
const locales = this.client.langs.aliases.find(x => x[0] === locale)?.[1] ?? [];
|
|
380
408
|
if (Object.values(types_1.Locale).includes(locale))
|
|
@@ -409,9 +437,7 @@ class CommandHandler extends common_1.BaseHandler {
|
|
|
409
437
|
}
|
|
410
438
|
parseSubCommandLocales(command) {
|
|
411
439
|
for (const i of command.options ?? []) {
|
|
412
|
-
|
|
413
|
-
if (i.locales)
|
|
414
|
-
this.parseCommandOptionLocales(i);
|
|
440
|
+
this.parseCommandOptionLocales(i);
|
|
415
441
|
}
|
|
416
442
|
return command;
|
|
417
443
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "seyfert",
|
|
3
|
-
"version": "2.1.1-dev-
|
|
3
|
+
"version": "2.1.1-dev-11520718826.0",
|
|
4
4
|
"description": "The most advanced framework for discord bots",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"module": "./lib/index.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@biomejs/biome": "1.9.4",
|
|
25
25
|
"@commitlint/cli": "^19.5.0",
|
|
26
26
|
"@commitlint/config-conventional": "^19.5.0",
|
|
27
|
-
"@types/node": "^22.7.
|
|
27
|
+
"@types/node": "^22.7.9",
|
|
28
28
|
"husky": "^9.1.6",
|
|
29
29
|
"lint-staged": "^15.2.10",
|
|
30
30
|
"typescript": "^5.6.3",
|