Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Rework context types (#153, solution 3) #243

Merged
merged 18 commits into from
Nov 22, 2022
Merged

Conversation

Nihlus
Copy link
Member

@Nihlus Nihlus commented Oct 15, 2022

This PR is a companion to #233, presenting the discussed third solution in the original issue. Since the issue was written, a number of architectural changes to interactivity have happened which render quite a few of the considerations moot. The end result is a far simpler and more workable implementation of streamlined contexts with richer data available to the end user.

In summary, the PR does two things:

One - it reworks the contexts into a set of interfaces and concrete types with the ability to distinguish between operations that are both commands and non-commands, providing detailed typesafe information about both cases.
image

Two - it reworks the execution flow of the message and interaction responders in order to simplify and streamline the procedure. Primarily, this means that pre- and post-execution events now run closer to the actual execution of the command itself and have full access to both the command node and its materialized parameters.

image

However, this does mean that pre- and post-execution events no longer run for events that fail to parse into executable commands, such as NotFound or ParsingError faults. This is a change from the previous behaviour, in which post-execution events would still run for these failure modes, and is one of the reasons this PR is marked as WIP.

I'd like to get some community feedback before I merge this, as it may mean previously supported code no longer works as expected. Please leaf through the diagrams and the code :)

@Nihlus Nihlus added the enhancement New feature or request label Oct 15, 2022
@Nihlus Nihlus self-assigned this Oct 15, 2022
@carlst99
Copy link
Contributor

Overall I think this is a great improvement! The only issue I have with this is not being able to detect command preparation errors. Nowadays with slash commands, it's less likely to be an issue. However, when using text commands I like to be able to inform the user when they've used a command incorrectly, or that it doesn't exist.
Personally, I don't mind if this isn't integrated with pre/post execution handlers. It looks to me like that might be troublesome. Simply being able to register a dedicated, context-aware handler for preparation errors would be enough.

@Nihlus
Copy link
Member Author

Nihlus commented Oct 19, 2022

That's definitely one solution I've considered. I'll let some more people chime in on their preferred solution before I do anything, though.

Copy link
Contributor

@VelvetToroyashi VelvetToroyashi left a comment

Choose a reason for hiding this comment

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

This PR is chonky due to the very broad scope of it, but I've done a skim over it, and see no real issues, except the aforementioned pre/post-execution one, but I believe I have a solution for that.

However, given the fundamental changes to how commands will be handled, I can only hope that an announcement will be made about this given how this is somewhat more than just "another breaking change".

@@ -38,7 +38,7 @@ public static class CustomIDHelpers
/// Gets the name used to build IDs for select menu components.
/// This may include text, role, channel etc. select menus.
/// </summary>
private const string SelectComponentName = "select-menu";
private const string _selectComponentName = "select-menu";
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this technically against the naming conventions for consts?

@VelvetToroyashi
Copy link
Contributor

One solution that may be more or less apt is instead of adding another handler and type to maintain, the ICommandContext parameter could be changed to be Optional<ICommandContext> (or one could be created from the available information, and the error would indicate that things like PreparredCommand would be unavailable), and the pre-execution check would be run regardless, though this obviously requires both noting this behavior somewhere in the code, and informing users of the behavior, which can and probably will increase complexity in user code, since error handling would be split between pre/post execution events, but for different reasons.

I suppose it's a tradeoff between complexity for us and complexity for "them" (the end-users).
If this idea seems utterly asinine, I apologize in advance; running on 4 hours of sleep isn't exactly beneficial to the mind.

@Nihlus
Copy link
Member Author

Nihlus commented Nov 21, 2022

Having had time to fiddle with this some more, what do we think of this flow?
image

@Nihlus
Copy link
Member Author

Nihlus commented Nov 21, 2022

Actually, here's a better one.

image

@Nihlus
Copy link
Member Author

Nihlus commented Nov 21, 2022

It is, of course, still up in the air if we want to have the default tree fallback functionality at all - I can do without it, personally.

@VelvetToroyashi
Copy link
Contributor

I can't say how often I've personally used it; it seems like a bit of a niche on top of a niche, however changing TreeNameResolver's API would be yet another breaking change.

@Nihlus
Copy link
Member Author

Nihlus commented Nov 21, 2022

To be fair, I did specify that it is up to the implementation if it wants to adhere to the AllowDefaultTree flag :P

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.

3 participants