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,11 +1,13 @@
using Discord.WebSocket;
using System.Collections.Generic;
using System.Collections.Immutable;
namespace Discord.Interactions
{
/// <summary>
/// Represents a Web-Socket based context of an <see cref="IDiscordInteraction"/>.
/// </summary>
public class SocketInteractionContext<TInteraction> : IInteractionContext
public class SocketInteractionContext<TInteraction> : IInteractionContext, IRouteMatchContainer
where TInteraction : SocketInteraction
{
/// <summary>
@@ -36,6 +38,9 @@ namespace Discord.Interactions
/// </summary>
public TInteraction Interaction { get; }
/// <inheritdoc cref="IRouteMatchContainer.SegmentMatches"/>
public IReadOnlyCollection<IRouteSegmentMatch> SegmentMatches { get; private set; }
/// <summary>
/// Initializes a new <see cref="SocketInteractionContext{TInteraction}"/>.
/// </summary>
@@ -50,6 +55,13 @@ namespace Discord.Interactions
Interaction = interaction;
}
/// <inheritdoc/>
public void SetSegmentMatches(IEnumerable<IRouteSegmentMatch> segmentMatches) => SegmentMatches = segmentMatches.ToImmutableArray();
//IRouteMatchContainer
/// <inheritdoc/>
IEnumerable<IRouteSegmentMatch> IRouteMatchContainer.SegmentMatches => SegmentMatches;
// IInteractionContext
/// <inheritdoc/>
IDiscordClient IInteractionContext.Client => Client;