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