@@ -17,7 +17,7 @@ Command Framework
1717A generic CDI-based command framework. This library requires Java 8 or newer but is fully Java 9+ compatible and can run
1818as a proper Java module on the module path. Any arbitrary underlying message framework like a Discord library, an IRC
1919library, or a Skype library can be used by providing an according [ ` CommandHandler ` ] [ CommandHandler JavaDoc ]
20- implementation. You are also welcome to contribute such implementations back to the main project for all users benefit.
20+ implementation. You are also welcome to contribute such implementations back to the main project for all users' benefit.
2121
2222
2323
@@ -32,9 +32,11 @@ Table of Contents
3232* [ Usage] ( #usage )
3333 * [ Message Framework] ( #message-framework )
3434 * [ Javacord] ( #javacord )
35- * [ Text Commands] ( #text-commands )
36- * [ Slash Commands] ( #slash-commands )
35+ * [ Text Commands] ( #javacord- text-commands )
36+ * [ Slash Commands] ( #javacord- slash-commands )
3737 * [ JDA] ( #jda )
38+ * [ Text Commands] ( #jda-text-commands )
39+ * [ Slash Commands] ( #jda-slash-commands )
3840 * [ Creating Commands] ( #creating-commands )
3941 * [ Command Aliases] ( #command-aliases )
4042 * [ Asynchronous Command Execution] ( #asynchronous-command-execution )
@@ -72,8 +74,8 @@ Prerequisites
7274* Java 8+
7375* At least one of the supported [ message frameworks] ( #supported-message-frameworks ) unless a custom ` CommandHandler `
7476 is used; without one there will be no error, but this framework will simply have nothing to do
75- * An implementation of CDI that implements CDI 3.0.0 like [ Weld SE] [ Weld SE Website ]
76- * [ Optional] ANTLR runtime 4.7 .2 if the [ ` ParameterParser ` ] [ ParameterParser JavaDoc ] is used
77+ * An implementation of CDI that implements CDI 3.0.1 like [ Weld SE] [ Weld SE Website ]
78+ * [ Optional] ANTLR runtime 4.13 .2 if the [ ` ParameterParser ` ] [ ParameterParser JavaDoc ] is used
7779
7880
7981
@@ -83,7 +85,7 @@ Supported Message Frameworks
8385The following message frameworks are currently supported out of the box:
8486
8587* [ Javacord] ( #javacord ) (text and slash commands)
86- * [ JDA] ( #jda ) (text commands)
88+ * [ JDA] ( #jda ) (text and slash commands)
8789
8890If you want to have support for an additional framework, do not hesitate to open a pull request or feature request
8991issue.
@@ -95,18 +97,50 @@ Setup
9597
9698### Gradle
9799
98- ``` gradle
99- repositories { mavenCentral() }
100- dependencies { implementation 'net.kautler:command-framework:0.5.0' }
100+ ``` kotlin
101+ repositories {
102+ mavenCentral()
103+ }
104+ dependencies {
105+ implementation(" net.kautler:command-framework:0.6.0-SNAPSHOT" )
106+ }
107+ ```
108+
109+ There are also feature variants published that Gradle consumers can conveniently depend on.
110+ One such variant per message framework support and one for the parameter parser.
111+ The code artifact is the same for all variants currently, but you will benefit from automatically getting
112+ the necessary transitive dependencies that are only mentioned as ` optional ` in the POM.
113+
114+ For example to use the Javacord support and the parameter parser,
115+ you can request the according feature variants like this:
116+
117+ ``` kotlin
118+ dependencies {
119+ implementation(" net.kautler:command-framework:0.6.0-SNAPSHOT" ) {
120+ capabilities {
121+ requireFeature(" javacord-support" )
122+ }
123+ }
124+ implementation(" net.kautler:command-framework" ) {
125+ capabilities {
126+ requireFeature(" parameter-parser" )
127+ }
128+ }
129+ }
101130```
102131
132+ _ ** Published Feature Variants:** _
133+ * ` net.kautler:command-framework-javacord-support `
134+ * ` net.kautler:command-framework-jda-support `
135+ * ` net.kautler:command-framework-parameter-parser `
136+
103137### Maven
104138
105139``` xml
106140<dependency >
107- <groupId >net.kautler</groupId >
108- <artifactId >command-framework</artifactId >
109- <version >0.5.0 </version >
141+ <groupId >net.kautler</groupId >
142+ <artifactId >command-framework</artifactId >
143+ <version >0.6.0-SNAPSHOT </version >
110144</dependency >
111145```
112146
@@ -123,7 +157,7 @@ Usage
123157
124158#### Javacord
125159
126- ##### Text Commands
160+ ##### < a name = " javacord-text-commands " /> Text Commands
127161
128162For the [ Javacord] [ Javacord Website ] support, include Javacord as implementation dependency and create a CDI producer
129163that produces either one ` DiscordApi ` , or if you use sharding a ` Collection<DiscordApi> ` with all shards where you want
@@ -146,6 +180,8 @@ class JavacordProducer {
146180 DiscordApi produceDiscordApi () {
147181 return new DiscordApiBuilder ()
148182 .setToken(discordToken)
183+ // comment in the next line when using text commands
184+ // .addIntents(MESSAGE_CONTENT)
149185 .login()
150186 .exceptionally(ExceptionLogger . get())
151187 .join();
@@ -158,11 +194,11 @@ class JavacordProducer {
158194```
159195
160196_ ** Tested versions:** _
161- * ` 3.4 .0 `
197+ * ` 3.8 .0 `
162198
163- ##### Slash Commands
199+ ##### < a name = " javacord-slash-commands " /> Slash Commands
164200
165- For slash commands you need to do the same as for [ Text Commands] ( #text-commands ) .
201+ For slash commands you need to do the same as for [ Text Commands] ( #javacord- text-commands ) .
166202
167203Additionally, the [ commands] ( #creating-commands ) have to implement
168204[ ` SlashCommandJavacord ` ] [ SlashCommandJavacord JavaDoc ] instead of ` Command ` . Furthermore, they must have a
@@ -179,7 +215,7 @@ commands, all phases before `BEFORE_COMMAND_COMPUTATION` are skipped by the comm
179215Finally, this framework does not register the slash commands with Discord for you automatically, because you
180216might want to register them globally, or per server, or you might want to add further commands not managed by
181217this framework, and so on. Instead, you can register the commands yourself by injecting the provided
182- ` List <SlashCommandBuilder>` . This injected list can directly be used as argument for methods like
218+ ` Set <SlashCommandBuilder>` . This injected list can directly be used as argument for methods like
183219` DiscordApi#bulkOverwriteGlobalApplicationCommands ` or ` DiscordApi#bulkOverwriteServerApplicationCommands ` .
184220The requirements described above regarding description and aliases are only enforced if you inject it somewhere.
185221
@@ -194,7 +230,7 @@ public class SlashCommandRegisterer {
194230 DiscordApi discordApi;
195231
196232 @Inject
197- List <SlashCommandBuilder > slashCommandBuilders;
233+ Set <SlashCommandBuilder > slashCommandBuilders;
198234
199235 void registerSlashCommands (@Observes @Initialized (ApplicationScoped . class) Object __ ) {
200236 discordApi
@@ -205,10 +241,12 @@ public class SlashCommandRegisterer {
205241```
206242
207243_ ** Tested versions:** _
208- * ` 3.4 .0 `
244+ * ` 3.8 .0 `
209245
210246#### JDA
211247
248+ ##### <a name =" jda-text-commands " />Text Commands
249+
212250For the [ JDA] [ JDA Website ] support, include JDA as implementation dependency and create a CDI producer that produces
213251either one ` JDA ` , of if you use sharding a ` Collection<JDA> ` , a ` ShardManager ` or a ` Collection<ShardManager> ` with all
214252shards where you want commands to be handled. You should also have a disposer method that properly shuts down the
@@ -231,10 +269,15 @@ class JdaProducer {
231269 try {
232270 return JDABuilder
233271 .createLight(discordToken)
272+ // comment in the next line when using text commands
273+ // .enableIntents(MESSAGE_CONTENT)
234274 .build()
235275 .awaitReady();
236- } catch (InterruptedException | LoginException e) {
237- logger. error(" Exception while logging in to Discord" , e);
276+ } catch (InterruptedException e) {
277+ logger
278+ .atError()
279+ .withThrowable(e)
280+ .log(" Exception while logging in to Discord" );
238281 return null ;
239282 }
240283 }
@@ -246,7 +289,57 @@ class JdaProducer {
246289```
247290
248291_ ** Tested versions:** _
249- * ` 4.4.0_352 `
292+ * ` 6.4.0 `
293+
294+ ##### <a name =" jda-slash-commands " />Slash Commands
295+
296+ For slash commands you need to do the same as for [ Text Commands] ( #jda-text-commands ) .
297+
298+ Additionally, the [ commands] ( #creating-commands ) have to implement
299+ [ ` SlashCommandJda ` ] [ SlashCommandJda JavaDoc ] instead of ` Command ` . Furthermore, they must have a
300+ [ description] ( #command-description ) defined, and all [ aliases] ( #command-aliases ) have to consist of one to three
301+ slash separated parts, so either ` command ` , ` command/subcommand ` , or ` command/subcommand-group/subcommand ` .
302+
303+ If your command needs parameters or you want to do other customizations of the ` SlashCommandData ` , you overwrite the
304+ ` SlashCommandJda#prepareSlashCommandData ` method, which just returns the argument in its default implementation.
305+ In the implementation of the method you can then use the full API for JDA slash commands. For subcommands you instead
306+ overwrite the ` SlashCommandJda#prepareSubcommandData ` method, which has the same default implementation and customizes
307+ a ` SubcommandData ` .
308+
309+ When using [ command context transformers] ( #customizing-the-command-recognition-and-resolution-process ) with slash
310+ commands, all phases before ` BEFORE_COMMAND_COMPUTATION ` are skipped by the command handler already.
311+
312+ Finally, this framework does not register the slash commands with Discord for you automatically, because you
313+ might want to register them globally, or per server, or you might want to add further commands not managed by
314+ this framework, and so on. Instead, you can register the commands yourself by injecting the provided
315+ ` Collection<SlashCommandData> ` . This injected collection can directly be used as argument for methods like
316+ ` CommandListUpdateAction#addCommands ` .
317+ The requirements described above regarding description and aliases are only enforced if you inject it somewhere.
318+
319+ A fully self-contained example containing a text, a slash, and a combined command can be found at
320+ ` examples/simplePingBotJda ` .
321+
322+ _ ** Example:** _
323+ ``` java
324+ @ApplicationScoped
325+ public class SlashCommandRegisterer {
326+ @Inject
327+ JDA jda;
328+
329+ @Inject
330+ Collection<SlashCommandData > slashCommandDatas;
331+
332+ void registerSlashCommands (@Observes @Initialized (ApplicationScoped . class) Object __ ) {
333+ jda
334+ .updateCommands()
335+ .addCommands(slashCommandDatas)
336+ .queue();
337+ }
338+ }
339+ ```
340+
341+ _ ** Tested versions:** _
342+ * ` 6.4.0 `
250343
251344### Creating Commands
252345
@@ -282,9 +375,13 @@ aliases to which the command reacts can be configured. If no aliases are configu
282375or ` Cmd ` suffix / prefix stripped and the first letter lowercased is used as a default. If at least one alias is
283376configured, only the explicitly configured ones are used.
284377
285- _ Javacord slash command specific:_ When injecting a ` List<SlashCommandBuilder> ` anywhere, all aliases of commands
286- implementing [ ` SlashCommandJavacord ` ] [ SlashCommandJavacord JavaDoc ] have to follow a pre-defined format that is described
287- at [ slash commands] ( #slash-commands ) .
378+ _ Javacord slash command specific:_ When injecting a ` Set<SlashCommandBuilder> ` or a supertype anywhere, all aliases of
379+ commands implementing [ ` SlashCommandJavacord ` ] [ SlashCommandJavacord JavaDoc ] have to follow a pre-defined format that is
380+ described at [ Javacord slash commands] ( #javacord-slash-commands ) .
381+
382+ _ JDA slash command specific:_ When injecting a ` Collection<SlashCommandData> ` or a supertype anywhere, all aliases of
383+ commands implementing [ ` SlashCommandJda ` ] [ SlashCommandJda JavaDoc ] have to follow a pre-defined format that is
384+ described at [ JDA slash commands] ( #jda-slash-commands ) .
288385
289386#### Asynchronous Command Execution
290387
@@ -308,8 +405,11 @@ being configured asynchronously if the underlying message framework dispatches m
308405By overwriting the ` Command#getDescription() ` method or applying the [ ` @Description ` ] [ @Description JavaDoc ] annotation,
309406the description of the command can be configured. This description can be used, for example, in a custom help command.
310407
311- _ Javacord slash command specific:_ When injecting a ` List<SlashCommandBuilder> ` anywhere, all commands implementing
312- [ ` SlashCommandJavacord ` ] [ SlashCommandJavacord JavaDoc ] have to provide a description.
408+ _ Javacord slash command specific:_ When injecting a ` Set<SlashCommandBuilder> ` or a supertype anywhere, all commands
409+ implementing [ ` SlashCommandJavacord ` ] [ SlashCommandJavacord JavaDoc ] have to provide a description.
410+
411+ _ JDA slash command specific:_ When injecting a ` Collection<SlashCommandData> ` or a supertype anywhere, all commands
412+ implementing [ ` SlashCommandJda ` ] [ SlashCommandJda JavaDoc ] have to provide a description.
313413
314414#### Command Restrictions
315415
@@ -773,8 +873,8 @@ constraints of semantic versioning. All other classes are considered internal an
773873License
774874-------
775875
776- ```
777- Copyright 2019-2022 Björn Kautler
876+ ``` plain
877+ Copyright 2019-2026 Björn Kautler
778878
779879Licensed under the Apache License, Version 2.0 (the "License");
780880you may not use this file except in compliance with the License.
@@ -806,7 +906,7 @@ limitations under the License.
806906[ Mutant Coverage Badge] :
807907 https://shields.io/badge/PIT%20Mutant%20Coverage-100%25-brightgreen.svg?style=flat
808908[ Integration Test Coverage Badge] :
809- https://shields.io/badge/Integration%20Test%20Coverage-~70 %25-brightgreen.svg?style=flat
909+ https://shields.io/badge/Integration%20Test%20Coverage-~75 %25-brightgreen.svg?style=flat
810910[ Supported Java Versions Badge] :
811911 https://shields.io/badge/Supported%20Java%20Versions-Java8+-lightgrey.svg
812912[ Supported Message Frameworks Badge] :
@@ -868,6 +968,8 @@ limitations under the License.
868968 https://www.javadoc.io/page/net.kautler/command-framework/latest/net/kautler/command/api/restriction/javacord/ServerJavacord.html
869969[ SlashCommandJavacord JavaDoc] :
870970 https://www.javadoc.io/page/net.kautler/command-framework/latest/net/kautler/command/api/slash/javacord/SlashCommandJavacord.html
971+ [ SlashCommandJda JavaDoc] :
972+ https://www.javadoc.io/page/net.kautler/command-framework/latest/net/kautler/command/api/slash/jda/SlashCommandJda.html
871973[ @Usage JavaDoc] :
872974 https://www.javadoc.io/page/net.kautler/command-framework/latest/net/kautler/command/api/annotation/Usage.html
873975[ UserJavacord JavaDoc] :
0 commit comments