You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
As it is now, we only have a singular command: /create-cookie. While future commands aren't specifically planned out, they are desired. Right now we hardcode the first command id returned from the Discord API and check if the command id matches the interaction id.
Describe the solution you'd like
Instead of hardcoding the functionality for a singular command, I'd prefer to use reflection or possibly source generation to auto-register the commands on startup. Ideally we'd pass the command id from the interaction, index from a frozen dictionary and execute a static delegate which returns an IResponse, however depending on the feature/command added we may have to make room for object initialization via dependency injection. Additionally, if we add multiple commands, we would have to provide a way to pass the command name and short description, optimistically with translations available. I propose an interface like the following:
With this design, I chose to forsake the static modifer and instead opt to initialize the ICommand as a singleton and then pass the ExecuteAsync method to the FrozenDictionary as a delegate. By creating the object, this allows us to use dependency injection to grab the logger or load translations from an external file.
Error handling inside the command handler is to be decided. I'll likely embed the error handling logic inside of the commands themselves, or maybe I'll add another method to the interface:
I forgot to mention that this comes at the cost of having to fully implement the Discord entities we choose to use. We can either switch to a Discord library that allows for external deserialization (possibly Remora or Starnight) or continue to create the entities ourselves.
Is your feature request related to a problem? Please describe.
As it is now, we only have a singular command:
/create-cookie
. While future commands aren't specifically planned out, they are desired. Right now we hardcode the first command id returned from the Discord API and check if the command id matches the interaction id.Registration:
CookieClicker/src/DiscordSlashCommandHandler.cs
Lines 51 to 52 in 3ff3469
Execution:
CookieClicker/src/Routes/Create.cs
Lines 47 to 55 in 3ff3469
Describe the solution you'd like
Instead of hardcoding the functionality for a singular command, I'd prefer to use reflection or possibly source generation to auto-register the commands on startup. Ideally we'd pass the command id from the interaction, index from a frozen dictionary and execute a static delegate which returns an
IResponse
, however depending on the feature/command added we may have to make room for object initialization via dependency injection. Additionally, if we add multiple commands, we would have to provide a way to pass the command name and short description, optimistically with translations available. I propose an interface like the following:With this design, I chose to forsake the
static
modifer and instead opt to initialize theICommand
as a singleton and then pass theExecuteAsync
method to theFrozenDictionary
as a delegate. By creating the object, this allows us to use dependency injection to grab the logger or load translations from an external file.Error handling inside the command handler is to be decided. I'll likely embed the error handling logic inside of the commands themselves, or maybe I'll add another method to the interface:
Describe alternatives you've considered
I am not using a switch case for this.
The text was updated successfully, but these errors were encountered: