Skip to content

How to design a basic command system? #10

Closed

Description

@Tais993

By making usage of a command system we can make the creation of commands really easy.

A user only needs to create 1 class that extends a "Command" class.
This automatically requires the override of multiple methods that create the help command, and more.

We would have to decide whenever we want reflection or hardcoded commands

By making usage of reflection, the user only needs to extend 1 class. (Which would also be required when hardcoded commands)
The command will automatically be added, and automatically run.
Disabling commands can be done by overriding a (non abstract) method (isDisabled a.e) that by default returns false.
This is really easy for everyone.

I can't comment on advantages of hardcoded commands, if anyone has any I'll add those here.

Feel free to add counter arguments against either in the commands, those will be added to this message.

React with the corresponding emoji to vote

  • 🚀 Reflection
  • 🥇 Hardcoded commands

Activity

  1. added
    question
    on Sep 5, 2021
  2. added this to the Initial Setup milestone on Sep 5, 2021
  3. illuminator3 commented on Sep 5, 2021

    @illuminator3
    Contributor

    I don't think reflection would be good, since we aim to be a beginner friendly and reflection isn't really beginner friendly at all. It could also cause portability issues over different Java versions.

  4. Tais993 commented on Sep 5, 2021

    @Tais993
    MemberAuthor

    How would it not be beginner friendly?
    I feel like it's even more beginner friendly, they don't have to add it to any collection or file.
    Just extending a class would be enough.

    could also cause portability issues over different Java versions.

    I'd assume we will use the latest Java, but feel free to discuss this in #13

  5. d3vel0per commented on Sep 5, 2021

    @d3vel0per
    Contributor

    We really need not use reflection as such. We can leverage something like a service registry pattern.
    Commands would have various classes of interfaces based on the kind of work they are supposed to do. And all command implementations will register in a central command registry at compile time which by definition would be a hardcoded list. It would be a ticking timebomb if any new command added dynamically gets deployed in production just because it adheres to a "command interface". We should have some control over the which commands are OK to run in production vs which aren't. Either it starts as a static list, can become a dynamic list managed in the database or if we have very fancy use cases rather use a rules engine. This way apart from the primary deployment even the command deployments can be rolled out in a controlled manner.

    Its another case if we want to leverage a DI framework which of course will use reflection/proxying behind the scenes but does the use case ask for those level of abstractions YAGNI

    Additionally since the new bot is supposed to be an aggregation of a whole lot of existing features I feel it would be good if the commands are isolated from each other in the runtime ie. a single bad command shouldn't bring down the whole bot engine.

  6. Tais993 commented on Sep 5, 2021

    @Tais993
    MemberAuthor

    After Googling "service registry pattern" I couldn't really find a good explanation, or well I don't understand what you mean exactly.
    It sounds really complicated, I could be misunderstanding it.

    But my original intention was to go for a approach like Chewtils did regarding Commands itself. (Not this code, probably not even close to it, but the idea)
    A simple run method, with other methods that get the command name, it's description etc.

    This is extremely simple.

    adheres to a "command interface". We should have some control over the which commands are OK to run in production vs which aren't

    Regarding this statement.

    Disabling commands can be done by overriding a (non abstract) method (isDisabled a.e) that by default returns false.

    And we shouldn't have non production things in a production branch regardless.
    Commands that are WIP should be in a different branch or a fork.

    Additionally since the new bot is supposed to be an aggregation of a whole lot of existing features I feel it would be good if the commands are isolated from each other in the runtime ie. a single bad command shouldn't bring down the whole bot engine.

    Reflection doesn't matter with this, this will be no issue.
    On errors only the event errors out.
    Not the bot.

    We really need not use reflection as such.

    Feel free to add a reaction as vote, same applies for @illuminator3

  7. changed the title [-]Creation of basic command system[/-] [+]How to design a basic command system[/+] on Sep 6, 2021
  8. changed the title [-]How to design a basic command system[/-] [+]How to design a basic command system?[/+] on Sep 6, 2021
  9. Tais993 commented on Sep 7, 2021

    @Tais993
    MemberAuthor

    If no-one will elaborate further on their decision reflection vs hardcoded is decided?

  10. Tais993 commented on Sep 7, 2021

    @Tais993
    MemberAuthor

    I'll be making a PR, which will be open for feedback.

  11. Zabuzard commented on Sep 9, 2021

    @Zabuzard
    Member

    Good discussions. I feel we have enough info to create a first proposal (@Tais993 is actually already working on it).

    Closing this for now. Discussions about the first draft can be done here: #59

  12. linked a pull request that will close this issueCommandHandler #30on Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

question

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions