@ezzi/base 1.0.3 → 2.0.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.
|
@@ -80,7 +80,6 @@ export interface GroupOptionData<Contexts> extends Omit<BaseOptionData, "require
|
|
|
80
80
|
export type SlashCommandOptionData<Contexts> = SlashCommandPrimitiveOptionData<Contexts> | GroupOptionData<Contexts> | SubCommandOptionData<Contexts>;
|
|
81
81
|
export type RunInteraction<T, Contexts> = T extends ApplicationCommandType.Message ? MessageContextMenuCommandInteraction<CacheMode<Contexts>> : T extends ApplicationCommandType.User ? UserContextMenuCommandInteraction<CacheMode<Contexts>> : ChatInputCommandInteraction<CacheMode<Contexts>>;
|
|
82
82
|
interface CommandRunThis {
|
|
83
|
-
/** Blocks the flow of executions */
|
|
84
83
|
block(): never;
|
|
85
84
|
}
|
|
86
85
|
type BaseAppCommandData = Omit<BaseApplicationCommandData, "contexts" | "dmPermission"> & Pick<BaseOptionData, "descriptionLocalizations">;
|
|
@@ -133,6 +132,7 @@ declare class GroupCommandModule<Type, Contexts extends readonly InteractionCont
|
|
|
133
132
|
export declare class Command<Type, Contexts extends readonly InteractionContextType[] = readonly InteractionContextType[], Return = unknown> {
|
|
134
133
|
readonly modules: CommandModule[];
|
|
135
134
|
readonly data: AppCommandData<Type, Contexts, Return>;
|
|
135
|
+
moduleListener?: (module: CommandModule) => void;
|
|
136
136
|
constructor(data: AppCommandData<Type, Contexts, Return>);
|
|
137
137
|
group<ModuleReturn = Return>(data: SubCommandGroupModuleData<Contexts, Return, ModuleReturn>): GroupCommandModule<Type, Contexts, Return, ModuleReturn>;
|
|
138
138
|
subcommand<R = Return>(data: SubCommandModuleData<Contexts, R>): this;
|
|
@@ -26,6 +26,7 @@ class GroupCommandModule {
|
|
|
26
26
|
class Command {
|
|
27
27
|
modules = [];
|
|
28
28
|
data;
|
|
29
|
+
moduleListener;
|
|
29
30
|
constructor(data) {
|
|
30
31
|
this.data = data;
|
|
31
32
|
this.data.type ??= ApplicationCommandType.ChatInput;
|
|
@@ -41,17 +42,21 @@ class Command {
|
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
44
|
group(data) {
|
|
44
|
-
|
|
45
|
+
const module = {
|
|
45
46
|
...data,
|
|
46
47
|
type: ApplicationCommandOptionType.SubcommandGroup
|
|
47
|
-
}
|
|
48
|
+
};
|
|
49
|
+
this.modules.push(module);
|
|
50
|
+
this.moduleListener?.(module);
|
|
48
51
|
return new GroupCommandModule(this, data);
|
|
49
52
|
}
|
|
50
53
|
subcommand(data) {
|
|
51
|
-
|
|
54
|
+
const module = {
|
|
52
55
|
...data,
|
|
53
56
|
type: ApplicationCommandOptionType.Subcommand
|
|
54
|
-
}
|
|
57
|
+
};
|
|
58
|
+
this.modules.push(module);
|
|
59
|
+
this.moduleListener?.(module);
|
|
55
60
|
return this;
|
|
56
61
|
}
|
|
57
62
|
}
|
|
@@ -66,8 +66,6 @@ class CommandManager {
|
|
|
66
66
|
for (const [k, v] of this.aliasCollection) {
|
|
67
67
|
this.runtimeCollection.set(k, v);
|
|
68
68
|
}
|
|
69
|
-
this.collection.clear();
|
|
70
|
-
this.aliasCollection.clear();
|
|
71
69
|
}
|
|
72
70
|
getAutocompleteHandler(...path) {
|
|
73
71
|
const commandName = path[0];
|
|
@@ -162,6 +160,9 @@ class CommandManager {
|
|
|
162
160
|
options: subcommands,
|
|
163
161
|
defaultMemberPermissions,
|
|
164
162
|
botPermissions,
|
|
163
|
+
run: _groupRun,
|
|
164
|
+
ignore: _groupIgnore,
|
|
165
|
+
aliases: _groupAliases,
|
|
165
166
|
...data
|
|
166
167
|
} = option;
|
|
167
168
|
if (botPermissions?.length) {
|
|
@@ -180,6 +181,11 @@ class CommandManager {
|
|
|
180
181
|
options: subOpts,
|
|
181
182
|
defaultMemberPermissions,
|
|
182
183
|
botPermissions,
|
|
184
|
+
run: _subRun,
|
|
185
|
+
ignore: _subIgnore,
|
|
186
|
+
aliases: _subAliases,
|
|
187
|
+
shortcut: _subShortcut,
|
|
188
|
+
group: _subGroup,
|
|
183
189
|
...data
|
|
184
190
|
} = option;
|
|
185
191
|
if (botPermissions?.length) {
|
|
@@ -272,21 +278,22 @@ class CommandManager {
|
|
|
272
278
|
const type = data.type ?? ApplicationCommandType.ChatInput;
|
|
273
279
|
const name = this.formatName(data.name, type);
|
|
274
280
|
const dmPermission = data.dmPermission ?? false;
|
|
281
|
+
const existingData = this.collection.get(name);
|
|
275
282
|
const commandData = {
|
|
276
283
|
...data,
|
|
277
284
|
name,
|
|
278
285
|
type,
|
|
279
|
-
dmPermission
|
|
286
|
+
dmPermission,
|
|
287
|
+
modules: existingData?.modules ?? []
|
|
280
288
|
};
|
|
281
|
-
if (
|
|
282
|
-
const existing = this.collection.get(name);
|
|
289
|
+
if (existingData) {
|
|
283
290
|
const canonicalPath2 = `/${type}/${name}`;
|
|
284
291
|
this.commandRunners.delete(canonicalPath2);
|
|
285
292
|
this.optionDefs.delete(canonicalPath2);
|
|
286
293
|
this.botPermissionsMap.delete(canonicalPath2);
|
|
287
294
|
this.autocompleteRunners.delete(canonicalPath2);
|
|
288
|
-
if (
|
|
289
|
-
for (const alias of
|
|
295
|
+
if (existingData.aliases?.length) {
|
|
296
|
+
for (const alias of existingData.aliases) {
|
|
290
297
|
this.aliasCollection.delete(this.formatName(alias, type));
|
|
291
298
|
}
|
|
292
299
|
}
|
|
@@ -323,6 +330,9 @@ class CommandManager {
|
|
|
323
330
|
descriptionLocalizations,
|
|
324
331
|
category,
|
|
325
332
|
botPermissions: _bp,
|
|
333
|
+
run: _run,
|
|
334
|
+
ignore: _ignore,
|
|
335
|
+
aliases: _aliases,
|
|
326
336
|
...data
|
|
327
337
|
} = raw;
|
|
328
338
|
const path = `/${data.type}/${data.name}`;
|
|
@@ -331,7 +341,7 @@ class CommandManager {
|
|
|
331
341
|
descriptionLocalizations,
|
|
332
342
|
options: this.buildOptions([
|
|
333
343
|
...options ?? [],
|
|
334
|
-
...this.resolveModules(modules ?? [], path,
|
|
344
|
+
...this.resolveModules(modules ?? [], path, raw.run)
|
|
335
345
|
], path)
|
|
336
346
|
} : {};
|
|
337
347
|
return { ...data, ...slashData, category };
|
|
@@ -344,8 +354,10 @@ class CommandManager {
|
|
|
344
354
|
}
|
|
345
355
|
addModule(commandName, module) {
|
|
346
356
|
const command = this.collection.get(commandName);
|
|
347
|
-
if (!command)
|
|
357
|
+
if (!command) {
|
|
358
|
+
console.warn(`[EzziApp] Comando "${commandName}" não encontrado ao registrar o módulo "${module.name}". Verifique se createCommand foi chamado antes de subcommand/group para esse comando.`);
|
|
348
359
|
return;
|
|
360
|
+
}
|
|
349
361
|
command.modules ??= [];
|
|
350
362
|
command.modules.push(module);
|
|
351
363
|
}
|
|
@@ -513,6 +525,10 @@ class CommandManager {
|
|
|
513
525
|
const messages = [];
|
|
514
526
|
const pluralize = (n) => n > 1 ? "s" : "";
|
|
515
527
|
const commands = this.build();
|
|
528
|
+
const stripInternal = (cmd) => {
|
|
529
|
+
const { global: _global, category: _category, ...rest } = cmd;
|
|
530
|
+
return rest;
|
|
531
|
+
};
|
|
516
532
|
const createVerboseLogs = (cmdsCollection) => cmdsCollection.map(({ id, name, type, client: cl, createdAt, guild }) => {
|
|
517
533
|
const [icon] = this.getTitle({
|
|
518
534
|
type
|
|
@@ -528,21 +544,26 @@ class CommandManager {
|
|
|
528
544
|
}
|
|
529
545
|
};
|
|
530
546
|
const targetGuilds = client.guilds.cache.filter(({ id }) => this.config.guilds?.includes(id));
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
const
|
|
541
|
-
|
|
547
|
+
try {
|
|
548
|
+
if (targetGuilds.size) {
|
|
549
|
+
const globalCommands = commands.filter((c) => c.global).map(stripInternal);
|
|
550
|
+
const guildCommands = commands.filter((c) => !c.global).map(stripInternal);
|
|
551
|
+
await client.application.commands.set(globalCommands).then((cmds) => {
|
|
552
|
+
if (!cmds.size)
|
|
553
|
+
return;
|
|
554
|
+
logRegistration(cmds, "globally");
|
|
555
|
+
});
|
|
556
|
+
for (const guild of targetGuilds.values()) {
|
|
557
|
+
const cmds = await guild.commands.set(guildCommands);
|
|
558
|
+
logRegistration(cmds, `in ${ck.underline(guild.name)} guild`);
|
|
559
|
+
}
|
|
560
|
+
} else {
|
|
561
|
+
await Promise.all(client.guilds.cache.map((guild) => guild.commands.set([])));
|
|
562
|
+
const globalCommands = commands.map(stripInternal);
|
|
563
|
+
await client.application.commands.set(globalCommands).then((cmds) => logRegistration(cmds, "globally"));
|
|
542
564
|
}
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
await client.application.commands.set(commands).then((cmds) => logRegistration(cmds, "globally"));
|
|
565
|
+
} catch (err) {
|
|
566
|
+
console.error("[EzziApp] Falha ao registrar comandos no Discord:", err);
|
|
546
567
|
}
|
|
547
568
|
const prefixCount = this.getPrefixCommandCount();
|
|
548
569
|
if (prefixCount > 0 && this.config.prefix) {
|
package/dist/creators/setup.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ApplicationCommandType, InteractionContextType, type CacheType, type ClientEvents, type PermissionResolvable } from "discord.js";
|
|
2
2
|
import { type BaseCommandsConfig, type BaseEventsConfig, type BaseRespondersConfig } from "../app.js";
|
|
3
|
-
import { type AppCommandData, type CommandType } from "./commands/command.js";
|
|
3
|
+
import { Command, type AppCommandData, type CommandType } from "./commands/command.js";
|
|
4
4
|
import { type EventData } from "./events/event.js";
|
|
5
5
|
import { Responder, type ResponderData, type ResponderType } from "./responders/responder.js";
|
|
6
6
|
export interface SetupCreatorsOptions {
|
|
@@ -11,15 +11,8 @@ export interface SetupCreatorsOptions {
|
|
|
11
11
|
responders?: Partial<BaseRespondersConfig>;
|
|
12
12
|
events?: Partial<BaseEventsConfig>;
|
|
13
13
|
}
|
|
14
|
-
/**
|
|
15
|
-
* Initializes the Ezzi command/event/responder creation system.
|
|
16
|
-
*
|
|
17
|
-
* This function configures the Ezzi application’s internal registries
|
|
18
|
-
* for commands, events, and responders, and returns a set of factory
|
|
19
|
-
* functions used to create each type of component.
|
|
20
|
-
*/
|
|
21
14
|
export declare function setupCreators(options?: SetupCreatorsOptions): {
|
|
22
|
-
createCommand<T extends CommandType = ApplicationCommandType.ChatInput,
|
|
15
|
+
createCommand<T extends CommandType = ApplicationCommandType.ChatInput, const C extends readonly InteractionContextType[] = [InteractionContextType.Guild], R = void>(data: AppCommandData<T, C, R>): Command<T, C, R>;
|
|
23
16
|
createEvent<EventName extends keyof ClientEvents>(data: EventData<EventName>): void;
|
|
24
17
|
createResponder<Path extends string, const Types extends readonly ResponderType[], Schema, Cache extends CacheType = CacheType>(data: ResponderData<Path, Types, Schema, Cache>): Responder<string, readonly ResponderType[], unknown, CacheType>;
|
|
25
18
|
};
|
package/dist/creators/setup.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
// src/creators/setup.ts
|
|
2
|
-
import {
|
|
3
|
-
ApplicationCommandOptionType,
|
|
4
|
-
ApplicationCommandType
|
|
5
|
-
} from "discord.js";
|
|
6
2
|
import {
|
|
7
3
|
EzziApp
|
|
8
4
|
} from "../app.js";
|
|
5
|
+
import {
|
|
6
|
+
Command
|
|
7
|
+
} from "./commands/command.js";
|
|
9
8
|
import { Event } from "./events/event.js";
|
|
10
9
|
import {
|
|
11
10
|
Responder
|
|
@@ -24,46 +23,19 @@ function setupCreators(options = {}) {
|
|
|
24
23
|
return {
|
|
25
24
|
createCommand(data) {
|
|
26
25
|
const currentApp = EzziApp.getInstance();
|
|
27
|
-
if (defaultMemberPerms)
|
|
26
|
+
if (defaultMemberPerms)
|
|
28
27
|
data.defaultMemberPermissions ??= defaultMemberPerms;
|
|
29
|
-
|
|
30
|
-
if (defaultBotPerms && !data.botPermissions?.length) {
|
|
28
|
+
if (defaultBotPerms && !data.botPermissions?.length)
|
|
31
29
|
data.botPermissions = defaultBotPerms;
|
|
32
|
-
|
|
33
|
-
const resolved = currentApp.commands.set(data);
|
|
30
|
+
const command = new Command(data);
|
|
31
|
+
const resolved = currentApp.commands.set(command.data);
|
|
32
|
+
command.moduleListener = (module) => {
|
|
33
|
+
currentApp.commands.addModule(resolved.name, module);
|
|
34
|
+
};
|
|
34
35
|
if (typeof currentApp.commands.addLog === "function") {
|
|
35
36
|
currentApp.commands.addLog(resolved);
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
-
return resolved;
|
|
39
|
-
}
|
|
40
|
-
const commandName = resolved.name;
|
|
41
|
-
const createSubcommand = (group) => (subData) => {
|
|
42
|
-
const subApp = EzziApp.getInstance();
|
|
43
|
-
if (defaultBotPerms && !subData.botPermissions?.length) {
|
|
44
|
-
subData = { ...subData, botPermissions: defaultBotPerms };
|
|
45
|
-
}
|
|
46
|
-
subApp.commands.addModule(commandName, {
|
|
47
|
-
...subData,
|
|
48
|
-
group,
|
|
49
|
-
type: ApplicationCommandOptionType.Subcommand
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
return Object.assign(data, {
|
|
53
|
-
...resolved,
|
|
54
|
-
group(groupData) {
|
|
55
|
-
const groupApp = EzziApp.getInstance();
|
|
56
|
-
if (defaultBotPerms && !groupData.botPermissions?.length) {
|
|
57
|
-
groupData = { ...groupData, botPermissions: defaultBotPerms };
|
|
58
|
-
}
|
|
59
|
-
groupApp.commands.addModule(commandName, {
|
|
60
|
-
...groupData,
|
|
61
|
-
type: ApplicationCommandOptionType.SubcommandGroup
|
|
62
|
-
});
|
|
63
|
-
return { subcommand: createSubcommand(groupData.name) };
|
|
64
|
-
},
|
|
65
|
-
subcommand: createSubcommand()
|
|
66
|
-
});
|
|
38
|
+
return command;
|
|
67
39
|
},
|
|
68
40
|
createEvent(data) {
|
|
69
41
|
const currentApp = EzziApp.getInstance();
|