Chew / JDA-Chewtils

Chew's fork of JDA-Applications/JDA-Utilities, with support for modern features such as Slash Commands, Context Menus, and more.
https://chew.pro/JDA-Chewtils
Apache License 2.0
73 stars 24 forks source link

Support for the interactions rework & Context Menus #45

Closed Chew closed 2 years ago

Chew commented 2 years ago

Surprisingly not bad (for me)

For y'all, bad news.

SlashCommandEvent got renamed to SlashCommandInteractionEvent.

NO BIG DEAL! I added it back as a JDA-Chewtils method. However, you will need to reimport the class.

I was able to do a simple find and replace across my project:

Find: import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; Replace: import com.jagrosh.jdautilities.command.SlashCommandEvent;

Because this new SlashCommandEvent extends SlashCommandInteractionEvent, all methods work fine. You don't need to change anything!

One thing though, this means event.getClient() works now. Now you no longer need to this.getClient() in your events.

Next, CooldownScope was moved. You simply need to import it for no functionality changes, if you use it.

This PR also adds full support for Context Menus. There is now UserContextMenu and MessageContextMenu classes used just like a Command or SlashCommand, this.name is what shows in the client.

To compensate for variables being used in now, 3 different, branching places, an Interaction class has been created. This class has functionality used in Command, SlashCommand, and now UserContextMenu and MessageContextMenu that does not change between classes. These being, botPermission, userPermission, ownerCommand, as well as cooldown and cooldownScope.

There is a new onAutoComplete(CommandAutoCompleteInteractionEvent event) you can override and it will be executed whenever an auto-complete option is triggered. Here you can reply as you would the execute event.

More to come!

Testing

If you want to help test, use the following repo/dependency information:

Maven stuff, I am not magic enough to convert to gradle

        <repository>
            <id>chew-m2-snapshots</id>
            <url>https://m2.chew.pro/snapshots/</url>
        </repository>
        <dependency>
            <groupId>pw.chew</groupId>
            <artifactId>jda-chewtils</artifactId>
            <version>2.0-interactions-SNAPSHOT</version>
            <scope>compile</scope>
            <type>pom</type>
        </dependency>

As usual I do not recommend Jitpack since it's a bit messy and confusing. I'll deploy here every commit. I will likely clear the snapshot stuff when this gets merged, however.

Chew commented 2 years ago

For anyone following...

Context Menu (message) in action: image

Auto Complete in action:

https://user-images.githubusercontent.com/8278263/148721486-6975d0aa-98ee-4378-bf2e-ecf5869a0392.mov

Chew commented 2 years ago

@RoryHelper approve