@@ -36,6 +36,15 @@ namespace Discord | |||||
int Version { get; } | int Version { get; } | ||||
/// <summary> | /// <summary> | ||||
/// Gets whether or not this interaction has been responded to. | |||||
/// </summary> | |||||
/// <remarks> | |||||
/// This property is locally set -- if you're running multiple bots | |||||
/// off the same token then this property won't be in sync with them. | |||||
/// </remarks> | |||||
bool HasResponded { get; } | |||||
/// <summary> | |||||
/// Gets the user who invoked the interaction. | /// Gets the user who invoked the interaction. | ||||
/// </summary> | /// </summary> | ||||
IUser User { get; } | IUser User { get; } | ||||
@@ -32,9 +32,6 @@ namespace Discord.Rest | |||||
/// </summary> | /// </summary> | ||||
internal new RestCommandBaseData Data { get; private set; } | internal new RestCommandBaseData Data { get; private set; } | ||||
internal override bool _hasResponded { get; set; } | |||||
private object _lock = new object(); | private object _lock = new object(); | ||||
internal RestCommandBase(DiscordRestClient client, Model model) | internal RestCommandBase(DiscordRestClient client, Model model) | ||||
@@ -126,23 +123,15 @@ namespace Discord.Rest | |||||
lock (_lock) | lock (_lock) | ||||
{ | { | ||||
if (_hasResponded) | |||||
if (HasResponded) | |||||
{ | { | ||||
throw new InvalidOperationException("Cannot respond twice to the same interaction"); | throw new InvalidOperationException("Cannot respond twice to the same interaction"); | ||||
} | } | ||||
} | |||||
try | |||||
{ | |||||
return SerializePayload(response); | |||||
} | |||||
finally | |||||
{ | |||||
lock (_lock) | |||||
{ | |||||
_hasResponded = true; | |||||
} | |||||
HasResponded = true; | |||||
} | } | ||||
return SerializePayload(response); | |||||
} | } | ||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
@@ -317,15 +306,12 @@ namespace Discord.Rest | |||||
lock (_lock) | lock (_lock) | ||||
{ | { | ||||
if (_hasResponded) | |||||
if (HasResponded) | |||||
{ | { | ||||
throw new InvalidOperationException("Cannot respond or defer twice to the same interaction"); | throw new InvalidOperationException("Cannot respond or defer twice to the same interaction"); | ||||
} | } | ||||
} | |||||
lock (_lock) | |||||
{ | |||||
_hasResponded = true; | |||||
HasResponded = true; | |||||
} | } | ||||
return SerializePayload(response); | return SerializePayload(response); | ||||
@@ -26,7 +26,6 @@ namespace Discord.Rest | |||||
public RestUserMessage Message { get; private set; } | public RestUserMessage Message { get; private set; } | ||||
private object _lock = new object(); | private object _lock = new object(); | ||||
internal override bool _hasResponded { get; set; } = false; | |||||
internal RestMessageComponent(BaseDiscordClient client, Model model) | internal RestMessageComponent(BaseDiscordClient client, Model model) | ||||
: base(client, model.Id) | : base(client, model.Id) | ||||
@@ -128,15 +127,12 @@ namespace Discord.Rest | |||||
lock (_lock) | lock (_lock) | ||||
{ | { | ||||
if (_hasResponded) | |||||
if (HasResponded) | |||||
{ | { | ||||
throw new InvalidOperationException("Cannot respond, update, or defer twice to the same interaction"); | throw new InvalidOperationException("Cannot respond, update, or defer twice to the same interaction"); | ||||
} | } | ||||
} | |||||
lock (_lock) | |||||
{ | |||||
_hasResponded = true; | |||||
HasResponded = true; | |||||
} | } | ||||
return SerializePayload(response); | return SerializePayload(response); | ||||
@@ -223,15 +219,12 @@ namespace Discord.Rest | |||||
lock (_lock) | lock (_lock) | ||||
{ | { | ||||
if (_hasResponded) | |||||
if (HasResponded) | |||||
{ | { | ||||
throw new InvalidOperationException("Cannot respond, update, or defer twice to the same interaction"); | throw new InvalidOperationException("Cannot respond, update, or defer twice to the same interaction"); | ||||
} | } | ||||
} | |||||
lock (_lock) | |||||
{ | |||||
_hasResponded = true; | |||||
HasResponded = true; | |||||
} | } | ||||
return SerializePayload(response); | return SerializePayload(response); | ||||
@@ -408,15 +401,12 @@ namespace Discord.Rest | |||||
lock (_lock) | lock (_lock) | ||||
{ | { | ||||
if (_hasResponded) | |||||
if (HasResponded) | |||||
{ | { | ||||
throw new InvalidOperationException("Cannot respond or defer twice to the same interaction"); | throw new InvalidOperationException("Cannot respond or defer twice to the same interaction"); | ||||
} | } | ||||
} | |||||
lock (_lock) | |||||
{ | |||||
_hasResponded = true; | |||||
HasResponded = true; | |||||
} | } | ||||
return SerializePayload(response); | return SerializePayload(response); | ||||
@@ -445,15 +435,12 @@ namespace Discord.Rest | |||||
lock (_lock) | lock (_lock) | ||||
{ | { | ||||
if (_hasResponded) | |||||
if (HasResponded) | |||||
{ | { | ||||
throw new InvalidOperationException("Cannot respond or defer twice to the same interaction"); | throw new InvalidOperationException("Cannot respond or defer twice to the same interaction"); | ||||
} | } | ||||
} | |||||
lock (_lock) | |||||
{ | |||||
_hasResponded = true; | |||||
HasResponded = true; | |||||
} | } | ||||
return SerializePayload(response); | return SerializePayload(response); | ||||
@@ -35,8 +35,6 @@ namespace Discord.Rest | |||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
public DateTimeOffset CreatedAt { get; private set; } | public DateTimeOffset CreatedAt { get; private set; } | ||||
internal abstract bool _hasResponded { get; set; } | |||||
/// <summary> | /// <summary> | ||||
/// <see langword="true"/> if the token is valid for replying to, otherwise <see langword="false"/>. | /// <see langword="true"/> if the token is valid for replying to, otherwise <see langword="false"/>. | ||||
/// </summary> | /// </summary> | ||||
@@ -53,6 +51,9 @@ namespace Discord.Rest | |||||
/// </summary> | /// </summary> | ||||
public RestGuild Guild { get; private set; } | public RestGuild Guild { get; private set; } | ||||
/// <inheritdoc/> | |||||
public bool HasResponded { get; protected set; } | |||||
internal RestInteraction(BaseDiscordClient discord, ulong id) | internal RestInteraction(BaseDiscordClient discord, ulong id) | ||||
: base(discord, id) | : base(discord, id) | ||||
{ | { | ||||
@@ -13,8 +13,6 @@ namespace Discord.Rest | |||||
/// </summary> | /// </summary> | ||||
public class RestPingInteraction : RestInteraction, IDiscordInteraction | public class RestPingInteraction : RestInteraction, IDiscordInteraction | ||||
{ | { | ||||
internal override bool _hasResponded { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } | |||||
internal RestPingInteraction(BaseDiscordClient client, ulong id) | internal RestPingInteraction(BaseDiscordClient client, ulong id) | ||||
: base(client, id) | : base(client, id) | ||||
{ | { | ||||
@@ -19,7 +19,6 @@ namespace Discord.Rest | |||||
/// </summary> | /// </summary> | ||||
public new RestAutocompleteInteractionData Data { get; } | public new RestAutocompleteInteractionData Data { get; } | ||||
internal override bool _hasResponded { get; set; } | |||||
private object _lock = new object(); | private object _lock = new object(); | ||||
internal RestAutocompleteInteraction(DiscordRestClient client, Model model) | internal RestAutocompleteInteraction(DiscordRestClient client, Model model) | ||||
@@ -61,15 +60,12 @@ namespace Discord.Rest | |||||
lock (_lock) | lock (_lock) | ||||
{ | { | ||||
if (_hasResponded) | |||||
if (HasResponded) | |||||
{ | { | ||||
throw new InvalidOperationException("Cannot respond twice to the same interaction"); | throw new InvalidOperationException("Cannot respond twice to the same interaction"); | ||||
} | } | ||||
} | |||||
lock (_lock) | |||||
{ | |||||
_hasResponded = true; | |||||
HasResponded = true; | |||||
} | } | ||||
var model = new API.InteractionResponse | var model = new API.InteractionResponse | ||||
@@ -411,11 +411,7 @@ namespace Discord.WebSocket | |||||
} | } | ||||
await Discord.Rest.ApiClient.CreateInteractionResponseAsync(response, Id, Token, options).ConfigureAwait(false); | await Discord.Rest.ApiClient.CreateInteractionResponseAsync(response, Id, Token, options).ConfigureAwait(false); | ||||
lock (_lock) | |||||
{ | |||||
HasResponded = true; | |||||
} | |||||
HasResponded = true; | |||||
} | } | ||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
@@ -439,11 +435,7 @@ namespace Discord.WebSocket | |||||
} | } | ||||
await Discord.Rest.ApiClient.CreateInteractionResponseAsync(response, Id, Token, options).ConfigureAwait(false); | await Discord.Rest.ApiClient.CreateInteractionResponseAsync(response, Id, Token, options).ConfigureAwait(false); | ||||
lock (_lock) | |||||
{ | |||||
HasResponded = true; | |||||
} | |||||
HasResponded = true; | |||||
} | } | ||||
//IComponentInteraction | //IComponentInteraction | ||||
@@ -318,11 +318,7 @@ namespace Discord.WebSocket | |||||
} | } | ||||
await Discord.Rest.ApiClient.CreateInteractionResponseAsync(response, Id, Token, options).ConfigureAwait(false); | await Discord.Rest.ApiClient.CreateInteractionResponseAsync(response, Id, Token, options).ConfigureAwait(false); | ||||
lock (_lock) | |||||
{ | |||||
HasResponded = true; | |||||
} | |||||
HasResponded = true; | |||||
} | } | ||||
} | } | ||||
} | } |