@@ -39,6 +39,7 @@ Table of Contents
3939 * [ Command Usage] ( #command-usage )
4040 * [ Parsing Parameters] ( #parsing-parameters )
4141 * [ Customizing Command Prefix] ( #customizing-command-prefix )
42+ * [ Customizing Alias Calculation] ( #customizing-alias-calculation )
4243 * [ CDI Events] ( #cdi-events )
4344 * [ Handling Missing Commands] ( #handling-missing-commands )
4445 * [ Handling Disallowed Commands] ( #handling-disallowed-commands )
@@ -409,6 +410,50 @@ public class MentionPrefixProvider extends MentionPrefixProviderJavacord {
409410}
410411```
411412
413+ #### Customizing Alias Calculation
414+
415+ The alias calculation can be customized by providing a CDI bean that implements the
416+ [ ` AliasAndParameterStringTransformer ` ] [ AliasAndParameterStringTransformer JavaDoc ] interface. In the implementation of
417+ the ` transformAliasAndParameterString ` method you can determine from the message that caused the processing what the
418+ alias and parameter string should be. The transformer is called after the alias and parameter string are determined from
419+ the message using all registered aliases and before the command is resolved from the alias. If an alias was found from
420+ the registered aliases, the ` aliasAndParameterString ` parameter contains the found information. If no alias was found,
421+ the parameter will be ` null ` . The fields in the ` AliasAndParameterString ` object are always non-` null ` .
422+
423+ The transformer can then either accept the found alias and parameter string by returning the argument directly, or it
424+ can determine a new alias and parameter string and return these. The return value of the transformer will be used for
425+ further processing. If the alias in the returned object is not one of the registered aliases or the transformer returns
426+ ` null ` , there will not be any command found and the respective CDI event will be fired.
427+
428+ Example use-cases for this are:
429+
430+ - fuzzy-searching for mistyped aliases and their automatic correction (this could also be used for just a
431+ "did you mean X" response, but for that the command not found events are probably better suited)
432+
433+ - having a command that forwards to one command in one channel but to another command in another channel,
434+ like ` !player ` that forwards to ` !mc:player ` in an MC channel but to ` !s4:player ` in an S4 channel
435+
436+ - supporting something like ` !runas @other-user foo bar baz ` , where the transformer will transform that to alias
437+ ` foo ` and parameter string ` bar baz ` and then a custom ` Restriction ` can check whether the message author has
438+ the permissions to use ` !runas ` and then for example whether the ` other-user ` would have permissions for the
439+ ` foo ` command and only then allow it to proceed
440+
441+ - forwarding to a ` !help ` command if an unknown command was issued
442+
443+ _ ** Example:** _
444+ ``` java
445+ @ApplicationScoped
446+ public class MyAliasAndParameterStringTransformer implements AliasAndParameterStringTransformer<Message > {
447+ @Override
448+ public AliasAndParameterString transformAliasAndParameterString (
449+ Message message , AliasAndParameterString aliasAndParameterString ) {
450+ return (aliasAndParameterString == null )
451+ ? new AliasAndParameterString (" help" , " " )
452+ : aliasAndParameterString;
453+ }
454+ }
455+ ```
456+
412457### CDI Events
413458
414459#### Handling Missing Commands
@@ -557,6 +602,8 @@ limitations under the License.
557602 https://www.javadoc.io/page/net.kautler/command-framework/latest/net/kautler/command/api/ParameterParser.html
558603[ PrefixProvider JavaDoc] :
559604 https://www.javadoc.io/page/net.kautler/command-framework/latest/net/kautler/command/api/prefix/PrefixProvider.html
605+ [ AliasAndParameterStringTransformer JavaDoc] :
606+ https://www.javadoc.io/page/net.kautler/command-framework/latest/net/kautler/command/api/AliasAndParameterStringTransformer.html
560607[ @RestrictedTo JavaDoc] :
561608 https://www.javadoc.io/page/net.kautler/command-framework/latest/net/kautler/command/api/annotation/RestrictedTo.html
562609[ Restriction JavaDoc] :
0 commit comments