Remora / Remora.Discord

A data-oriented C# Discord library, focused on high-performance concurrency and robust design.
GNU Lesser General Public License v3.0
243 stars 46 forks source link

fix(commands): Fix handling of pulling context #335

Closed VelvetToroyashi closed 5 months ago

VelvetToroyashi commented 5 months ago

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 by AbstractTypeParser<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.