Skip to content

Basic command interface and examples - #49

Merged
Tais993 merged 7 commits into
Together-Java:feature/command-systemfrom
Tais993:feature/command-system
Sep 9, 2021
Merged

Tais993 merged 7 commits into
Together-Java:feature/command-systemfrom
Tais993:feature/command-system

Conversation

@Tais993

@Tais993 Tais993 commented Sep 8, 2021

Copy link
Copy Markdown
Member

Thought again about interface vs abstract class.
And ended up with an interface.

I'm not sure how it exactly ends like, so maybe it will become an abstract class again.
We'll find out

Added ICommand, the basic command interface all commands have to implement.
Added SubCommandExample, it's an example for a command with subcommands.
Added CommandExample, just a normal command example.

Opinions on the docs, or the code itself are welcome!
Hopefully this is alright so we will have this as basis for the branch.

Thought again about interface vs abstract class.
And ended up with an interface.

I'm not sure how it exactly ends like, so maybe it will become an abstract class again.
We'll find out

Added SubCommandExample, it's an example for a command with subcommands.
Let's not talk about that :)
Thought again about interface vs abstract class.
And ended up with an interface.

I'm not sure how it exactly ends like, so maybe it will become an abstract class again.
We'll find out

Added SubCommandExample, it's an example for a command with subcommands.
* <br> A second example will come for sub-commands.
*
*/
public interface ICommand {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public interface ICommand {
public interface Command {

Starting interfaces with I is an old standard that I don't think we need to follow. Feel free to disregard if the group feels otherwise.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to follow it yeah, following it has no downsides.
While it does have the upside of telling the user it's a interface.
Which is nice, since commands have to implement it, not extend it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should anyway not make changes for such minor things, but I thing we should stick with a naming convention throughout the project.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also suggest sticking to common Java conventions. IIRC using I and comparable as prefix is more a thing for C-based languages.

@Tais993 Tais993 Sep 9, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no Java convention telling you to not use or or use it ¯_(ツ)_/¯

Interface names should be capitalized like class names.

So by adding an I to the name, we are following Java conventions.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well yes, everything falls under that classification. Just saying that I've yet to see anyone code Java like that in the industry/higher education

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really care so ig I'll change it

…#getCommandName and to the ICommand#getDescription method
@Tais993 Tais993 self-assigned this Sep 8, 2021
@Tais993 Tais993 added the enhancement New feature or request label Sep 8, 2021
@RicardoMonteiroSimoes

Copy link
Copy Markdown

What speaks against using already existing libraries that solve this problem? Out of my head I know of one, the thing is it uses annotations for it.

The next question would be if all commands are created at compile time or if you want to be able to load them at runtime? As in, you have the bot framework that handles everything, and i.e. the "Ban"-Command could be updated outside of the bot and dynamically loaded.

@Tais993

Tais993 commented Sep 9, 2021 •

Copy link
Copy Markdown
Member Author

What speaks against using already existing libraries that solve this problem? Out of my head I know of one, the thing is it uses annotations for it

Yes, Chewtils a.e

Those are fun for people that lack coding knowledge, or just want it to be easy and simple.
They're not bad, don't get me wrong.

But by creating something like this yourself, it's all educational for everyone, and it's fun + you have way more control

could be updated outside of the bot and dynamically loaded.

I'm not gonna bother creating anything like that, just restarting also works and is way simpler.

@Tais993

Tais993 commented Sep 9, 2021

Copy link
Copy Markdown
Member Author

I want this PR merged asap so there's a basis for people to work on.
The Command interface isn't fully finished, but this introduces a basis so the comandhandler can be created

@RicardoMonteiroSimoes

Copy link
Copy Markdown

Has it been defined how you handle commands that are locked behind roles? Maybe thats a feature that you could include, or make it a separate interface

@Tais993

Tais993 commented Sep 9, 2021

Copy link
Copy Markdown
Member Author

I thought I mentioned this somewhere..

And yes I thought about it, I'm planning for making it easier to add command permissions in the future.

Currently slash-command permissions are pretty shit, and Discord has confirmed on reworking them. (See Moderation -> "Revisit the permissions system to make it more flexible")

So I'll wait until the rework, when the rework has been completed this will be added.
But not going to spend time on a bad system that will need to be fully reworked once the new system is out

@RicardoMonteiroSimoes

Copy link
Copy Markdown

Yes, I've read that comment, but wasn't aware it would be a limitation on role based filters? The bot would (probably) filter those, so such a system would be independent of discords slash command API? Unless, of course, you can define roles in the API for them

@Tais993

Tais993 commented Sep 9, 2021

Copy link
Copy Markdown
Member Author

The current slash-command permissions system works fully on roles.
Which works yes, but it'd be nicer to have the clear command for everyone with the manage message permission.
Instead of having to hardcode the roles and more.

So right now you can just do Member#hasPermission instead

Well, I don't see a reason to use roles besides because of Discord limitations.

@Tais993
Tais993 merged commit 8c6b3a2 into Together-Java:feature/command-system Sep 9, 2021
Tais993 added a commit to Tais993/TJ-Bot that referenced this pull request Sep 9, 2021
@Zabuzard

Zabuzard commented Sep 9, 2021

Copy link
Copy Markdown
Member

May I ask, @Tais993 why did you not migrate the existing command to the "new" system?

@Zabuzard Zabuzard added this to the Initial Setup milestone Sep 9, 2021
@Tais993

Tais993 commented Sep 9, 2021 •

Copy link
Copy Markdown
Member Author

What existing commands, also this is probably better to be in the draft PR
Can't link a issue/or on mobile?

Tais993 added a commit that referenced this pull request Sep 11, 2021
Adds a start of the command system.

The Command interface has methods for the SlashCommandEvent, ButtonClickEvent and SelectionMenuEvent.
The Command interface includes Javadoc, and there's 2 examples (SubCommandExample and CommandExample)

This is still WIP but creates an foundation for others to work on.
Tais993 added a commit that referenced this pull request Sep 11, 2021
Adds a start of the command system.

The Command interface has methods for the SlashCommandEvent, ButtonClickEvent and SelectionMenuEvent.
The Command interface includes Javadoc, and there's 2 examples (SubCommandExample and CommandExample)

This is still WIP but creates an foundation for others to work on.
Tais993 added a commit that referenced this pull request Sep 11, 2021
Adds a start of the command system.

The Command interface has methods for the SlashCommandEvent, ButtonClickEvent and SelectionMenuEvent.
The Command interface includes Javadoc, and there's 2 examples (SubCommandExample and CommandExample)

This is still WIP but creates an foundation for others to work on.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants