Package net.kautler.command.api
Interface CommandContextTransformer<M>
-
- Type Parameters:
M
- the class of the messages for which this transformer can be triggered
- All Known Implementing Classes:
MentionPrefixTransformerJavacord
,MentionPrefixTransformerJda
public interface CommandContextTransformer<M>
A transformer that can transform a command context in a givenphase
or multiple ones. Implementations need to be annotated with one or more@InPhase
annotations to specify in which phases the transformer should be called. Only one transformer per phase that can be applied to a given message framework is supported currently.Possible use-cases for example include:
- custom prefix computation for example based on the server of the message
- fuzzy-searching for mistyped aliases and their automatic correction (this could also be used for just a "did you mean X" response, but for that the command not found events are probably better suited)
-
having a command that forwards to one command in one channel
but to another command in another channel,
like
!player
that forwards to!mc:player
in an MC channel but to!s4:player
in an S4 channel -
supporting something like
!runas @other-user foo bar baz
, where this transformer will transform that to aliasfoo
and parameter stringbar baz
and then a customRestriction
can check whether the message author has the permissions to use!runas
and then for example whether theother-user
would have permissions for thefoo
command and only then allow it to proceed -
forwarding to a
!help
command if an unknown command was issued - having a custom command registry for example with dynamically created command instances
- See Also:
CommandContextTransformer.Phase
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
CommandContextTransformer.InPhase
A CDI qualifier that is used for defining the phase in which a command context transformer should be called.static interface
CommandContextTransformer.InPhases
An annotation which serves as container for applying multiple@InPhase
annotations.static class
CommandContextTransformer.Phase
The phases during which a command context transformer is called if one is provided for the given phase.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <T extends M>
CommandContext<T>transform(CommandContext<T> commandContext, CommandContextTransformer.Phase phase)
Transforms the given command context in the givenphase
.
-
-
-
Method Detail
-
transform
<T extends M> CommandContext<T> transform(CommandContext<T> commandContext, CommandContextTransformer.Phase phase)
Transforms the given command context in the givenphase
. The fields of the given command context can be empty depending on the current phase. The fields that are set in the returned command context can cause future phases to be skipped if the according data is already computed in an earlier phase. The description of the single phases specifies which fields in the given command context should be set and which fields in the returned command context should be set and the respective effect that is caused by this. The returned value must not benull
.- Type Parameters:
T
- the class of the messages for which this transformer is triggered- Parameters:
commandContext
- the command context to be transformed, usually populated according to the phase description, but not necessarilyphase
- the phase this transformer is currently called in- Returns:
- the transformed command context
- See Also:
CommandContextTransformer.Phase
-
-