fix(commands): Fix handling of pulling context #335
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes an issue wherein Remora would not correctly pull from the context when resolving partial messages. This poses an issue where the user cannot access member information via the API (e.g., an HTTP bot).
The issue in question is that when presented with an
IPartialMessage
parameter, the parser will always attempt to resolve the message via REST, which, under normal circumstances would be fine; this is generally desirable behavior for text commands, but is detrimental to slash commands, and especially context menus where this is enforced (e.g., you must have the message parameter.)Regardless, there is a very simple fix, but before that I wanted to explain why this is an issue to being with.
The issue doesn't lie in the actual API logic, but the delegation to the "base" implementation of the class.
The reason this happens is because of type erasure; more specifically the
object
overloads on parsers, which are abstracted away byAbstractTypeParser<TParser>
, which is how this bug arose to begin with. Remora doesn't invoke the generic method at runtime despite Remora.Commands checking for parser types by the service-locator pattern, and instead invokes the type-erased method, which could really do anything.