[Feature] Config Bypass for CanSendResponse (#2932)

* Adds bool switch for DeferAsyncTimeCheck in DiscordConfig

* Adds DeferAsyncTimeCheck bool to DiscordSocketClient

* Adds DeferAsyncTimeCheck to DeferAsync in SocketCommandBase

* Adds DeferAsyncTimeCheck to DeferAsync in SocketModal

* Adds DeferAsyncTimeCheck to DeferAsync in SocketMessageComponent

* Changes name of DeferAsyncTimeCheck to be more general

* Moves ResponseInternalTimeCheck from socket client to base client

* Adds ResponseInternalTimeCheck to Rest interactions

* Adds ResponseInternalTimeCheck to socket interactions
This commit is contained in:
Bence Szucs
2024-05-16 17:25:21 -04:00
committed by GitHub
parent aa424f6f37
commit 9030a5b2bb
10 changed files with 39 additions and 29 deletions

View File

@@ -45,6 +45,7 @@ namespace Discord.Rest
public TokenType TokenType => ApiClient.AuthTokenType;
internal bool UseInteractionSnowflakeDate { get; private set; }
internal bool FormatUsersInBidirectionalUnicode { get; private set; }
internal bool ResponseInternalTimeCheck { get; private set; }
/// <summary> Creates a new REST-only Discord client. </summary>
internal BaseDiscordClient(DiscordRestConfig config, API.DiscordRestApiClient client)
@@ -59,6 +60,7 @@ namespace Discord.Rest
UseInteractionSnowflakeDate = config.UseInteractionSnowflakeDate;
FormatUsersInBidirectionalUnicode = config.FormatUsersInBidirectionalUnicode;
ResponseInternalTimeCheck = config.ResponseInternalTimeCheck;
ApiClient.RequestQueue.RateLimitTriggered += async (id, info, endpoint) =>
{

View File

@@ -86,7 +86,7 @@ namespace Discord.Rest
if (!IsValidToken)
throw new InvalidOperationException("Interaction token is no longer valid");
if (!InteractionHelper.CanSendResponse(this))
if (!InteractionHelper.CanSendResponse(this) && Discord.ResponseInternalTimeCheck)
throw new TimeoutException($"Cannot respond to an interaction after {InteractionHelper.ResponseTimeLimit} seconds!");
embeds ??= Array.Empty<Embed>();
@@ -317,7 +317,7 @@ namespace Discord.Rest
/// </returns>
public override string Defer(bool ephemeral = false, RequestOptions options = null)
{
if (!InteractionHelper.CanSendResponse(this))
if (!InteractionHelper.CanSendResponse(this) && Discord.ResponseInternalTimeCheck)
throw new TimeoutException($"Cannot defer an interaction after {InteractionHelper.ResponseTimeLimit} seconds!");
var response = new API.InteractionResponse
@@ -352,7 +352,7 @@ namespace Discord.Rest
/// <exception cref="InvalidOperationException"></exception>
public override string RespondWithModal(Modal modal, RequestOptions options = null)
{
if (!InteractionHelper.CanSendResponse(this))
if (!InteractionHelper.CanSendResponse(this) && Discord.ResponseInternalTimeCheck)
throw new TimeoutException($"Cannot defer an interaction after {InteractionHelper.ResponseTimeLimit} seconds of no response/acknowledgement");
var response = new API.InteractionResponse

View File

@@ -82,7 +82,7 @@ namespace Discord.Rest
if (!IsValidToken)
throw new InvalidOperationException("Interaction token is no longer valid");
if (!InteractionHelper.CanSendResponse(this))
if (!InteractionHelper.CanSendResponse(this) && Discord.ResponseInternalTimeCheck)
throw new TimeoutException($"Cannot respond to an interaction after {InteractionHelper.ResponseTimeLimit} seconds!");
embeds ??= Array.Empty<Embed>();
@@ -153,7 +153,7 @@ namespace Discord.Rest
if (!IsValidToken)
throw new InvalidOperationException("Interaction token is no longer valid");
if (!InteractionHelper.CanSendResponse(this))
if (!InteractionHelper.CanSendResponse(this) && Discord.ResponseInternalTimeCheck)
throw new TimeoutException($"Cannot respond to an interaction after {InteractionHelper.ResponseTimeLimit} seconds!");
if (args.AllowedMentions.IsSpecified)
@@ -424,7 +424,7 @@ namespace Discord.Rest
/// </returns>
public string DeferLoading(bool ephemeral = false, RequestOptions options = null)
{
if (!InteractionHelper.CanSendResponse(this))
if (!InteractionHelper.CanSendResponse(this) && Discord.ResponseInternalTimeCheck)
throw new TimeoutException($"Cannot defer an interaction after {InteractionHelper.ResponseTimeLimit} seconds of no response/acknowledgement");
var response = new API.InteractionResponse
@@ -458,7 +458,7 @@ namespace Discord.Rest
/// <exception cref="InvalidOperationException"></exception>
public override string Defer(bool ephemeral = false, RequestOptions options = null)
{
if (!InteractionHelper.CanSendResponse(this))
if (!InteractionHelper.CanSendResponse(this) && Discord.ResponseInternalTimeCheck)
throw new TimeoutException($"Cannot defer an interaction after {InteractionHelper.ResponseTimeLimit} seconds of no response/acknowledgement");
var response = new API.InteractionResponse
@@ -490,7 +490,7 @@ namespace Discord.Rest
/// <exception cref="InvalidOperationException"></exception>
public override string RespondWithModal(Modal modal, RequestOptions options = null)
{
if (!InteractionHelper.CanSendResponse(this))
if (!InteractionHelper.CanSendResponse(this) && Discord.ResponseInternalTimeCheck)
throw new TimeoutException($"Cannot defer an interaction after {InteractionHelper.ResponseTimeLimit} seconds of no response/acknowledgement");
var response = new API.InteractionResponse

View File

@@ -51,7 +51,7 @@ namespace Discord.Rest
/// </returns>
public override string Defer(bool ephemeral = false, RequestOptions options = null)
{
if (!InteractionHelper.CanSendResponse(this))
if (!InteractionHelper.CanSendResponse(this) && Discord.ResponseInternalTimeCheck)
throw new TimeoutException($"Cannot defer an interaction after {InteractionHelper.ResponseTimeLimit} seconds!");
var response = new API.InteractionResponse
@@ -91,7 +91,7 @@ namespace Discord.Rest
/// </returns>
public string DeferLoading(bool ephemeral = false, RequestOptions options = null)
{
if (!InteractionHelper.CanSendResponse(this))
if (!InteractionHelper.CanSendResponse(this) && Discord.ResponseInternalTimeCheck)
throw new TimeoutException($"Cannot defer an interaction after {InteractionHelper.ResponseTimeLimit} seconds of no response/acknowledgement");
var response = new API.InteractionResponse
@@ -320,7 +320,7 @@ namespace Discord.Rest
if (!IsValidToken)
throw new InvalidOperationException("Interaction token is no longer valid");
if (!InteractionHelper.CanSendResponse(this))
if (!InteractionHelper.CanSendResponse(this) && Discord.ResponseInternalTimeCheck)
throw new TimeoutException($"Cannot respond to an interaction after {InteractionHelper.ResponseTimeLimit} seconds!");
embeds ??= Array.Empty<Embed>();
@@ -486,7 +486,7 @@ namespace Discord.Rest
if (!IsValidToken)
throw new InvalidOperationException("Interaction token is no longer valid");
if (!InteractionHelper.CanSendResponse(this))
if (!InteractionHelper.CanSendResponse(this) && Discord.ResponseInternalTimeCheck)
throw new TimeoutException($"Cannot respond to an interaction after {InteractionHelper.ResponseTimeLimit} seconds!");
if (args.AllowedMentions.IsSpecified)

View File

@@ -55,7 +55,7 @@ namespace Discord.Rest
/// </returns>
public string Respond(IEnumerable<AutocompleteResult> result, RequestOptions options = null)
{
if (!InteractionHelper.CanSendResponse(this))
if (!InteractionHelper.CanSendResponse(this) && Discord.ResponseInternalTimeCheck)
throw new TimeoutException($"Cannot respond to an interaction after {InteractionHelper.ResponseTimeLimit} seconds!");
lock (_lock)