@globalart/nestcord 1.5.9 → 1.6.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/dist/core/src/commands/command.discovery.d.ts +10 -1
- package/dist/core/src/commands/command.discovery.js +13 -0
- package/dist/core/src/commands/commands.module.d.ts +1 -0
- package/dist/core/src/commands/commands.module.js +16 -4
- package/dist/core/src/commands/commands.service.d.ts +1 -0
- package/dist/core/src/commands/commands.service.js +12 -0
- package/dist/core/src/commands/slash-commands/slash-command.discovery.d.ts +1 -0
- package/dist/core/src/commands/slash-commands/slash-commands.service.d.ts +1 -0
- package/dist/core/src/commands/slash-commands/slash-commands.service.js +3 -0
- package/dist/core/src/context/nestcord-base.discovery.d.ts +1 -1
- package/dist/core/src/nestcord-options.interface.d.ts +4 -0
- package/package.json +1 -1
|
@@ -1,14 +1,23 @@
|
|
|
1
|
-
import { BaseApplicationCommandData, Snowflake } from 'discord.js';
|
|
1
|
+
import { ApplicationCommand, BaseApplicationCommandData, Snowflake } from 'discord.js';
|
|
2
2
|
import { NestCordBaseDiscovery } from '../context';
|
|
3
3
|
export interface BaseCommandMeta extends BaseApplicationCommandData {
|
|
4
4
|
guilds?: Snowflake[];
|
|
5
5
|
category?: string;
|
|
6
|
+
discordResponse?: ApplicationCommand;
|
|
6
7
|
}
|
|
7
8
|
/**
|
|
8
9
|
* Represents a command discovery.
|
|
9
10
|
* @abstract
|
|
10
11
|
*/
|
|
11
12
|
export declare abstract class CommandDiscovery<T extends BaseCommandMeta = BaseCommandMeta> extends NestCordBaseDiscovery<T> {
|
|
13
|
+
/**
|
|
14
|
+
* Return the command ID
|
|
15
|
+
*/
|
|
16
|
+
getId(): string;
|
|
17
|
+
/**
|
|
18
|
+
* Return the discord response of command
|
|
19
|
+
*/
|
|
20
|
+
getDiscordResponse(): ApplicationCommand<{}>;
|
|
12
21
|
/**
|
|
13
22
|
* Returns the command name.
|
|
14
23
|
*/
|
|
@@ -7,6 +7,19 @@ const context_1 = require("../context");
|
|
|
7
7
|
* @abstract
|
|
8
8
|
*/
|
|
9
9
|
class CommandDiscovery extends context_1.NestCordBaseDiscovery {
|
|
10
|
+
/**
|
|
11
|
+
* Return the command ID
|
|
12
|
+
*/
|
|
13
|
+
getId() {
|
|
14
|
+
var _a;
|
|
15
|
+
return (_a = this.meta.discordResponse) === null || _a === void 0 ? void 0 : _a.id;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Return the discord response of command
|
|
19
|
+
*/
|
|
20
|
+
getDiscordResponse() {
|
|
21
|
+
return this.meta.discordResponse;
|
|
22
|
+
}
|
|
10
23
|
/**
|
|
11
24
|
* Returns the command name.
|
|
12
25
|
*/
|
|
@@ -12,5 +12,6 @@ export declare class CommandsModule implements OnModuleInit, OnApplicationBootst
|
|
|
12
12
|
private readonly slashCommandsService;
|
|
13
13
|
constructor(client: Client, options: NestCordModuleOptions, commandsService: CommandsService, contextMenusService: ContextMenusService, slashCommandsService: SlashCommandsService);
|
|
14
14
|
onModuleInit(): Promise<void>;
|
|
15
|
+
private initializeClient;
|
|
15
16
|
onApplicationBootstrap(): void;
|
|
16
17
|
}
|
|
@@ -38,15 +38,27 @@ let CommandsModule = class CommandsModule {
|
|
|
38
38
|
}
|
|
39
39
|
onModuleInit() {
|
|
40
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
if (this.options.skipRegistration) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
41
|
this.client.once('ready', () => __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
yield this.initializeClient();
|
|
43
|
+
}));
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
initializeClient() {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const { skipGetCommandInfoFromDiscord, skipRegistration } = this.options;
|
|
49
|
+
if (!skipGetCommandInfoFromDiscord) {
|
|
50
|
+
yield this.client.application.commands.fetch();
|
|
51
|
+
this.commandsService.getAllCommandsAndSetAdditionalMeta();
|
|
52
|
+
}
|
|
53
|
+
if (!skipRegistration) {
|
|
45
54
|
if (this.client.application.partial) {
|
|
46
55
|
yield this.client.application.fetch();
|
|
47
56
|
}
|
|
48
57
|
yield this.commandsService.registerAllCommands();
|
|
49
|
-
|
|
58
|
+
if (!skipGetCommandInfoFromDiscord) {
|
|
59
|
+
this.commandsService.getAllCommandsAndSetAdditionalMeta();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
50
62
|
});
|
|
51
63
|
}
|
|
52
64
|
onApplicationBootstrap() {
|
|
@@ -30,4 +30,5 @@ export declare class CommandsService {
|
|
|
30
30
|
getGlobalCommandByName(name: string): CommandDiscovery;
|
|
31
31
|
getGuildCommands(guildId: string): CommandDiscovery[];
|
|
32
32
|
getGuildCommandByName(guildId: string, name: string): CommandDiscovery;
|
|
33
|
+
getAllCommandsAndSetAdditionalMeta(): void;
|
|
33
34
|
}
|
|
@@ -110,6 +110,18 @@ let CommandsService = CommandsService_1 = class CommandsService {
|
|
|
110
110
|
getGuildCommandByName(guildId, name) {
|
|
111
111
|
return this.getGuildCommands(guildId).find((command) => command.getName() === name);
|
|
112
112
|
}
|
|
113
|
+
getAllCommandsAndSetAdditionalMeta() {
|
|
114
|
+
const commands = this.getCommandsMap();
|
|
115
|
+
const commandsCache = this.client.application.commands.cache;
|
|
116
|
+
const matchingCommands = Array.from(commandsCache.values()).filter((command) => commands.has(command.name));
|
|
117
|
+
for (const command of matchingCommands) {
|
|
118
|
+
const commandByName = commands.get(command.name);
|
|
119
|
+
if (commandByName.meta) {
|
|
120
|
+
commandByName.meta.discordResponse = command;
|
|
121
|
+
}
|
|
122
|
+
this.slashCommandsService.update(commandByName);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
113
125
|
};
|
|
114
126
|
exports.CommandsService = CommandsService;
|
|
115
127
|
exports.CommandsService = CommandsService = CommandsService_1 = __decorate([
|
|
@@ -5,6 +5,7 @@ export interface SlashCommandMeta extends ChatInputApplicationCommandData {
|
|
|
5
5
|
type?: ApplicationCommandType.ChatInput | ApplicationCommandOptionType.SubcommandGroup | ApplicationCommandOptionType.Subcommand;
|
|
6
6
|
category?: string;
|
|
7
7
|
guilds?: Snowflake[];
|
|
8
|
+
discordResponse?: any;
|
|
8
9
|
}
|
|
9
10
|
export interface OptionMeta extends APIApplicationCommandOptionBase<any> {
|
|
10
11
|
resolver?: keyof CommandInteractionOptionResolver;
|
|
@@ -10,6 +10,7 @@ export declare class SlashCommandsService {
|
|
|
10
10
|
readonly cache: Collection<string, SlashCommandDiscovery>;
|
|
11
11
|
constructor(reflector: Reflector);
|
|
12
12
|
add(command: SlashCommandDiscovery): void;
|
|
13
|
+
update(command: SlashCommandDiscovery): void;
|
|
13
14
|
get(commandName: string): SlashCommandDiscovery;
|
|
14
15
|
remove(commandName: string): boolean;
|
|
15
16
|
addSubCommand(subCommand: SlashCommandDiscovery): void;
|
|
@@ -30,6 +30,9 @@ let SlashCommandsService = SlashCommandsService_1 = class SlashCommandsService {
|
|
|
30
30
|
}
|
|
31
31
|
this.cache.set(command.getName(), command);
|
|
32
32
|
}
|
|
33
|
+
update(command) {
|
|
34
|
+
this.cache.set(command.getName(), command);
|
|
35
|
+
}
|
|
33
36
|
get(commandName) {
|
|
34
37
|
return this.cache.get(commandName);
|
|
35
38
|
}
|
|
@@ -9,7 +9,7 @@ interface DiscoveredItem {
|
|
|
9
9
|
handler?: (...args: unknown[]) => void;
|
|
10
10
|
}
|
|
11
11
|
export declare abstract class NestCordBaseDiscovery<T = unknown> {
|
|
12
|
-
|
|
12
|
+
meta: T;
|
|
13
13
|
protected readonly reflector: Reflector;
|
|
14
14
|
protected discovery: DiscoveredItem;
|
|
15
15
|
protected contextCallback: Function;
|
|
@@ -23,4 +23,8 @@ export interface NestCordModuleOptions extends DiscordClientOptions {
|
|
|
23
23
|
* If skipRegistration is true, nestcord would not automatically register your application commands with Discord. You would have to register the application commands manually.
|
|
24
24
|
*/
|
|
25
25
|
skipRegistration?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* If true, the bot won't fetch data from the Discord API, and discordResponse in the commandDiscovery will be null."
|
|
28
|
+
*/
|
|
29
|
+
skipGetCommandInfoFromDiscord?: boolean;
|
|
26
30
|
}
|
package/package.json
CHANGED