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 givenphaseor multiple ones. Implementations need to be annotated with one or more@InPhaseannotations 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
!playerthat forwards to!mc:playerin an MC channel but to!s4:playerin an S4 channel -
supporting something like
!runas @other-user foo bar baz, where this transformer will transform that to aliasfooand parameter stringbar bazand then a customRestrictioncan check whether the message author has the permissions to use!runasand then for example whether theother-userwould have permissions for thefoocommand and only then allow it to proceed -
forwarding to a
!helpcommand 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 interfaceCommandContextTransformer.InPhaseA CDI qualifier that is used for defining the phase in which a command context transformer should be called.static interfaceCommandContextTransformer.InPhasesAn annotation which serves as container for applying multiple@InPhaseannotations.static classCommandContextTransformer.PhaseThe 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
-
-