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 given phase 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 alias foo and parameter string bar baz and then a custom Restriction can check whether the message author has the permissions to use !runas and then for example whether the other-user would have permissions for the foo 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
    • Method Detail

      • transform

        <T extends MCommandContext<T> transform​(CommandContext<T> commandContext,
                                                  CommandContextTransformer.Phase phase)
        Transforms the given command context in the given phase. 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 be null.
        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 necessarily
        phase - the phase this transformer is currently called in
        Returns:
        the transformed command context
        See Also:
        CommandContextTransformer.Phase