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
74 stars 24 forks source link

Add a way to provide/use own interfaces/classes/... for SlashCommands #66

Open Andre601 opened 2 years ago

Andre601 commented 2 years ago

Issue Checklist

Affected Modules

Command

Description

It would be useful, if there was a sort of SlashCommandPreProcess method or alike that would allow me (and probably many others) to do the most common checks on a slash command such as if it was from a guild.

What could be somewhat problematic is to decide how stuff is returned... Should it stay a SlashCommandEvent, or should it already be handled (deferReply()?) and then the InteractionHook returned?

I personally would find it cool, if we could "override" the default execute method to have our own instead.

To explain what I mean with that, I want to quickly show an example of what I'm currently using in my bot with message-based commands. I'm using a different library for those commands called JDA-Command, which provides and uses an interface called AbstractCommand<T>. Since my commands are always with JDA Message objects and only work in Guilds did I "override" it by extending a Command interface I made with it to then override the method with my own: https://github.com/purrbot-site/PurrBot/blob/2f44f14757bbbd6d82ca29bffa41bb53d42da232/src/main/java/site/purrbot/bot/commands/Command.java

This basically allowed me to reduce commonly made checks and actions and have a bit more safety about things (i.e. that Guild and Member are always present)

Having a similar way in Chewtils would help a lot, because then I could check if the command is from a Guild, obtain user/member and the textchannel instance and if they are null return an error before processing it further...

I hope you get what I mean... I'm not the best at explaining stuff...

Chew commented 2 years ago

Would you like a ISlashCommand interface that you can implement, as long as it has whatever the library requires?

Andre601 commented 2 years ago

Could be a solution.

Andre601 commented 2 years ago

My personal goal is just a way to have Chewtils handle the SlashCommandEvent in one central place and then execute a method for the respective command class that would have stuff...

If I understand interfaces correctly do I currently have a setup like this:

Chew commented 2 years ago

It'd be something like this:

Chewtils has a ISlashCommand

Then you have your own Impl, (SlashCommand will be an impl as well)

Maybe like this:

public class MyCustomSlashCommand implements ISlashCommand {
    public void handle(SlashCommandEvent event) {
        // the cool stuff

        run(); // method in interface
    }
}

Then in your own bot:

public class SuperCommand extends MyCustomSlashCommand {
    // code like normal
}

This is merely a theory, I'm sure something like it is possible.