Browse Source

Allow users to opt out of preemtive rate limiting

pull/759/head
Christopher F 8 years ago
parent
commit
d9f77651b1
2 changed files with 10 additions and 2 deletions
  1. +5
    -0
      src/Discord.Net.Core/RequestOptions.cs
  2. +5
    -2
      src/Discord.Net.Rest/Net/Queue/RequestQueueBucket.cs

+ 5
- 0
src/Discord.Net.Core/RequestOptions.cs View File

@@ -15,6 +15,11 @@ namespace Discord
public RetryMode? RetryMode { get; set; } public RetryMode? RetryMode { get; set; }
public bool HeaderOnly { get; internal set; } public bool HeaderOnly { get; internal set; }
/// <summary> /// <summary>
/// Should this request bypass the ratelimit buckets? This option should be used sparingly, and when used, should be coupled with your own
/// delays between requests, to avoid encountering 429 errors.
/// </summary>
public bool BypassBuckets { get; set; }
/// <summary>
/// The reason for this action in the guild's audit log /// The reason for this action in the guild's audit log
/// </summary> /// </summary>
public string AuditLogReason { get; set; } public string AuditLogReason { get; set; }


+ 5
- 2
src/Discord.Net.Rest/Net/Queue/RequestQueueBucket.cs View File

@@ -48,8 +48,11 @@ namespace Discord.Net.Queue
LastAttemptAt = DateTimeOffset.UtcNow; LastAttemptAt = DateTimeOffset.UtcNow;
while (true) while (true)
{ {
await _queue.EnterGlobalAsync(id, request).ConfigureAwait(false);
await EnterAsync(id, request).ConfigureAwait(false);
if (!request.Options.BypassBuckets)
{
await _queue.EnterGlobalAsync(id, request).ConfigureAwait(false);
await EnterAsync(id, request).ConfigureAwait(false);
}


#if DEBUG_LIMITS #if DEBUG_LIMITS
Debug.WriteLine($"[{id}] Sending..."); Debug.WriteLine($"[{id}] Sending...");


Loading…
Cancel
Save