@wolfstar/plugin-subcommands-advanced 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.
- package/LICENSE +202 -0
- package/README.md +124 -0
- package/dist/esm/index-BuJfV_kf.d.ts +280 -0
- package/dist/esm/index-BuJfV_kf.d.ts.map +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/register.d.ts +19 -0
- package/dist/esm/register.d.ts.map +1 -0
- package/dist/esm/register.js +30 -0
- package/dist/esm/register.js.map +1 -0
- package/dist/esm/src-JCzq0KZw.js +384 -0
- package/dist/esm/src-JCzq0KZw.js.map +1 -0
- package/package.json +71 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# `@wolfstar/plugin-subcommands-advanced`
|
|
2
|
+
|
|
3
|
+
Plugin for [`@wolfstar/http-framework`](https://www.npmjs.com/package/@wolfstar/http-framework) that lets you split slash **subcommands** (and subcommand groups) into **separate command classes**, instead of putting every handler method on the parent.
|
|
4
|
+
|
|
5
|
+
Adapted from [`@kaname-png/plugin-subcommands-advanced`](https://github.com/sawa-ko/neko-plugins/tree/main/packages/subcommands-advanced) for WolfStar’s HTTP interaction framework.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @wolfstar/http-framework @wolfstar/plugin-subcommands-advanced
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
Import the register entrypoint **before** creating the client:
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import "@wolfstar/plugin-subcommands-advanced/register";
|
|
19
|
+
import { Client, RegisterCommand } from "@wolfstar/http-framework";
|
|
20
|
+
import {
|
|
21
|
+
Command,
|
|
22
|
+
Subcommand,
|
|
23
|
+
RegisterAsSubcommand,
|
|
24
|
+
RegisterAsSubcommandGroup,
|
|
25
|
+
} from "@wolfstar/plugin-subcommands-advanced";
|
|
26
|
+
|
|
27
|
+
const client = new Client({
|
|
28
|
+
subcommandsAdvanced: {
|
|
29
|
+
// optional: piece names become parent/sub or parent/group/sub
|
|
30
|
+
nameCommandsAutogenerated: true,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Recommended layout:
|
|
36
|
+
|
|
37
|
+
```text
|
|
38
|
+
commands/
|
|
39
|
+
└── utils/
|
|
40
|
+
├── parent.ts // parent chat-input command
|
|
41
|
+
├── ping.ts // subcommand
|
|
42
|
+
└── poll/
|
|
43
|
+
└── create.ts // grouped subcommand
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Parent command
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { RegisterCommand } from "@wolfstar/http-framework";
|
|
50
|
+
import { Subcommand } from "@wolfstar/plugin-subcommands-advanced";
|
|
51
|
+
|
|
52
|
+
@RegisterCommand((builder) =>
|
|
53
|
+
builder
|
|
54
|
+
.setName("utils")
|
|
55
|
+
.setDescription("Utility commands")
|
|
56
|
+
.addSubcommandGroup((group) => group.setName("poll").setDescription("Poll tools")),
|
|
57
|
+
)
|
|
58
|
+
export class UtilsCommand extends Subcommand {}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Direct subcommand
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
import { Command, RegisterAsSubcommand } from "@wolfstar/plugin-subcommands-advanced";
|
|
65
|
+
|
|
66
|
+
@RegisterAsSubcommand("utils", (builder) => builder.setName("ping").setDescription("Ping the bot"))
|
|
67
|
+
export class PingCommand extends Command {
|
|
68
|
+
public override chatInputRun(interaction: Command.ChatInputInteraction) {
|
|
69
|
+
return interaction.reply({ content: "Pong!" });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Grouped subcommand
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import { Command, RegisterAsSubcommandGroup } from "@wolfstar/plugin-subcommands-advanced";
|
|
78
|
+
|
|
79
|
+
@RegisterAsSubcommandGroup("utils", "poll", (builder) =>
|
|
80
|
+
builder.setName("create").setDescription("Create a poll"),
|
|
81
|
+
)
|
|
82
|
+
export class PollCreateCommand extends Command {
|
|
83
|
+
public override chatInputRun(interaction: Command.ChatInputInteraction) {
|
|
84
|
+
return interaction.reply({ content: "Created!" });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Constructor options (no decorators)
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
import { Command } from "@wolfstar/plugin-subcommands-advanced";
|
|
93
|
+
|
|
94
|
+
export class PingCommand extends Command {
|
|
95
|
+
public constructor(context: Command.LoaderContext, options: Command.Options) {
|
|
96
|
+
super(context, {
|
|
97
|
+
...options,
|
|
98
|
+
registerSubCommand: {
|
|
99
|
+
parentCommandName: "utils",
|
|
100
|
+
slashSubcommand: (builder) => builder.setName("ping").setDescription("Ping!"),
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
public override chatInputRun(interaction: Command.ChatInputInteraction) {
|
|
106
|
+
return interaction.reply({ content: "Pong!" });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## How it works
|
|
112
|
+
|
|
113
|
+
`@wolfstar/http-framework` routes subcommands to **methods on the parent** command instance. This plugin:
|
|
114
|
+
|
|
115
|
+
1. Lets child command classes register themselves into in-memory registries (by parent name).
|
|
116
|
+
2. After all command pieces are constructed, rebuilds the parent’s chat-input resolver and `CommandRouter`, installing thin delegate methods that call each child’s `chatInputRun`.
|
|
117
|
+
|
|
118
|
+
You do not need to call the optional `hooks.subcommands` / `hooks.groups` helpers unless you are registering the parent imperatively and want to attach builders yourself.
|
|
119
|
+
|
|
120
|
+
## Notes
|
|
121
|
+
|
|
122
|
+
- HTTP-only: there is no message-command support (unlike the Sapphire original).
|
|
123
|
+
- Child classes should **not** use `@RegisterCommand` — only the parent registers the top-level slash command.
|
|
124
|
+
- Subcommand groups must still be declared on the parent (via `@RegisterCommand` builder or `registerApplicationCommands`).
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { Command, CommandLoaderStrategy, CommandStore, container } from "@wolfstar/http-framework";
|
|
2
|
+
import { SlashCommandBuilder, SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
|
3
|
+
import { Collection } from "@discordjs/collection";
|
|
4
|
+
import { APIApplicationCommandSubcommandOption } from "discord-api-types/v10";
|
|
5
|
+
//#region src/lib/utils/types.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Resolvable slash-subcommand payload accepted by the plugin.
|
|
8
|
+
*/
|
|
9
|
+
type SlashSubcommandResolvable = SlashCommandSubcommandBuilder | {
|
|
10
|
+
toJSON(): Pick<APIApplicationCommandSubcommandOption, "name" | "description">;
|
|
11
|
+
} | Pick<APIApplicationCommandSubcommandOption, "name" | "description"> | ((builder: SlashCommandSubcommandBuilder, Container: typeof container) => SlashCommandSubcommandBuilder | void);
|
|
12
|
+
/**
|
|
13
|
+
* Options to register a command class as a subcommand of a parent command.
|
|
14
|
+
*/
|
|
15
|
+
interface RegisterSubCommandOptions {
|
|
16
|
+
/**
|
|
17
|
+
* The chat-input name of the parent command (the name passed to {@link RegisterCommand}).
|
|
18
|
+
*/
|
|
19
|
+
parentCommandName: string;
|
|
20
|
+
/**
|
|
21
|
+
* Slash subcommand data (builder, JSON, or callback). Required for Discord registration.
|
|
22
|
+
*/
|
|
23
|
+
slashSubcommand: SlashSubcommandResolvable;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Options to register a command class as a subcommand inside a parent subcommand group.
|
|
27
|
+
*/
|
|
28
|
+
interface RegisterSubCommandGroupOptions {
|
|
29
|
+
/**
|
|
30
|
+
* The chat-input name of the parent command.
|
|
31
|
+
*/
|
|
32
|
+
parentCommandName: string;
|
|
33
|
+
/**
|
|
34
|
+
* The name of the subcommand group already registered on the parent.
|
|
35
|
+
*/
|
|
36
|
+
groupName: string;
|
|
37
|
+
/**
|
|
38
|
+
* Slash subcommand data (builder, JSON, or callback). Required for Discord registration.
|
|
39
|
+
*/
|
|
40
|
+
slashSubcommand: SlashSubcommandResolvable;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Extra {@link Command} options accepted by the advanced subcommands {@link Command} class.
|
|
44
|
+
*/
|
|
45
|
+
interface SubcommandCommandOptions {
|
|
46
|
+
registerSubCommand?: RegisterSubCommandOptions;
|
|
47
|
+
registerSubcommandInGroup?: RegisterSubCommandGroupOptions;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Entry stored in the subcommand / group registries.
|
|
51
|
+
*/
|
|
52
|
+
interface SubcommandMappingCollection {
|
|
53
|
+
slashCommand: SlashCommandSubcommandBuilder;
|
|
54
|
+
commandPiece: Command;
|
|
55
|
+
methodName: string;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Plugin options under `ClientOptions.subcommandsAdvanced`.
|
|
59
|
+
*/
|
|
60
|
+
interface PluginSubcommandOptions {
|
|
61
|
+
/**
|
|
62
|
+
* Auto-generate piece names as `parent/sub` or `parent/group/sub` so multiple
|
|
63
|
+
* subcommand classes do not collide in `@sapphire/pieces`.
|
|
64
|
+
*
|
|
65
|
+
* @default false
|
|
66
|
+
*/
|
|
67
|
+
nameCommandsAutogenerated?: boolean;
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/lib/structures/command.d.ts
|
|
71
|
+
type AdvancedCommandOptions = Command.Options & SubcommandCommandOptions;
|
|
72
|
+
/**
|
|
73
|
+
* Command class that can register itself as a modular subcommand (or grouped subcommand)
|
|
74
|
+
* of a parent {@link Subcommand} / chat-input command.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* import { Command } from '@wolfstar/plugin-subcommands-advanced';
|
|
79
|
+
*
|
|
80
|
+
* export class PingCommand extends Command {
|
|
81
|
+
* public constructor(context: Command.LoaderContext, options: Command.Options) {
|
|
82
|
+
* super(context, {
|
|
83
|
+
* ...options,
|
|
84
|
+
* registerSubCommand: {
|
|
85
|
+
* parentCommandName: 'utils',
|
|
86
|
+
* slashSubcommand: (builder) => builder.setName('ping').setDescription('Ping!')
|
|
87
|
+
* }
|
|
88
|
+
* });
|
|
89
|
+
* }
|
|
90
|
+
*
|
|
91
|
+
* public override chatInputRun(interaction: Command.ChatInputInteraction) {
|
|
92
|
+
* return interaction.reply({ content: 'Pong!' });
|
|
93
|
+
* }
|
|
94
|
+
* }
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
declare class Command$1<Options extends AdvancedCommandOptions = AdvancedCommandOptions> extends Command<Options> {
|
|
98
|
+
constructor(context: Command.LoaderContext, options?: Options);
|
|
99
|
+
}
|
|
100
|
+
declare namespace Command$1 {
|
|
101
|
+
type Options = AdvancedCommandOptions;
|
|
102
|
+
type JSON = Command.JSON;
|
|
103
|
+
/** @deprecated Use {@linkcode LoaderContext} instead. */
|
|
104
|
+
type Context = LoaderContext;
|
|
105
|
+
type LoaderContext = Command.LoaderContext;
|
|
106
|
+
type ChatInputInteraction = Command.ChatInputInteraction;
|
|
107
|
+
type AutocompleteInteraction = Command.AutocompleteInteraction;
|
|
108
|
+
type ApplicationCommandInteraction = Command.ApplicationCommandInteraction;
|
|
109
|
+
type Registry = Command.Registry;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Parent command marker. Extend this for the chat-input command that owns modular
|
|
113
|
+
* subcommands. Wiring of children is performed automatically by the plugin loader
|
|
114
|
+
* strategy after all pieces are constructed.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* import { RegisterCommand } from '@wolfstar/http-framework';
|
|
119
|
+
* import { Subcommand } from '@wolfstar/plugin-subcommands-advanced';
|
|
120
|
+
*
|
|
121
|
+
* @RegisterCommand((builder) =>
|
|
122
|
+
* builder
|
|
123
|
+
* .setName('utils')
|
|
124
|
+
* .setDescription('Utility commands')
|
|
125
|
+
* .addSubcommandGroup((group) => group.setName('poll').setDescription('Polls'))
|
|
126
|
+
* )
|
|
127
|
+
* export class UtilsCommand extends Subcommand {}
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
declare class Subcommand<Options extends Command.Options = Command.Options> extends Command<Options> {
|
|
131
|
+
/**
|
|
132
|
+
* Optional hooks for imperative {@link registerApplicationCommands} usage.
|
|
133
|
+
*/
|
|
134
|
+
readonly hooks: {
|
|
135
|
+
subcommands(piece: Command, context?: import("@discordjs/builders").SlashCommandBuilder): void;
|
|
136
|
+
groups(piece: Command, context?: import("@discordjs/builders").SlashCommandBuilder): void;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
declare namespace Subcommand {
|
|
140
|
+
type Options = Command.Options;
|
|
141
|
+
type JSON = Command.JSON;
|
|
142
|
+
/** @deprecated Use {@linkcode LoaderContext} instead. */
|
|
143
|
+
type Context = LoaderContext;
|
|
144
|
+
type LoaderContext = Command.LoaderContext;
|
|
145
|
+
type ChatInputInteraction = Command.ChatInputInteraction;
|
|
146
|
+
type AutocompleteInteraction = Command.AutocompleteInteraction;
|
|
147
|
+
type ApplicationCommandInteraction = Command.ApplicationCommandInteraction;
|
|
148
|
+
type Registry = Command.Registry;
|
|
149
|
+
}
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region src/lib/utils/decorators.d.ts
|
|
152
|
+
type CommandConstructor = new (...args: any[]) => Command;
|
|
153
|
+
/**
|
|
154
|
+
* Class decorator that registers the decorated command as a direct subcommand of `parentCommandName`.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* import { Command, RegisterAsSubcommand } from '@wolfstar/plugin-subcommands-advanced';
|
|
159
|
+
*
|
|
160
|
+
* @RegisterAsSubcommand('utils', (builder) => builder.setName('ping').setDescription('Ping!'))
|
|
161
|
+
* export class PingCommand extends Command {
|
|
162
|
+
* public override chatInputRun(interaction: Command.ChatInputInteraction) {
|
|
163
|
+
* return interaction.reply({ content: 'Pong!' });
|
|
164
|
+
* }
|
|
165
|
+
* }
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
declare function RegisterAsSubcommand(parentCommandName: string, slashSubcommand: SlashSubcommandResolvable): <T extends CommandConstructor>(target: T) => T;
|
|
169
|
+
/**
|
|
170
|
+
* Class decorator that registers the decorated command as a subcommand inside a group.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* import { Command, RegisterAsSubcommandGroup } from '@wolfstar/plugin-subcommands-advanced';
|
|
175
|
+
*
|
|
176
|
+
* @RegisterAsSubcommandGroup('utils', 'poll', (builder) =>
|
|
177
|
+
* builder.setName('create').setDescription('Create a poll')
|
|
178
|
+
* )
|
|
179
|
+
* export class PollCreateCommand extends Command {
|
|
180
|
+
* public override chatInputRun(interaction: Command.ChatInputInteraction) {
|
|
181
|
+
* return interaction.reply({ content: 'Created!' });
|
|
182
|
+
* }
|
|
183
|
+
* }
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
declare function RegisterAsSubcommandGroup(parentCommandName: string, groupName: string, slashSubcommand: SlashSubcommandResolvable): <T extends CommandConstructor>(target: T) => T;
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region src/lib/utils/functions.d.ts
|
|
189
|
+
/**
|
|
190
|
+
* Registry of direct subcommands keyed by parent command name, then subcommand name.
|
|
191
|
+
*/
|
|
192
|
+
declare const subCommandsRegistry: Collection<string, Collection<string, SubcommandMappingCollection>>;
|
|
193
|
+
/**
|
|
194
|
+
* Registry of grouped subcommands keyed by parent → group → subcommand name.
|
|
195
|
+
*/
|
|
196
|
+
declare const subCommandsGroupRegistry: Collection<string, Collection<string, Collection<string, SubcommandMappingCollection>>>;
|
|
197
|
+
/**
|
|
198
|
+
* Normalize slash subcommand input into a builder.
|
|
199
|
+
*/
|
|
200
|
+
declare function parseSlashSubcommand(subcommand: SlashSubcommandResolvable): SlashCommandSubcommandBuilder;
|
|
201
|
+
/**
|
|
202
|
+
* Stable method name linked on the parent command for a direct subcommand.
|
|
203
|
+
*/
|
|
204
|
+
declare function subcommandMethodName(subcommandName: string): string;
|
|
205
|
+
/**
|
|
206
|
+
* Stable method name linked on the parent command for a grouped subcommand.
|
|
207
|
+
*/
|
|
208
|
+
declare function subcommandGroupMethodName(groupName: string, subcommandName: string): string;
|
|
209
|
+
/**
|
|
210
|
+
* Register a command piece as a direct subcommand of `parentCommandName`.
|
|
211
|
+
*/
|
|
212
|
+
declare function analyzeSubCommandParsed(piece: Command, parentCommandName: string, subcommand: SlashSubcommandResolvable): Command;
|
|
213
|
+
/**
|
|
214
|
+
* Register a command piece as a subcommand inside a group of `parentCommandName`.
|
|
215
|
+
*/
|
|
216
|
+
declare function analyzeSubcommandGroupParsed(piece: Command, parentCommandName: string, groupName: string, subcommand: SlashSubcommandResolvable): Command;
|
|
217
|
+
//#endregion
|
|
218
|
+
//#region src/lib/utils/hooks.d.ts
|
|
219
|
+
/**
|
|
220
|
+
* Optional hooks for parent commands that register chat-input commands imperatively
|
|
221
|
+
* via {@link Command.registerApplicationCommands}. Prefer relying on the automatic
|
|
222
|
+
* wiring performed by {@link SubcommandsAdvancedLoaderStrategy}; these helpers are
|
|
223
|
+
* useful when you want to inspect or manually attach builders during registration.
|
|
224
|
+
*/
|
|
225
|
+
declare const RegisterSubcommandsHooks: {
|
|
226
|
+
/**
|
|
227
|
+
* Attach registered direct subcommands onto a {@link SlashCommandBuilder}.
|
|
228
|
+
*/
|
|
229
|
+
subcommands(piece: Command, context?: SlashCommandBuilder): void;
|
|
230
|
+
/**
|
|
231
|
+
* Attach registered grouped subcommands onto matching groups on a {@link SlashCommandBuilder}.
|
|
232
|
+
*/
|
|
233
|
+
groups(piece: Command, context?: SlashCommandBuilder): void;
|
|
234
|
+
};
|
|
235
|
+
//#endregion
|
|
236
|
+
//#region src/lib/utils/strategy.d.ts
|
|
237
|
+
/**
|
|
238
|
+
* Loader strategy that wires modular subcommands onto parent commands before
|
|
239
|
+
* chat-input mappings are published to {@link CommandStore.router}.
|
|
240
|
+
*
|
|
241
|
+
* {@link CommandStore.loadAll} constructs every piece first (children populate the
|
|
242
|
+
* registries), then inserts them — {@link onLoad} therefore sees a complete registry.
|
|
243
|
+
*/
|
|
244
|
+
declare class SubcommandsAdvancedLoaderStrategy extends CommandLoaderStrategy {
|
|
245
|
+
onLoad(store: CommandStore, piece: Command): Command<import("@sapphire/pieces").PieceOptions>;
|
|
246
|
+
}
|
|
247
|
+
//#endregion
|
|
248
|
+
//#region src/lib/utils/wiring.d.ts
|
|
249
|
+
/**
|
|
250
|
+
* Whether this piece is a parent that has registered modular subcommands.
|
|
251
|
+
*/
|
|
252
|
+
declare function hasRegisteredSubcommands(parentName: string): boolean;
|
|
253
|
+
/**
|
|
254
|
+
* Install delegate methods on the parent and rebuild its chat-input resolver + router
|
|
255
|
+
* so modular child command classes handle each subcommand.
|
|
256
|
+
*
|
|
257
|
+
* Must run after every command piece has been constructed (e.g. from
|
|
258
|
+
* {@link CommandLoaderStrategy.onLoad}), so the registries contain every child.
|
|
259
|
+
*
|
|
260
|
+
* Delegates are installed on the parent **prototype** so reconstructed instances
|
|
261
|
+
* (Store `loadAll` rebuilds pieces) still satisfy {@link CommandRouter}'s method checks.
|
|
262
|
+
*/
|
|
263
|
+
declare function wireParentSubcommands(parent: Command): void;
|
|
264
|
+
/**
|
|
265
|
+
* Reset subcommand registries (useful between tests).
|
|
266
|
+
*/
|
|
267
|
+
declare function clearSubcommandRegistries(): void;
|
|
268
|
+
//#endregion
|
|
269
|
+
//#region src/index.d.ts
|
|
270
|
+
declare module "@wolfstar/http-framework" {
|
|
271
|
+
interface ClientOptions {
|
|
272
|
+
/**
|
|
273
|
+
* Options for `@wolfstar/plugin-subcommands-advanced`.
|
|
274
|
+
*/
|
|
275
|
+
subcommandsAdvanced?: PluginSubcommandOptions;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
//#endregion
|
|
279
|
+
export { SubcommandMappingCollection as S, PluginSubcommandOptions as _, RegisterSubcommandsHooks as a, SlashSubcommandResolvable as b, parseSlashSubcommand as c, subcommandGroupMethodName as d, subcommandMethodName as f, Subcommand as g, Command$1 as h, SubcommandsAdvancedLoaderStrategy as i, subCommandsGroupRegistry as l, RegisterAsSubcommandGroup as m, hasRegisteredSubcommands as n, analyzeSubCommandParsed as o, RegisterAsSubcommand as p, wireParentSubcommands as r, analyzeSubcommandGroupParsed as s, clearSubcommandRegistries as t, subCommandsRegistry as u, RegisterSubCommandGroupOptions as v, SubcommandCommandOptions as x, RegisterSubCommandOptions as y };
|
|
280
|
+
//# sourceMappingURL=index-BuJfV_kf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-BuJfV_kf.d.ts","names":[],"sources":["../../src/lib/utils/types.ts","../../src/lib/structures/command.ts","../../src/lib/utils/decorators.ts","../../src/lib/utils/functions.ts","../../src/lib/utils/hooks.ts","../../src/lib/utils/strategy.ts","../../src/lib/utils/wiring.ts","../../src/index.ts"],"mappings":";;;;;;;;KAOY,4BACR;EACE,UAAU,KAAK;IACjB,KAAK,mEAEH,SAAS,+BACT,kBAAkB,cACf;;;;UAKQ;;;;EAIf;;;;EAIA,iBAAiB;;;;;UA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,OAAA,OAAA,SAAO,UAAY;;;;;;;;;;;cCvBtB,0CAA0C;EACrC,OAAO,OAAO,cAAc,OAAO,UAAO,mCAAA;;;;;;;iBCG5C,yBAAyB;;;;;;;;;;;iBAczB,sBAAsB,QAAQ;;;;iBAyI9B;;;;YCvIJ;;;;IAIR,sBAAsB"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { S as SubcommandMappingCollection, _ as PluginSubcommandOptions, a as RegisterSubcommandsHooks, b as SlashSubcommandResolvable, c as parseSlashSubcommand, d as subcommandGroupMethodName, f as subcommandMethodName, g as Subcommand, h as Command, i as SubcommandsAdvancedLoaderStrategy, l as subCommandsGroupRegistry, m as RegisterAsSubcommandGroup, n as hasRegisteredSubcommands, o as analyzeSubCommandParsed, p as RegisterAsSubcommand, r as wireParentSubcommands, s as analyzeSubcommandGroupParsed, t as clearSubcommandRegistries, u as subCommandsRegistry, v as RegisterSubCommandGroupOptions, x as SubcommandCommandOptions, y as RegisterSubCommandOptions } from "./index-BuJfV_kf.js";
|
|
2
|
+
export { Command, type PluginSubcommandOptions, RegisterAsSubcommand, RegisterAsSubcommandGroup, type RegisterSubCommandGroupOptions, type RegisterSubCommandOptions, RegisterSubcommandsHooks, type SlashSubcommandResolvable, Subcommand, type SubcommandCommandOptions, type SubcommandMappingCollection, SubcommandsAdvancedLoaderStrategy, analyzeSubCommandParsed, analyzeSubcommandGroupParsed, clearSubcommandRegistries, hasRegisteredSubcommands, parseSlashSubcommand, subCommandsGroupRegistry, subCommandsRegistry, subcommandGroupMethodName, subcommandMethodName, wireParentSubcommands };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as RegisterAsSubcommand, c as Subcommand, d as analyzeSubcommandGroupParsed, f as parseSlashSubcommand, g as subcommandMethodName, h as subcommandGroupMethodName, i as wireParentSubcommands, l as RegisterSubcommandsHooks, m as subCommandsRegistry, n as clearSubcommandRegistries, o as RegisterAsSubcommandGroup, p as subCommandsGroupRegistry, r as hasRegisteredSubcommands, s as Command, t as SubcommandsAdvancedLoaderStrategy, u as analyzeSubCommandParsed } from "./src-JCzq0KZw.js";
|
|
2
|
+
|
|
3
|
+
export { Command, RegisterAsSubcommand, RegisterAsSubcommandGroup, RegisterSubcommandsHooks, Subcommand, SubcommandsAdvancedLoaderStrategy, analyzeSubCommandParsed, analyzeSubcommandGroupParsed, clearSubcommandRegistries, hasRegisteredSubcommands, parseSlashSubcommand, subCommandsGroupRegistry, subCommandsRegistry, subcommandGroupMethodName, subcommandMethodName, wireParentSubcommands };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import "./index-BuJfV_kf.js";
|
|
2
|
+
import { Client, ClientOptions, Plugin, postInitialization } from "@wolfstar/http-framework";
|
|
3
|
+
//#region src/register.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Installs the advanced subcommands loader strategy so modular child command
|
|
6
|
+
* classes are wired onto their parent chat-input commands after load.
|
|
7
|
+
*
|
|
8
|
+
* Activate by importing the side-effecting entrypoint before creating the client:
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import '@wolfstar/plugin-subcommands-advanced/register';
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
declare class SubcommandsAdvancedPlugin extends Plugin {
|
|
15
|
+
static [postInitialization](this: Client, _options: ClientOptions): void;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { SubcommandsAdvancedPlugin };
|
|
19
|
+
//# sourceMappingURL=register.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.d.ts","names":[],"sources":["../../src/register.ts"],"mappings":";;;;;;;;;;;;;cAqBa,kCAAkC;UAC9B,oBAAoB,MAAM,QAAQ,UAAU"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { t as SubcommandsAdvancedLoaderStrategy } from "./src-JCzq0KZw.js";
|
|
2
|
+
import { Client, Plugin, container, postInitialization } from "@wolfstar/http-framework";
|
|
3
|
+
|
|
4
|
+
//#region src/register.ts
|
|
5
|
+
/**
|
|
6
|
+
* Installs the advanced subcommands loader strategy so modular child command
|
|
7
|
+
* classes are wired onto their parent chat-input commands after load.
|
|
8
|
+
*
|
|
9
|
+
* Activate by importing the side-effecting entrypoint before creating the client:
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import '@wolfstar/plugin-subcommands-advanced/register';
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
var SubcommandsAdvancedPlugin = class extends Plugin {
|
|
16
|
+
static [postInitialization](_options) {
|
|
17
|
+
const store = container.stores.get("commands");
|
|
18
|
+
Object.defineProperty(store, "strategy", {
|
|
19
|
+
value: new SubcommandsAdvancedLoaderStrategy(),
|
|
20
|
+
configurable: true,
|
|
21
|
+
enumerable: true,
|
|
22
|
+
writable: true
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
Client.plugins.registerPostInitializationHook(SubcommandsAdvancedPlugin[postInitialization], "WolfStar-SubcommandsAdvanced-PostInitialization");
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { SubcommandsAdvancedPlugin };
|
|
30
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.js","names":[],"sources":["../../src/register.ts"],"sourcesContent":["import {\n Client,\n container,\n Plugin,\n postInitialization,\n type ClientOptions,\n type CommandStore,\n} from \"@wolfstar/http-framework\";\nimport \"./index.js\";\nimport { SubcommandsAdvancedLoaderStrategy } from \"./lib/utils/strategy.js\";\n\n/**\n * Installs the advanced subcommands loader strategy so modular child command\n * classes are wired onto their parent chat-input commands after load.\n *\n * Activate by importing the side-effecting entrypoint before creating the client:\n *\n * ```ts\n * import '@wolfstar/plugin-subcommands-advanced/register';\n * ```\n */\nexport class SubcommandsAdvancedPlugin extends Plugin {\n public static [postInitialization](this: Client, _options: ClientOptions): void {\n const store = container.stores.get(\"commands\") as CommandStore;\n Object.defineProperty(store, \"strategy\", {\n value: new SubcommandsAdvancedLoaderStrategy(),\n configurable: true,\n enumerable: true,\n writable: true,\n });\n }\n}\n\nClient.plugins.registerPostInitializationHook(\n SubcommandsAdvancedPlugin[postInitialization]!,\n \"WolfStar-SubcommandsAdvanced-PostInitialization\",\n);\n"],"mappings":";;;;;;;;;;;;;;AAqBA,IAAa,4BAAb,cAA+C,OAAO;CACpD,QAAe,oBAAkC,UAA+B;EAC9E,MAAM,QAAQ,UAAU,OAAO,IAAI,UAAU;EAC7C,OAAO,eAAe,OAAO,YAAY;GACvC,OAAO,IAAI,kCAAkC;GAC7C,cAAc;GACd,YAAY;GACZ,UAAU;EACZ,CAAC;CACH;AACF;AAEA,OAAO,QAAQ,+BACb,0BAA0B,qBAC1B,iDACF"}
|
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import { Command, CommandLoaderStrategy, CommandRouter, applicationCommandRegistry, container } from "@wolfstar/http-framework";
|
|
2
|
+
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
|
3
|
+
import { Collection } from "@discordjs/collection";
|
|
4
|
+
import { ApplicationCommandOptionType } from "discord-api-types/v10";
|
|
5
|
+
|
|
6
|
+
//#region src/lib/utils/functions.ts
|
|
7
|
+
/**
|
|
8
|
+
* Registry of direct subcommands keyed by parent command name, then subcommand name.
|
|
9
|
+
*/
|
|
10
|
+
const subCommandsRegistry = new Collection();
|
|
11
|
+
/**
|
|
12
|
+
* Registry of grouped subcommands keyed by parent → group → subcommand name.
|
|
13
|
+
*/
|
|
14
|
+
const subCommandsGroupRegistry = new Collection();
|
|
15
|
+
/**
|
|
16
|
+
* Normalize slash subcommand input into a builder.
|
|
17
|
+
*/
|
|
18
|
+
function parseSlashSubcommand(subcommand) {
|
|
19
|
+
if (typeof subcommand === "function") {
|
|
20
|
+
const builder = new SlashCommandSubcommandBuilder();
|
|
21
|
+
return subcommand(builder, container) ?? builder;
|
|
22
|
+
}
|
|
23
|
+
if (subcommand instanceof SlashCommandSubcommandBuilder) return subcommand;
|
|
24
|
+
if (typeof subcommand === "object" && subcommand !== null && "toJSON" in subcommand && typeof subcommand.toJSON === "function") {
|
|
25
|
+
const json = subcommand.toJSON();
|
|
26
|
+
return new SlashCommandSubcommandBuilder().setName(json.name).setDescription(json.description);
|
|
27
|
+
}
|
|
28
|
+
const data = subcommand;
|
|
29
|
+
return new SlashCommandSubcommandBuilder().setName(data.name).setDescription(data.description);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Stable method name linked on the parent command for a direct subcommand.
|
|
33
|
+
*/
|
|
34
|
+
function subcommandMethodName(subcommandName) {
|
|
35
|
+
return `__wolfstar_sc_${subcommandName}`;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Stable method name linked on the parent command for a grouped subcommand.
|
|
39
|
+
*/
|
|
40
|
+
function subcommandGroupMethodName(groupName, subcommandName) {
|
|
41
|
+
return `__wolfstar_sc_${groupName}_${subcommandName}`;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Register a command piece as a direct subcommand of `parentCommandName`.
|
|
45
|
+
*/
|
|
46
|
+
function analyzeSubCommandParsed(piece, parentCommandName, subcommand) {
|
|
47
|
+
const subcommandParsed = parseSlashSubcommand(subcommand);
|
|
48
|
+
const subcommandName = subcommandParsed.name;
|
|
49
|
+
const entry = {
|
|
50
|
+
slashCommand: subcommandParsed,
|
|
51
|
+
commandPiece: piece,
|
|
52
|
+
methodName: subcommandMethodName(subcommandName)
|
|
53
|
+
};
|
|
54
|
+
subCommandsRegistry.ensure(parentCommandName, () => new Collection()).set(subcommandName, entry);
|
|
55
|
+
return piece;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Register a command piece as a subcommand inside a group of `parentCommandName`.
|
|
59
|
+
*/
|
|
60
|
+
function analyzeSubcommandGroupParsed(piece, parentCommandName, groupName, subcommand) {
|
|
61
|
+
const subcommandParsed = parseSlashSubcommand(subcommand);
|
|
62
|
+
const subcommandName = subcommandParsed.name;
|
|
63
|
+
const entry = {
|
|
64
|
+
slashCommand: subcommandParsed,
|
|
65
|
+
commandPiece: piece,
|
|
66
|
+
methodName: subcommandGroupMethodName(groupName, subcommandName)
|
|
67
|
+
};
|
|
68
|
+
subCommandsGroupRegistry.ensure(parentCommandName, () => new Collection()).ensure(groupName, () => new Collection()).set(subcommandName, entry);
|
|
69
|
+
return piece;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/lib/utils/hooks.ts
|
|
74
|
+
/**
|
|
75
|
+
* Optional hooks for parent commands that register chat-input commands imperatively
|
|
76
|
+
* via {@link Command.registerApplicationCommands}. Prefer relying on the automatic
|
|
77
|
+
* wiring performed by {@link SubcommandsAdvancedLoaderStrategy}; these helpers are
|
|
78
|
+
* useful when you want to inspect or manually attach builders during registration.
|
|
79
|
+
*/
|
|
80
|
+
const RegisterSubcommandsHooks = {
|
|
81
|
+
/**
|
|
82
|
+
* Attach registered direct subcommands onto a {@link SlashCommandBuilder}.
|
|
83
|
+
*/
|
|
84
|
+
subcommands(piece, context) {
|
|
85
|
+
const subcommands = subCommandsRegistry.get(piece.router.chatInputName ?? piece.name);
|
|
86
|
+
if (!subcommands) {
|
|
87
|
+
console.warn(`[plugin-subcommands-advanced]: No direct subcommands registered for parent "${piece.router.chatInputName ?? piece.name}".`);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (!context) return;
|
|
91
|
+
for (const { slashCommand } of subcommands.values()) context.addSubcommand(slashCommand);
|
|
92
|
+
},
|
|
93
|
+
/**
|
|
94
|
+
* Attach registered grouped subcommands onto matching groups on a {@link SlashCommandBuilder}.
|
|
95
|
+
*/
|
|
96
|
+
groups(piece, context) {
|
|
97
|
+
const groups = subCommandsGroupRegistry.get(piece.router.chatInputName ?? piece.name);
|
|
98
|
+
if (!groups) {
|
|
99
|
+
console.warn(`[plugin-subcommands-advanced]: No subcommand groups registered for parent "${piece.router.chatInputName ?? piece.name}".`);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (!context) return;
|
|
103
|
+
for (const [groupName, commands] of groups) {
|
|
104
|
+
const group = context.options.find((option) => {
|
|
105
|
+
const data = "toJSON" in option && typeof option.toJSON === "function" ? option.toJSON() : null;
|
|
106
|
+
return data && typeof data === "object" && "name" in data && data.name === groupName;
|
|
107
|
+
});
|
|
108
|
+
if (!group?.addSubcommand) continue;
|
|
109
|
+
for (const { slashCommand } of commands.values()) group.addSubcommand(slashCommand);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region src/lib/structures/command.ts
|
|
116
|
+
/**
|
|
117
|
+
* Command class that can register itself as a modular subcommand (or grouped subcommand)
|
|
118
|
+
* of a parent {@link Subcommand} / chat-input command.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* import { Command } from '@wolfstar/plugin-subcommands-advanced';
|
|
123
|
+
*
|
|
124
|
+
* export class PingCommand extends Command {
|
|
125
|
+
* public constructor(context: Command.LoaderContext, options: Command.Options) {
|
|
126
|
+
* super(context, {
|
|
127
|
+
* ...options,
|
|
128
|
+
* registerSubCommand: {
|
|
129
|
+
* parentCommandName: 'utils',
|
|
130
|
+
* slashSubcommand: (builder) => builder.setName('ping').setDescription('Ping!')
|
|
131
|
+
* }
|
|
132
|
+
* });
|
|
133
|
+
* }
|
|
134
|
+
*
|
|
135
|
+
* public override chatInputRun(interaction: Command.ChatInputInteraction) {
|
|
136
|
+
* return interaction.reply({ content: 'Pong!' });
|
|
137
|
+
* }
|
|
138
|
+
* }
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
var Command$1 = class extends Command {
|
|
142
|
+
constructor(context, options = {}) {
|
|
143
|
+
const nameCommandsAutogenerated = container.client?.options.subcommandsAdvanced?.nameCommandsAutogenerated === true;
|
|
144
|
+
let name = options.name;
|
|
145
|
+
if (options.registerSubCommand && nameCommandsAutogenerated) {
|
|
146
|
+
const parsed = parseSlashSubcommand(options.registerSubCommand.slashSubcommand);
|
|
147
|
+
name = `${options.registerSubCommand.parentCommandName}/${parsed.name}`;
|
|
148
|
+
}
|
|
149
|
+
if (options.registerSubcommandInGroup && nameCommandsAutogenerated) {
|
|
150
|
+
const parsed = parseSlashSubcommand(options.registerSubcommandInGroup.slashSubcommand);
|
|
151
|
+
name = `${options.registerSubcommandInGroup.parentCommandName}/${options.registerSubcommandInGroup.groupName}/${parsed.name}`;
|
|
152
|
+
}
|
|
153
|
+
super(context, {
|
|
154
|
+
...options,
|
|
155
|
+
name
|
|
156
|
+
});
|
|
157
|
+
if (this.options.registerSubCommand) {
|
|
158
|
+
const { parentCommandName, slashSubcommand } = this.options.registerSubCommand;
|
|
159
|
+
analyzeSubCommandParsed(this, parentCommandName, slashSubcommand);
|
|
160
|
+
}
|
|
161
|
+
if (this.options.registerSubcommandInGroup) {
|
|
162
|
+
const { parentCommandName, groupName, slashSubcommand } = this.options.registerSubcommandInGroup;
|
|
163
|
+
analyzeSubcommandGroupParsed(this, parentCommandName, groupName, slashSubcommand);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* Parent command marker. Extend this for the chat-input command that owns modular
|
|
169
|
+
* subcommands. Wiring of children is performed automatically by the plugin loader
|
|
170
|
+
* strategy after all pieces are constructed.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* import { RegisterCommand } from '@wolfstar/http-framework';
|
|
175
|
+
* import { Subcommand } from '@wolfstar/plugin-subcommands-advanced';
|
|
176
|
+
*
|
|
177
|
+
* @RegisterCommand((builder) =>
|
|
178
|
+
* builder
|
|
179
|
+
* .setName('utils')
|
|
180
|
+
* .setDescription('Utility commands')
|
|
181
|
+
* .addSubcommandGroup((group) => group.setName('poll').setDescription('Polls'))
|
|
182
|
+
* )
|
|
183
|
+
* export class UtilsCommand extends Subcommand {}
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
var Subcommand = class extends Command {
|
|
187
|
+
/**
|
|
188
|
+
* Optional hooks for imperative {@link registerApplicationCommands} usage.
|
|
189
|
+
*/
|
|
190
|
+
hooks = RegisterSubcommandsHooks;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
//#endregion
|
|
194
|
+
//#region src/lib/utils/decorators.ts
|
|
195
|
+
/**
|
|
196
|
+
* Class decorator that registers the decorated command as a direct subcommand of `parentCommandName`.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* import { Command, RegisterAsSubcommand } from '@wolfstar/plugin-subcommands-advanced';
|
|
201
|
+
*
|
|
202
|
+
* @RegisterAsSubcommand('utils', (builder) => builder.setName('ping').setDescription('Ping!'))
|
|
203
|
+
* export class PingCommand extends Command {
|
|
204
|
+
* public override chatInputRun(interaction: Command.ChatInputInteraction) {
|
|
205
|
+
* return interaction.reply({ content: 'Pong!' });
|
|
206
|
+
* }
|
|
207
|
+
* }
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
function RegisterAsSubcommand(parentCommandName, slashSubcommand) {
|
|
211
|
+
return function decorate(target) {
|
|
212
|
+
return class extends target {
|
|
213
|
+
constructor(...args) {
|
|
214
|
+
const [context, baseOptions = {}] = args;
|
|
215
|
+
const parsed = parseSlashSubcommand(slashSubcommand);
|
|
216
|
+
const name = container.client?.options.subcommandsAdvanced?.nameCommandsAutogenerated === true ? `${parentCommandName}/${parsed.name}` : baseOptions.name;
|
|
217
|
+
super(context, {
|
|
218
|
+
...baseOptions,
|
|
219
|
+
name
|
|
220
|
+
});
|
|
221
|
+
analyzeSubCommandParsed(this, parentCommandName, slashSubcommand);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Class decorator that registers the decorated command as a subcommand inside a group.
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```typescript
|
|
231
|
+
* import { Command, RegisterAsSubcommandGroup } from '@wolfstar/plugin-subcommands-advanced';
|
|
232
|
+
*
|
|
233
|
+
* @RegisterAsSubcommandGroup('utils', 'poll', (builder) =>
|
|
234
|
+
* builder.setName('create').setDescription('Create a poll')
|
|
235
|
+
* )
|
|
236
|
+
* export class PollCreateCommand extends Command {
|
|
237
|
+
* public override chatInputRun(interaction: Command.ChatInputInteraction) {
|
|
238
|
+
* return interaction.reply({ content: 'Created!' });
|
|
239
|
+
* }
|
|
240
|
+
* }
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
function RegisterAsSubcommandGroup(parentCommandName, groupName, slashSubcommand) {
|
|
244
|
+
return function decorate(target) {
|
|
245
|
+
return class extends target {
|
|
246
|
+
constructor(...args) {
|
|
247
|
+
const [context, baseOptions = {}] = args;
|
|
248
|
+
const parsed = parseSlashSubcommand(slashSubcommand);
|
|
249
|
+
const name = container.client?.options.subcommandsAdvanced?.nameCommandsAutogenerated === true ? `${parentCommandName}/${groupName}/${parsed.name}` : baseOptions.name;
|
|
250
|
+
super(context, {
|
|
251
|
+
...baseOptions,
|
|
252
|
+
name
|
|
253
|
+
});
|
|
254
|
+
analyzeSubcommandGroupParsed(this, parentCommandName, groupName, slashSubcommand);
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
//#endregion
|
|
261
|
+
//#region src/lib/utils/wiring.ts
|
|
262
|
+
const wiredParents = /* @__PURE__ */ new WeakSet();
|
|
263
|
+
/**
|
|
264
|
+
* Whether this piece is a parent that has registered modular subcommands.
|
|
265
|
+
*/
|
|
266
|
+
function hasRegisteredSubcommands(parentName) {
|
|
267
|
+
return subCommandsRegistry.has(parentName) || subCommandsGroupRegistry.has(parentName);
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Install delegate methods on the parent and rebuild its chat-input resolver + router
|
|
271
|
+
* so modular child command classes handle each subcommand.
|
|
272
|
+
*
|
|
273
|
+
* Must run after every command piece has been constructed (e.g. from
|
|
274
|
+
* {@link CommandLoaderStrategy.onLoad}), so the registries contain every child.
|
|
275
|
+
*
|
|
276
|
+
* Delegates are installed on the parent **prototype** so reconstructed instances
|
|
277
|
+
* (Store `loadAll` rebuilds pieces) still satisfy {@link CommandRouter}'s method checks.
|
|
278
|
+
*/
|
|
279
|
+
function wireParentSubcommands(parent) {
|
|
280
|
+
const parentName = parent.router.chatInputName;
|
|
281
|
+
if (!parentName || !hasRegisteredSubcommands(parentName)) return;
|
|
282
|
+
if (wiredParents.has(parent)) return;
|
|
283
|
+
const ctor = parent.constructor;
|
|
284
|
+
const chatInput = applicationCommandRegistry.get(ctor)?.chatInput;
|
|
285
|
+
if (!chatInput) {
|
|
286
|
+
console.warn(`[plugin-subcommands-advanced]: Parent command "${parentName}" has no chat-input registration; skipping wiring.`);
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
const snapshot = chatInput.toJSON();
|
|
290
|
+
applicationCommandRegistry.delete(ctor);
|
|
291
|
+
const resolver = applicationCommandRegistry.ensure(ctor).makeChatInput();
|
|
292
|
+
resolver.setCommand(baseCommandData(snapshot));
|
|
293
|
+
for (const option of snapshot.options ?? []) if (option.type === ApplicationCommandOptionType.SubcommandGroup) {
|
|
294
|
+
resolver.addSubcommandGroup(groupDataWithoutSubcommands(option), getLinkedMethod(option));
|
|
295
|
+
for (const subcommand of option.options ?? []) resolver.addSubcommand(subcommand, getLinkedMethod(subcommand), option.name);
|
|
296
|
+
} else if (option.type === ApplicationCommandOptionType.Subcommand) resolver.addSubcommand(option, getLinkedMethod(option));
|
|
297
|
+
const direct = subCommandsRegistry.get(parentName);
|
|
298
|
+
if (direct) for (const entry of direct.values()) {
|
|
299
|
+
installDelegate(ctor, parentName, entry);
|
|
300
|
+
resolver.addSubcommand(entry.slashCommand, entry.methodName);
|
|
301
|
+
}
|
|
302
|
+
const groups = subCommandsGroupRegistry.get(parentName);
|
|
303
|
+
if (groups) for (const [groupName, commands] of groups) for (const entry of commands.values()) {
|
|
304
|
+
installDelegate(ctor, parentName, entry);
|
|
305
|
+
resolver.addSubcommand(entry.slashCommand, entry.methodName, groupName);
|
|
306
|
+
}
|
|
307
|
+
Object.defineProperty(parent, "router", {
|
|
308
|
+
value: new CommandRouter(parent),
|
|
309
|
+
configurable: true,
|
|
310
|
+
enumerable: true,
|
|
311
|
+
writable: false
|
|
312
|
+
});
|
|
313
|
+
wiredParents.add(parent);
|
|
314
|
+
}
|
|
315
|
+
function baseCommandData(snapshot) {
|
|
316
|
+
const { options: _options, ...rest } = snapshot;
|
|
317
|
+
return rest;
|
|
318
|
+
}
|
|
319
|
+
function groupDataWithoutSubcommands(group) {
|
|
320
|
+
const { options: _options, type: _type, ...rest } = group;
|
|
321
|
+
return rest;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* `http-framework` links a subcommand (or group) option to its handler method by
|
|
325
|
+
* defining a non-enumerable symbol property on the resolved option object. The
|
|
326
|
+
* symbol is not exported, so it is recovered here by its description to preserve
|
|
327
|
+
* framework-native subcommand routing when the resolver is rebuilt.
|
|
328
|
+
*/
|
|
329
|
+
const LINKED_METHOD_SYMBOL_DESCRIPTION = "decorated-command.method.link";
|
|
330
|
+
function getLinkedMethod(option) {
|
|
331
|
+
for (const symbol of Object.getOwnPropertySymbols(option)) if (symbol.description === LINKED_METHOD_SYMBOL_DESCRIPTION) return Reflect.get(option, symbol) ?? null;
|
|
332
|
+
return null;
|
|
333
|
+
}
|
|
334
|
+
function installDelegate(parentCtor, parentName, entry) {
|
|
335
|
+
const { methodName } = entry;
|
|
336
|
+
Object.defineProperty(parentCtor.prototype, methodName, {
|
|
337
|
+
configurable: true,
|
|
338
|
+
enumerable: false,
|
|
339
|
+
writable: true,
|
|
340
|
+
value(interaction, args) {
|
|
341
|
+
const resolved = lookupEntry(parentName, methodName);
|
|
342
|
+
if (!resolved) throw new Error(`[plugin-subcommands-advanced]: No child command registered for parent "${parentName}" method "${methodName}".`);
|
|
343
|
+
return resolved.commandPiece.chatInputRun(interaction, args);
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
function lookupEntry(parentName, methodName) {
|
|
348
|
+
const direct = subCommandsRegistry.get(parentName);
|
|
349
|
+
if (direct) {
|
|
350
|
+
for (const entry of direct.values()) if (entry.methodName === methodName) return entry;
|
|
351
|
+
}
|
|
352
|
+
const groups = subCommandsGroupRegistry.get(parentName);
|
|
353
|
+
if (groups) {
|
|
354
|
+
for (const commands of groups.values()) for (const entry of commands.values()) if (entry.methodName === methodName) return entry;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Reset subcommand registries (useful between tests).
|
|
359
|
+
*/
|
|
360
|
+
function clearSubcommandRegistries() {
|
|
361
|
+
subCommandsRegistry.clear();
|
|
362
|
+
subCommandsGroupRegistry.clear();
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
//#endregion
|
|
366
|
+
//#region src/lib/utils/strategy.ts
|
|
367
|
+
/**
|
|
368
|
+
* Loader strategy that wires modular subcommands onto parent commands before
|
|
369
|
+
* chat-input mappings are published to {@link CommandStore.router}.
|
|
370
|
+
*
|
|
371
|
+
* {@link CommandStore.loadAll} constructs every piece first (children populate the
|
|
372
|
+
* registries), then inserts them — {@link onLoad} therefore sees a complete registry.
|
|
373
|
+
*/
|
|
374
|
+
var SubcommandsAdvancedLoaderStrategy = class extends CommandLoaderStrategy {
|
|
375
|
+
onLoad(store, piece) {
|
|
376
|
+
const parentName = piece.router.chatInputName;
|
|
377
|
+
if (parentName && hasRegisteredSubcommands(parentName)) wireParentSubcommands(piece);
|
|
378
|
+
return super.onLoad(store, piece);
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
//#endregion
|
|
383
|
+
export { RegisterAsSubcommand as a, Subcommand as c, analyzeSubcommandGroupParsed as d, parseSlashSubcommand as f, subcommandMethodName as g, subcommandGroupMethodName as h, wireParentSubcommands as i, RegisterSubcommandsHooks as l, subCommandsRegistry as m, clearSubcommandRegistries as n, RegisterAsSubcommandGroup as o, subCommandsGroupRegistry as p, hasRegisteredSubcommands as r, Command$1 as s, SubcommandsAdvancedLoaderStrategy as t, analyzeSubCommandParsed as u };
|
|
384
|
+
//# sourceMappingURL=src-JCzq0KZw.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"src-JCzq0KZw.js","names":["Command","FrameworkCommand"],"sources":["../../src/lib/utils/functions.ts","../../src/lib/utils/hooks.ts","../../src/lib/structures/command.ts","../../src/lib/utils/decorators.ts","../../src/lib/utils/wiring.ts","../../src/lib/utils/strategy.ts"],"sourcesContent":["import { SlashCommandSubcommandBuilder } from \"@discordjs/builders\";\nimport { Collection } from \"@discordjs/collection\";\nimport { container, type Command } from \"@wolfstar/http-framework\";\nimport type { SlashSubcommandResolvable, SubcommandMappingCollection } from \"./types.js\";\n\n/**\n * Registry of direct subcommands keyed by parent command name, then subcommand name.\n */\nexport const subCommandsRegistry: Collection<\n string,\n Collection<string, SubcommandMappingCollection>\n> = new Collection();\n\n/**\n * Registry of grouped subcommands keyed by parent → group → subcommand name.\n */\nexport const subCommandsGroupRegistry: Collection<\n string,\n Collection<string, Collection<string, SubcommandMappingCollection>>\n> = new Collection();\n\n/**\n * Normalize slash subcommand input into a builder.\n */\nexport function parseSlashSubcommand(\n subcommand: SlashSubcommandResolvable,\n): SlashCommandSubcommandBuilder {\n if (typeof subcommand === \"function\") {\n const builder = new SlashCommandSubcommandBuilder();\n return subcommand(builder, container) ?? builder;\n }\n\n if (subcommand instanceof SlashCommandSubcommandBuilder) {\n return subcommand;\n }\n\n if (\n typeof subcommand === \"object\" &&\n subcommand !== null &&\n \"toJSON\" in subcommand &&\n typeof subcommand.toJSON === \"function\"\n ) {\n const json = (subcommand as { toJSON: () => { name: string; description: string } }).toJSON();\n return new SlashCommandSubcommandBuilder().setName(json.name).setDescription(json.description);\n }\n\n const data = subcommand as { name: string; description: string };\n return new SlashCommandSubcommandBuilder().setName(data.name).setDescription(data.description);\n}\n\n/**\n * Stable method name linked on the parent command for a direct subcommand.\n */\nexport function subcommandMethodName(subcommandName: string): string {\n return `__wolfstar_sc_${subcommandName}`;\n}\n\n/**\n * Stable method name linked on the parent command for a grouped subcommand.\n */\nexport function subcommandGroupMethodName(groupName: string, subcommandName: string): string {\n return `__wolfstar_sc_${groupName}_${subcommandName}`;\n}\n\n/**\n * Register a command piece as a direct subcommand of `parentCommandName`.\n */\nexport function analyzeSubCommandParsed(\n piece: Command,\n parentCommandName: string,\n subcommand: SlashSubcommandResolvable,\n): Command {\n const subcommandParsed = parseSlashSubcommand(subcommand);\n const subcommandName = subcommandParsed.name;\n const methodName = subcommandMethodName(subcommandName);\n const entry: SubcommandMappingCollection = {\n slashCommand: subcommandParsed,\n commandPiece: piece,\n methodName,\n };\n\n const registry = subCommandsRegistry.ensure(parentCommandName, () => new Collection());\n registry.set(subcommandName, entry);\n\n return piece;\n}\n\n/**\n * Register a command piece as a subcommand inside a group of `parentCommandName`.\n */\nexport function analyzeSubcommandGroupParsed(\n piece: Command,\n parentCommandName: string,\n groupName: string,\n subcommand: SlashSubcommandResolvable,\n): Command {\n const subcommandParsed = parseSlashSubcommand(subcommand);\n const subcommandName = subcommandParsed.name;\n const methodName = subcommandGroupMethodName(groupName, subcommandName);\n const entry: SubcommandMappingCollection = {\n slashCommand: subcommandParsed,\n commandPiece: piece,\n methodName,\n };\n\n const parentRegistry = subCommandsGroupRegistry.ensure(parentCommandName, () => new Collection());\n const groupRegistry = parentRegistry.ensure(groupName, () => new Collection());\n groupRegistry.set(subcommandName, entry);\n\n return piece;\n}\n","import type { SlashCommandBuilder } from \"@discordjs/builders\";\nimport type { Command } from \"@wolfstar/http-framework\";\nimport { subCommandsGroupRegistry, subCommandsRegistry } from \"./functions.js\";\n\n/**\n * Optional hooks for parent commands that register chat-input commands imperatively\n * via {@link Command.registerApplicationCommands}. Prefer relying on the automatic\n * wiring performed by {@link SubcommandsAdvancedLoaderStrategy}; these helpers are\n * useful when you want to inspect or manually attach builders during registration.\n */\nexport const RegisterSubcommandsHooks = {\n /**\n * Attach registered direct subcommands onto a {@link SlashCommandBuilder}.\n */\n subcommands(piece: Command, context?: SlashCommandBuilder): void {\n const subcommands = subCommandsRegistry.get(piece.router.chatInputName ?? piece.name);\n if (!subcommands) {\n console.warn(\n `[plugin-subcommands-advanced]: No direct subcommands registered for parent \"${piece.router.chatInputName ?? piece.name}\".`,\n );\n return;\n }\n\n if (!context) return;\n\n for (const { slashCommand } of subcommands.values()) {\n context.addSubcommand(slashCommand);\n }\n },\n\n /**\n * Attach registered grouped subcommands onto matching groups on a {@link SlashCommandBuilder}.\n */\n groups(piece: Command, context?: SlashCommandBuilder): void {\n const groups = subCommandsGroupRegistry.get(piece.router.chatInputName ?? piece.name);\n if (!groups) {\n console.warn(\n `[plugin-subcommands-advanced]: No subcommand groups registered for parent \"${piece.router.chatInputName ?? piece.name}\".`,\n );\n return;\n }\n\n if (!context) return;\n\n for (const [groupName, commands] of groups) {\n const group = context.options.find((option) => {\n const data =\n \"toJSON\" in option && typeof option.toJSON === \"function\" ? option.toJSON() : null;\n return data && typeof data === \"object\" && \"name\" in data && data.name === groupName;\n }) as { addSubcommand?(subcommand: unknown): unknown } | undefined;\n\n if (!group?.addSubcommand) continue;\n\n for (const { slashCommand } of commands.values()) {\n group.addSubcommand(slashCommand);\n }\n }\n },\n};\n","import { Command as FrameworkCommand, container } from \"@wolfstar/http-framework\";\nimport {\n analyzeSubCommandParsed,\n analyzeSubcommandGroupParsed,\n parseSlashSubcommand,\n} from \"../utils/functions.js\";\nimport { RegisterSubcommandsHooks } from \"../utils/hooks.js\";\nimport type { SubcommandCommandOptions } from \"../utils/types.js\";\n\nexport type AdvancedCommandOptions = FrameworkCommand.Options & SubcommandCommandOptions;\n\n/**\n * Command class that can register itself as a modular subcommand (or grouped subcommand)\n * of a parent {@link Subcommand} / chat-input command.\n *\n * @example\n * ```typescript\n * import { Command } from '@wolfstar/plugin-subcommands-advanced';\n *\n * export class PingCommand extends Command {\n * public constructor(context: Command.LoaderContext, options: Command.Options) {\n * super(context, {\n * ...options,\n * registerSubCommand: {\n * parentCommandName: 'utils',\n * slashSubcommand: (builder) => builder.setName('ping').setDescription('Ping!')\n * }\n * });\n * }\n *\n * public override chatInputRun(interaction: Command.ChatInputInteraction) {\n * return interaction.reply({ content: 'Pong!' });\n * }\n * }\n * ```\n */\nexport class Command<\n Options extends AdvancedCommandOptions = AdvancedCommandOptions,\n> extends FrameworkCommand<Options> {\n public constructor(context: FrameworkCommand.LoaderContext, options: Options = {} as Options) {\n const nameCommandsAutogenerated =\n container.client?.options.subcommandsAdvanced?.nameCommandsAutogenerated === true;\n let name = options.name;\n\n if (options.registerSubCommand && nameCommandsAutogenerated) {\n const parsed = parseSlashSubcommand(options.registerSubCommand.slashSubcommand);\n name = `${options.registerSubCommand.parentCommandName}/${parsed.name}`;\n }\n\n if (options.registerSubcommandInGroup && nameCommandsAutogenerated) {\n const parsed = parseSlashSubcommand(options.registerSubcommandInGroup.slashSubcommand);\n name = `${options.registerSubcommandInGroup.parentCommandName}/${options.registerSubcommandInGroup.groupName}/${parsed.name}`;\n }\n\n super(context, { ...options, name } as Options);\n\n if (this.options.registerSubCommand) {\n const { parentCommandName, slashSubcommand } = this.options.registerSubCommand;\n analyzeSubCommandParsed(this, parentCommandName, slashSubcommand);\n }\n\n if (this.options.registerSubcommandInGroup) {\n const { parentCommandName, groupName, slashSubcommand } =\n this.options.registerSubcommandInGroup;\n analyzeSubcommandGroupParsed(this, parentCommandName, groupName, slashSubcommand);\n }\n }\n}\n\nexport namespace Command {\n export type Options = AdvancedCommandOptions;\n export type JSON = FrameworkCommand.JSON;\n /** @deprecated Use {@linkcode LoaderContext} instead. */\n export type Context = LoaderContext;\n export type LoaderContext = FrameworkCommand.LoaderContext;\n export type ChatInputInteraction = FrameworkCommand.ChatInputInteraction;\n export type AutocompleteInteraction = FrameworkCommand.AutocompleteInteraction;\n export type ApplicationCommandInteraction = FrameworkCommand.ApplicationCommandInteraction;\n export type Registry = FrameworkCommand.Registry;\n}\n\n/**\n * Parent command marker. Extend this for the chat-input command that owns modular\n * subcommands. Wiring of children is performed automatically by the plugin loader\n * strategy after all pieces are constructed.\n *\n * @example\n * ```typescript\n * import { RegisterCommand } from '@wolfstar/http-framework';\n * import { Subcommand } from '@wolfstar/plugin-subcommands-advanced';\n *\n * @RegisterCommand((builder) =>\n * builder\n * .setName('utils')\n * .setDescription('Utility commands')\n * .addSubcommandGroup((group) => group.setName('poll').setDescription('Polls'))\n * )\n * export class UtilsCommand extends Subcommand {}\n * ```\n */\nexport class Subcommand<\n Options extends FrameworkCommand.Options = FrameworkCommand.Options,\n> extends FrameworkCommand<Options> {\n /**\n * Optional hooks for imperative {@link registerApplicationCommands} usage.\n */\n public readonly hooks = RegisterSubcommandsHooks;\n}\n\nexport namespace Subcommand {\n export type Options = FrameworkCommand.Options;\n export type JSON = FrameworkCommand.JSON;\n /** @deprecated Use {@linkcode LoaderContext} instead. */\n export type Context = LoaderContext;\n export type LoaderContext = FrameworkCommand.LoaderContext;\n export type ChatInputInteraction = FrameworkCommand.ChatInputInteraction;\n export type AutocompleteInteraction = FrameworkCommand.AutocompleteInteraction;\n export type ApplicationCommandInteraction = FrameworkCommand.ApplicationCommandInteraction;\n export type Registry = FrameworkCommand.Registry;\n}\n","import { Command as FrameworkCommand, container } from \"@wolfstar/http-framework\";\nimport {\n analyzeSubCommandParsed,\n analyzeSubcommandGroupParsed,\n parseSlashSubcommand,\n} from \"./functions.js\";\nimport type { SlashSubcommandResolvable } from \"./types.js\";\n\ntype CommandConstructor = new (...args: any[]) => FrameworkCommand;\n\n/**\n * Class decorator that registers the decorated command as a direct subcommand of `parentCommandName`.\n *\n * @example\n * ```typescript\n * import { Command, RegisterAsSubcommand } from '@wolfstar/plugin-subcommands-advanced';\n *\n * @RegisterAsSubcommand('utils', (builder) => builder.setName('ping').setDescription('Ping!'))\n * export class PingCommand extends Command {\n * public override chatInputRun(interaction: Command.ChatInputInteraction) {\n * return interaction.reply({ content: 'Pong!' });\n * }\n * }\n * ```\n */\nexport function RegisterAsSubcommand(\n parentCommandName: string,\n slashSubcommand: SlashSubcommandResolvable,\n) {\n return function decorate<T extends CommandConstructor>(target: T): T {\n return class extends target {\n public constructor(...args: any[]) {\n const [context, baseOptions = {}] = args as [\n FrameworkCommand.LoaderContext,\n FrameworkCommand.Options,\n ];\n const parsed = parseSlashSubcommand(slashSubcommand);\n const name =\n container.client?.options.subcommandsAdvanced?.nameCommandsAutogenerated === true\n ? `${parentCommandName}/${parsed.name}`\n : baseOptions.name;\n\n super(context, { ...baseOptions, name });\n analyzeSubCommandParsed(this, parentCommandName, slashSubcommand);\n }\n } as T;\n };\n}\n\n/**\n * Class decorator that registers the decorated command as a subcommand inside a group.\n *\n * @example\n * ```typescript\n * import { Command, RegisterAsSubcommandGroup } from '@wolfstar/plugin-subcommands-advanced';\n *\n * @RegisterAsSubcommandGroup('utils', 'poll', (builder) =>\n * builder.setName('create').setDescription('Create a poll')\n * )\n * export class PollCreateCommand extends Command {\n * public override chatInputRun(interaction: Command.ChatInputInteraction) {\n * return interaction.reply({ content: 'Created!' });\n * }\n * }\n * ```\n */\nexport function RegisterAsSubcommandGroup(\n parentCommandName: string,\n groupName: string,\n slashSubcommand: SlashSubcommandResolvable,\n) {\n return function decorate<T extends CommandConstructor>(target: T): T {\n return class extends target {\n public constructor(...args: any[]) {\n const [context, baseOptions = {}] = args as [\n FrameworkCommand.LoaderContext,\n FrameworkCommand.Options,\n ];\n const parsed = parseSlashSubcommand(slashSubcommand);\n const name =\n container.client?.options.subcommandsAdvanced?.nameCommandsAutogenerated === true\n ? `${parentCommandName}/${groupName}/${parsed.name}`\n : baseOptions.name;\n\n super(context, { ...baseOptions, name });\n analyzeSubcommandGroupParsed(this, parentCommandName, groupName, slashSubcommand);\n }\n } as T;\n };\n}\n","import { applicationCommandRegistry, CommandRouter, type Command } from \"@wolfstar/http-framework\";\nimport {\n ApplicationCommandOptionType,\n type APIApplicationCommandSubcommandGroupOption,\n type RESTPostAPIChatInputApplicationCommandsJSONBody,\n} from \"discord-api-types/v10\";\nimport { subCommandsGroupRegistry, subCommandsRegistry } from \"./functions.js\";\nimport type { SubcommandMappingCollection } from \"./types.js\";\n\nconst wiredParents = new WeakSet<Command>();\n\n/**\n * Whether this piece is a parent that has registered modular subcommands.\n */\nexport function hasRegisteredSubcommands(parentName: string): boolean {\n return subCommandsRegistry.has(parentName) || subCommandsGroupRegistry.has(parentName);\n}\n\n/**\n * Install delegate methods on the parent and rebuild its chat-input resolver + router\n * so modular child command classes handle each subcommand.\n *\n * Must run after every command piece has been constructed (e.g. from\n * {@link CommandLoaderStrategy.onLoad}), so the registries contain every child.\n *\n * Delegates are installed on the parent **prototype** so reconstructed instances\n * (Store `loadAll` rebuilds pieces) still satisfy {@link CommandRouter}'s method checks.\n */\nexport function wireParentSubcommands(parent: Command): void {\n const parentName = parent.router.chatInputName;\n if (!parentName || !hasRegisteredSubcommands(parentName)) return;\n if (wiredParents.has(parent)) return;\n\n const ctor = parent.constructor as typeof Command;\n const existing = applicationCommandRegistry.get(ctor);\n const chatInput = existing?.chatInput;\n if (!chatInput) {\n console.warn(\n `[plugin-subcommands-advanced]: Parent command \"${parentName}\" has no chat-input registration; skipping wiring.`,\n );\n return;\n }\n\n const snapshot = chatInput.toJSON();\n applicationCommandRegistry.delete(ctor);\n\n const resolver = applicationCommandRegistry.ensure(ctor).makeChatInput();\n resolver.setCommand(baseCommandData(snapshot));\n\n for (const option of snapshot.options ?? []) {\n if (option.type === ApplicationCommandOptionType.SubcommandGroup) {\n resolver.addSubcommandGroup(groupDataWithoutSubcommands(option), getLinkedMethod(option));\n for (const subcommand of option.options ?? []) {\n resolver.addSubcommand(subcommand, getLinkedMethod(subcommand), option.name);\n }\n } else if (option.type === ApplicationCommandOptionType.Subcommand) {\n resolver.addSubcommand(option, getLinkedMethod(option));\n }\n }\n\n const direct = subCommandsRegistry.get(parentName);\n if (direct) {\n for (const entry of direct.values()) {\n installDelegate(ctor, parentName, entry);\n resolver.addSubcommand(entry.slashCommand, entry.methodName);\n }\n }\n\n const groups = subCommandsGroupRegistry.get(parentName);\n if (groups) {\n for (const [groupName, commands] of groups) {\n for (const entry of commands.values()) {\n installDelegate(ctor, parentName, entry);\n resolver.addSubcommand(entry.slashCommand, entry.methodName, groupName);\n }\n }\n }\n\n Object.defineProperty(parent, \"router\", {\n value: new CommandRouter(parent),\n configurable: true,\n enumerable: true,\n writable: false,\n });\n\n wiredParents.add(parent);\n}\n\nfunction baseCommandData(snapshot: RESTPostAPIChatInputApplicationCommandsJSONBody) {\n const { options: _options, ...rest } = snapshot;\n return rest;\n}\n\nfunction groupDataWithoutSubcommands(group: APIApplicationCommandSubcommandGroupOption) {\n const { options: _options, type: _type, ...rest } = group;\n return rest;\n}\n\n/**\n * `http-framework` links a subcommand (or group) option to its handler method by\n * defining a non-enumerable symbol property on the resolved option object. The\n * symbol is not exported, so it is recovered here by its description to preserve\n * framework-native subcommand routing when the resolver is rebuilt.\n */\nconst LINKED_METHOD_SYMBOL_DESCRIPTION = \"decorated-command.method.link\";\n\nfunction getLinkedMethod(option: object): string | null {\n for (const symbol of Object.getOwnPropertySymbols(option)) {\n if (symbol.description === LINKED_METHOD_SYMBOL_DESCRIPTION) {\n return (Reflect.get(option, symbol) as string | undefined) ?? null;\n }\n }\n\n return null;\n}\n\nfunction installDelegate(\n parentCtor: typeof Command,\n parentName: string,\n entry: SubcommandMappingCollection,\n): void {\n const { methodName } = entry;\n\n Object.defineProperty(parentCtor.prototype, methodName, {\n configurable: true,\n enumerable: false,\n writable: true,\n value(this: Command, interaction: Command.ApplicationCommandInteraction, args: object) {\n const resolved = lookupEntry(parentName, methodName);\n if (!resolved) {\n throw new Error(\n `[plugin-subcommands-advanced]: No child command registered for parent \"${parentName}\" method \"${methodName}\".`,\n );\n }\n return resolved.commandPiece.chatInputRun(interaction, args);\n },\n });\n}\n\nfunction lookupEntry(\n parentName: string,\n methodName: string,\n): SubcommandMappingCollection | undefined {\n const direct = subCommandsRegistry.get(parentName);\n if (direct) {\n for (const entry of direct.values()) {\n if (entry.methodName === methodName) return entry;\n }\n }\n\n const groups = subCommandsGroupRegistry.get(parentName);\n if (groups) {\n for (const commands of groups.values()) {\n for (const entry of commands.values()) {\n if (entry.methodName === methodName) return entry;\n }\n }\n }\n\n return undefined;\n}\n\n/**\n * Reset subcommand registries (useful between tests).\n */\nexport function clearSubcommandRegistries(): void {\n subCommandsRegistry.clear();\n subCommandsGroupRegistry.clear();\n}\n","import { CommandLoaderStrategy, type Command, type CommandStore } from \"@wolfstar/http-framework\";\nimport { hasRegisteredSubcommands, wireParentSubcommands } from \"./wiring.js\";\n\n/**\n * Loader strategy that wires modular subcommands onto parent commands before\n * chat-input mappings are published to {@link CommandStore.router}.\n *\n * {@link CommandStore.loadAll} constructs every piece first (children populate the\n * registries), then inserts them — {@link onLoad} therefore sees a complete registry.\n */\nexport class SubcommandsAdvancedLoaderStrategy extends CommandLoaderStrategy {\n public override onLoad(store: CommandStore, piece: Command) {\n const parentName = piece.router.chatInputName;\n if (parentName && hasRegisteredSubcommands(parentName)) {\n wireParentSubcommands(piece);\n }\n\n return super.onLoad(store, piece);\n }\n}\n"],"mappings":";;;;;;;;;AAQA,MAAa,sBAGT,IAAI,WAAW;;;;AAKnB,MAAa,2BAGT,IAAI,WAAW;;;;AAKnB,SAAgB,qBACd,YAC+B;CAC/B,IAAI,OAAO,eAAe,YAAY;EACpC,MAAM,UAAU,IAAI,8BAA8B;EAClD,OAAO,WAAW,SAAS,SAAS,KAAK;CAC3C;CAEA,IAAI,sBAAsB,+BACxB,OAAO;CAGT,IACE,OAAO,eAAe,YACtB,eAAe,QACf,YAAY,cACZ,OAAO,WAAW,WAAW,YAC7B;EACA,MAAM,OAAQ,WAAuE,OAA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AAgB,4BAAkC;CAChD,oBAAoB,MAAM;CAC1B,yBAAyB,MAAM;AACjC;;;;;;;;;;;AC9JA,IAAa,oCAAb,cAAuD,sBAAsB;CAC3E,AAAgB,OAAO,OAAqB,OAAgB;EAC1D,MAAM,aAAa,MAAM,OAAO;EAChC,IAAI,cAAc,yBAAyB,UAAU,GACnD,sBAAsB,KAAK;EAG7B,OAAO,MAAM,OAAO,OAAO,KAAK;CAClC;AACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wolfstar/plugin-subcommands-advanced",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Plugin for @wolfstar/http-framework to modularize slash subcommands into separate command classes",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"discord",
|
|
7
|
+
"http-framework",
|
|
8
|
+
"plugin",
|
|
9
|
+
"subcommands",
|
|
10
|
+
"wolfstar"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/wolfstar-project/plugins/tree/main/packages/plugin-subcommands-advanced",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/wolfstar-project/plugins/issues"
|
|
15
|
+
},
|
|
16
|
+
"license": "Apache-2.0",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/wolfstar-project/plugins.git",
|
|
20
|
+
"directory": "packages/plugin-subcommands-advanced"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"type": "module",
|
|
26
|
+
"sideEffects": [
|
|
27
|
+
"./dist/esm/register.js"
|
|
28
|
+
],
|
|
29
|
+
"main": "./dist/esm/index.js",
|
|
30
|
+
"module": "./dist/esm/index.js",
|
|
31
|
+
"types": "./dist/esm/index.d.ts",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"import": {
|
|
35
|
+
"types": "./dist/esm/index.d.ts",
|
|
36
|
+
"default": "./dist/esm/index.js"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"./register": {
|
|
40
|
+
"import": {
|
|
41
|
+
"types": "./dist/esm/register.d.ts",
|
|
42
|
+
"default": "./dist/esm/register.js"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public",
|
|
48
|
+
"provenance": true
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@discordjs/builders": "^1.13.0",
|
|
52
|
+
"@discordjs/collection": "^2.1.1",
|
|
53
|
+
"discord-api-types": "^0.38.33"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@wolfstar/http-framework": "^3.1.0",
|
|
57
|
+
"@wolfstar/http-framework-test-utils": "^3.0.1"
|
|
58
|
+
},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"@wolfstar/http-framework": "^3.1.0"
|
|
61
|
+
},
|
|
62
|
+
"engines": {
|
|
63
|
+
"node": ">=20.0.0"
|
|
64
|
+
},
|
|
65
|
+
"scripts": {
|
|
66
|
+
"build": "tsdown --config-loader unrun",
|
|
67
|
+
"typecheck": "tsc --noEmit",
|
|
68
|
+
"lint": "oxlint src --fix",
|
|
69
|
+
"test": "vitest run"
|
|
70
|
+
}
|
|
71
|
+
}
|