Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[FEATURE] Interpolate message sending #40

Closed
aless2003 opened this issue Jan 31, 2022 · 6 comments
Closed

[FEATURE] Interpolate message sending #40

aless2003 opened this issue Jan 31, 2022 · 6 comments

Comments

@aless2003
Copy link
Contributor

So, I have two quick questions about the new version of jda-commands, as I'm currently in the process of migrating my Bots structure to Version 2.0.0

  1. I can't figure out how to give it the packages where my commands reside in. In the example you do it like this:
    image
    but the only methods I can find in the library have Strings there.
    image
    What pattern would I have to use for example to find all Commands in say example.commands?

  2. Is there no way anymore to customize how the help Command gets sent? Because I until now have written my own custom help sending mechanism:
    image
    This was easy in the prior versions, but I can't seem to find a way to do it in Version 2.0.0 (I could very well have overseen something, but as of right now I can't find anything)

@Kaktushose
Copy link
Owner

  1. the release with tag 2.0.0 had some critical issues so I rereleased it as v.2.0.0. So make sure to use v.2.0.0 and the issue should be resolved.

  2. Yes. the HelpMessageSender got removed and for the moment there is no replacement for it. I will think about how to bring it back

@Kaktushose Kaktushose self-assigned this Feb 1, 2022
@aless2003
Copy link
Contributor Author

Ah, alright, guess I'll have to stick with the default help for now then

@Kaktushose
Copy link
Owner

I have two possible solutions up in mind:

  1. Bring back the old HelpMessageSender Interface and integrate it in the ImplementationRegistry

  2. Combine it with the tentative idea of a general event system. This could look like something like this:

@Component
public class HelpEventListener implements EventListener {

    @Override
    public void onGenericHelp(GenericHelpEvent event, Message message) {
        // Acknowledge the event, tells jda-commands that this listener will handle the event and the default listener shouldn't be called
        event.consume(); 

        // manipulate the message to meet your desires
        message.doWhateverYouWant();

        // send message
        event.getChannel().sendMessage(message).queue();
    }
}

The second solution brings in more modularity and options. which may be useful especially with regards to slash commands coming. However it's more complicated and the consume as well as the similarities to the JDA event system might confuse people

@Kaktushose Kaktushose changed the title Questions about Version 2.0.0 [FEATURE] Interpolate message sending Feb 1, 2022
@aless2003
Copy link
Contributor Author

Hmm alright, so if I understand that second one right, we would implement the "onGenericHelp" method which we could customize however we want. I see how it could be confusing, wouldn't worry too much about it though, as most people who want to change the sending behavior probably also know how JDA Listeners work

@Kaktushose
Copy link
Owner

The question is whether we have a real gain from the 2. solution. The first and old solution works fine and is easier to implement, so I think I will just go with the first one

@Kaktushose
Copy link
Owner

This has been implemented as following and will become available with the next update.

public interface MessageSender {

    /**
     * Called when a generic help message should be sent.
     *
     * @param context the corresponding {@link CommandContext}
     * @param message the help message to send
     */
    void sendGenericHelpMessage(@NotNull CommandContext context, @NotNull Message message);

    /**
     * Called when a specific help message should be sent.
     *
     * @param context the corresponding {@link CommandContext}
     * @param message the help message to send
     */
    void sendSpecificHelpMessage(@NotNull CommandContext context, @NotNull Message message);

    /**
     * Called when an error message should be sent.
     *
     * @param context the corresponding {@link CommandContext}
     * @param message the error message to send
     */
    void sendErrorMessage(@NotNull CommandContext context, @NotNull Message message);
}

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants