Skip to content

CommandHandler - #30

Closed
Tais993 wants to merge 1 commit into
Together-Java:feature/command-systemfrom
Tais993:commands
Closed

Tais993 wants to merge 1 commit into
Together-Java:feature/command-systemfrom
Tais993:commands

Conversation

@Tais993

@Tais993 Tais993 commented Sep 7, 2021

Copy link
Copy Markdown
Member

Will be the PR for the command handler and more.
Currently this is only the Command class, open for feedback!

Issue #10

Added ExampleCommand so starting with developing becomes easier.
@Tais993 Tais993 added the enhancement New feature or request label Sep 7, 2021
@Tais993 Tais993 self-assigned this Sep 7, 2021
@Nincodedo

Copy link
Copy Markdown

Just curious, why an abstract class and not an interface?

@java-coding-prodigy

Copy link
Copy Markdown
Contributor

I too don't see the benefit of using an abstract class over an interface here.

@Tais993

Tais993 commented Sep 8, 2021 •

Copy link
Copy Markdown
Member Author

You didn't look at my code in that case.
This allows us to add optional options.
Like isGuildOnly
And in the future possibly more

Like with permissions, instead of forcing you to add a method and return null
Just nothing, makes it more readable by having less code.

@Nincodedo

Copy link
Copy Markdown

How does an interface prevent us from adding optional options?

@Tais993

Tais993 commented Sep 8, 2021

Copy link
Copy Markdown
Member Author

There's no way to have a default method that can be overridden?
At least, as far as I know.

@java-coding-prodigy

Copy link
Copy Markdown
Contributor

Well if you take the example of isGuildOnly you could have it as a regular method in the interface. When you implement all the methods, a boolean method will return false, at least in IntelliJ.

@Tais993

Tais993 commented Sep 8, 2021

Copy link
Copy Markdown
Member Author

I'm confused? Can you show me an example if how it should be implemented.

@Nincodedo

Copy link
Copy Markdown

You can override it just by including that method in the implementing class. It works just like abstract methods from an abstract class.

https://www.tutorialspoint.com/can-we-override-default-methods-in-java

@java-coding-prodigy

java-coding-prodigy commented Sep 8, 2021 •

Copy link
Copy Markdown
Contributor

I'm confused? Can you show me an example if how it should be implemented.

I meant that, say you have this code

interface AnInterface{
        boolean booleanMethod();
}
class ExtendingClass implements AnInterface{

}

Obviously, this won't compile. On IntelliJ, it will directly give the option to add unimplemented methods. Once you click on it, this is what the class will look like.

class ExtendingClass implements AnInterface{
        public boolean booleanMethod(){
                return false;
        }
}

@Tais993

Tais993 commented Sep 8, 2021

Copy link
Copy Markdown
Member Author

Howly fuck, my mind just exploded.

On that note, fields might end up being useful.
And since all commands extenders are related (atleast from my point of view), it doesn't make sense to have an interface.

@Tais993

Tais993 commented Sep 8, 2021

Copy link
Copy Markdown
Member Author

and @java-coding-prodigy, I meant having default methods that can be overriden.
But Nincodedo already showed that

@Nincodedo

Copy link
Copy Markdown

If we add fields, then yes an abstract class would make more sense.

@java-coding-prodigy

Copy link
Copy Markdown
Contributor

It is possible to have fields in interfaces, just that they will be the same throughout all implementing classes, either that or we could have a method in the interface called getVar, which will be different for different classes.
As we don't have abstract fields in java, we would have to do the same thing for abstract classes, so unless I am missing something here, in this scenario too, interfaces come out on top.

@Tais993

Tais993 commented Sep 8, 2021 •

Copy link
Copy Markdown
Member Author

I'm not sure whenever we will actually add fields, so if we eventually end up not using fields this will be changed to a interface.

And yes, an interface allows constants, but not non-public or non-static variables.
Before this gets merged to develop, we will look back and change to an interface if no features of abstract classes will be used.
That's alright to everyone?

@Tais993
Tais993 changed the base branch from develop to feature/command-system September 8, 2021 09:10
@Tais993
Tais993 marked this pull request as ready for review September 8, 2021 09:11
@Tais993

Tais993 commented Sep 8, 2021

Copy link
Copy Markdown
Member Author

Will create a new PR from feature/command-system to develop.
This way everyone can contribute to the command-system.

@I-Al-Istannen I-Al-Istannen left a comment •

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.

I think we should have a basic story for menus / selects / buttons. How do they fit in here, if the command can only be triggered by a SlashCommandEvent? Are they a separate system? How could a button in message trigger a command? How could we edit the message if a button is clicked?

* Look at {@link org.togetherjava.tjbot.commands.example.ExampleCommand} for an example.
* A second example will come for sub-commands.
*/
public abstract class AbstractCommand {

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.

This might be able to be an interface if we never need local state:

Suggested change
public abstract class AbstractCommand {
public interface Command

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.

Before this gets merged to develop, we will look back and change to an interface if no features of abstract classes will be used.
My last message

Comment on lines +32 to +34
public boolean isGuildOnly() {
return false;
}

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.

Suggested change
public boolean isGuildOnly() {
return false;
}
default isGuildOnly() {
return false;
}

@Tais993

Tais993 commented Sep 8, 2021

Copy link
Copy Markdown
Member Author

Are they a separate system?
I'd say so yeah.

We can also make all execute methods optional.
And then add 2 context menu execute methods.

This way everything can be done with extending 1 class.

We could also separate it, not sure what everyone thinks.

@marko-radosavljevic marko-radosavljevic left a comment •

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.

Since this goes into a feature branch, I'm fine with it.

@Tais993 Tais993 closed this Sep 8, 2021
@Tais993
Tais993 deleted the commands branch September 8, 2021 13:26
@Tais993

Tais993 commented Sep 8, 2021

Copy link
Copy Markdown
Member Author

Thought I merged it, mistake on my side

@Zabuzard Zabuzard linked an issue Sep 9, 2021 that may be closed by this pull request
@Zabuzard Zabuzard added this to the Initial Setup milestone Sep 9, 2021
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.

How to design a basic command system?

6 participants