Skip to content

Rewrite Commands #10

@HelpfulStranger999

Description

@HelpfulStranger999

In its current state, commands are fairly fragile and violate the SOLID principle. The open-closed principle states that classes should be open to extension while being closed for modification when it comes to altering behavior. Bug fixes are not an example of violating the open-closed principle, but adding a new command does. To add a new command, you must add one function that checks if the twitch client private variables have been initialized and if not initializes them, then calls another function that actually is the heart of the command logic. In addition to requiring modification, this design violates the Single responsibility pattern, which states that each class should focus on doing one thing. This class focuses on doing all of the commands. I would argue that this class should be rewritten.

I propose a structure similar to the Discord.NET commands library. We could define an interface for a basic command structure, maybe building in permissions as well and argument parsing. Each command can implement this interface. For injecting the twitch client we can use dependency injection. The commands logic can be overhauled to find all classes that implement this interface using reflection. On a command message sent, it can then create all classes and inject any requested dependencies using reflection, then call the various functions of the interfaces as needed. This new structure would make all the involved classes significantly less fragile, follow the SOLID principles better, and make it easier for eventual unit testing and integration testing etc.

For other bot features, the command class would likely be refactored extensively to avoid repeating logic, like for when rotating the shop hooks directly to the pubsub event.

Does this make sense to everyone? Does anyone have any thoughts on this proposition?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions