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:
Cenk Ergen
2022-04-27 17:09:30 +03:00
committed by GitHub
parent 26c1a7e80f
commit 4ce1801bdf
7 changed files with 114 additions and 3 deletions

View File

@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading.Tasks;
namespace Discord.Rest
@@ -6,7 +8,7 @@ namespace Discord.Rest
/// <summary>
/// Represents a Rest based context of an <see cref="IDiscordInteraction"/>.
/// </summary>
public class RestInteractionContext<TInteraction> : IRestInteractionContext
public class RestInteractionContext<TInteraction> : IRestInteractionContext, IRouteMatchContainer
where TInteraction : RestInteraction
{
/// <summary>
@@ -45,6 +47,9 @@ namespace Discord.Rest
/// </remarks>
public Func<string, Task> InteractionResponseCallback { get; set; }
/// <inheritdoc cref="IRouteMatchContainer.SegmentMatches"/>
public IReadOnlyCollection<IRouteSegmentMatch> SegmentMatches { get; private set; }
/// <summary>
/// Initializes a new <see cref="RestInteractionContext{TInteraction}"/>.
/// </summary>
@@ -71,6 +76,13 @@ namespace Discord.Rest
InteractionResponseCallback = interactionResponseCallback;
}
/// <inheritdoc/>
public void SetSegmentMatches(IEnumerable<IRouteSegmentMatch> segmentMatches) => SegmentMatches = segmentMatches.ToImmutableArray();
//IRouteMatchContainer
/// <inheritdoc/>
IEnumerable<IRouteSegmentMatch> IRouteMatchContainer.SegmentMatches => SegmentMatches;
// IInterationContext
/// <inheritdoc/>
IDiscordClient IInteractionContext.Client => Client;