feature: Passing CustomId matches into contexts (#2136)
* add logic for passing the wild card captures into the context * move concrete impl of IRouteSegmentMatch to internal * Apply suggestions from code review Co-authored-by: Quin Lynch <49576606+quinchs@users.noreply.github.com> * fix build errors * Apply suggestions from code review Co-authored-by: Armano den Boef <68127614+Rozen4334@users.noreply.github.com> Co-authored-by: Quin Lynch <49576606+quinchs@users.noreply.github.com> Co-authored-by: Armano den Boef <68127614+Rozen4334@users.noreply.github.com>
This commit is contained in:
@@ -775,6 +775,9 @@ namespace Discord.Interactions
|
||||
await _componentCommandExecutedEvent.InvokeAsync(null, context, result).ConfigureAwait(false);
|
||||
return result;
|
||||
}
|
||||
|
||||
SetMatchesIfApplicable(context, result);
|
||||
|
||||
return await result.Command.ExecuteAsync(context, services, result.RegexCaptureGroups).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
@@ -819,9 +822,25 @@ namespace Discord.Interactions
|
||||
await _componentCommandExecutedEvent.InvokeAsync(null, context, result).ConfigureAwait(false);
|
||||
return result;
|
||||
}
|
||||
|
||||
SetMatchesIfApplicable(context, result);
|
||||
|
||||
return await result.Command.ExecuteAsync(context, services, result.RegexCaptureGroups).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private static void SetMatchesIfApplicable<T>(IInteractionContext context, SearchResult<T> searchResult)
|
||||
where T : class, ICommandInfo
|
||||
{
|
||||
if (!searchResult.Command.SupportsWildCards || context is not IRouteMatchContainer matchContainer)
|
||||
return;
|
||||
|
||||
var matches = new RouteSegmentMatch[searchResult.RegexCaptureGroups.Length];
|
||||
for (var i = 0; i < searchResult.RegexCaptureGroups.Length; i++)
|
||||
matches[i] = new RouteSegmentMatch(searchResult.RegexCaptureGroups[i]);
|
||||
|
||||
matchContainer.SetSegmentMatches(matches);
|
||||
}
|
||||
|
||||
internal TypeConverter GetTypeConverter(Type type, IServiceProvider services = null)
|
||||
=> _typeConverterMap.Get(type, services);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user