Inject Event Objects into Command Methods #78

Open
opened 2019-11-20 19:59:39 +00:00 by Ghost · 0 comments
Ghost commented 2019-11-20 19:59:39 +00:00 (Migrated from codeberg.org)

Feature Request

Sub-Project

This is regarding:

  • core

Description

Currently the only event we can inject is ActionEvent, regardless of type parameters.
This is nice as it provides some control which is useful, however it'd be better if we were able to
use some kind of pre-execution bindings so there was a cleaner and better way we could handle event
objects other than the highest level Action object.

Motivation

Referring to Discord (ComCord) as the primary example of this, it's quite common that
we want to access E or M inside the ActionEvent<E, M>, but the only way to get these
is with injecting the ActionEvent and then doing the respective getter.

It'd be great if events just had a pool of objects that could be injected into events, and
there was a property or annotation that indicated to take from the pool instead of treating
it like a parameter instead of hard-coding specifically for the ActionEvent.

Interface

@Singleton
public class PrefixController implements Controller {

    public String before(ActionEvent<?, Message> event, String prefix) {
        Message message = event.getMessage();
        Guild guild = message.getGuild();
        
        return "I had to go get Message/Guild manually.";
    }

    public String after(@Inject Message message, @Inject Guild guild, String prefix) {
         return "I can just inject message, or guild. This is cleaner and simpler.";
    }
}
# Feature Request <!-- This is for requesting new features, or improvements/additions to existing features. This is pre-filled with example values, feel free to remove them before populating the template. If you feel a heading is irrelevent, just remove it. --> ## Sub-Project <!-- Can you specify which sub-project(s) this is relevant to? If you aren't sure, or this is a proposal for a new sub-project, you can delete this. --> This is regarding: * core ## Description <!-- Explain what this is about, try to use full sentences, and make your point clear. --> Currently the only event we can inject is `ActionEvent`, regardless of type parameters. This is nice as it provides some control which is useful, however it'd be better if we were able to use some kind of pre-execution bindings so there was a cleaner and better way we could handle event objects other than the highest level Action object. ## Motivation <!-- Why is this a feature that should be implemented in Commandler rather than in your own project using it? What makes this fundamental, or reusable, or of demand to other developers? --> Referring to Discord (ComCord) as the primary example of this, it's quite common that we want to access `E` or `M` inside the `ActionEvent<E, M>`, but the only way to get these is with injecting the `ActionEvent` and then doing the respective getter. It'd be great if events just had a pool of objects that could be injected into events, and there was a property or annotation that indicated to take from the pool instead of treating it like a parameter instead of hard-coding specifically for the `ActionEvent`. ## Interface <!-- In some cases you may wish to propose an interface or method names to help describe how you'd want to use this, or for others to discuss and improve ahead of time before final implementation. --> ```java @Singleton public class PrefixController implements Controller { public String before(ActionEvent<?, Message> event, String prefix) { Message message = event.getMessage(); Guild guild = message.getGuild(); return "I had to go get Message/Guild manually."; } public String after(@Inject Message message, @Inject Guild guild, String prefix) { return "I can just inject message, or guild. This is cleaner and simpler."; } } ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
SethFalco/commandler#78
No description provided.