Browse Source

Merged request BucketId and ClientBucketId. Added IsClientBucket.

tags/1.0-rc
RogueException 8 years ago
parent
commit
91e6cb98c3
3 changed files with 18 additions and 18 deletions
  1. +12
    -12
      src/Discord.Net.Core/API/DiscordRestApiClient.cs
  2. +5
    -5
      src/Discord.Net.Core/Net/Queue/RequestQueueBucket.cs
  3. +1
    -1
      src/Discord.Net.Core/RequestOptions.cs

+ 12
- 12
src/Discord.Net.Core/API/DiscordRestApiClient.cs View File

@@ -172,8 +172,8 @@ namespace Discord.API
{
options = options ?? new RequestOptions();
options.HeaderOnly = true;
options.BucketId = bucketId;
options.ClientBucketId = AuthTokenType == TokenType.User ? clientBucketId : null;
options.BucketId = AuthTokenType == TokenType.User ? clientBucketId : bucketId;
options.IsClientBucket = AuthTokenType == TokenType.User;

var request = new RestRequest(_restClient, method, endpoint, options);
await SendInternalAsync(method, endpoint, request).ConfigureAwait(false);
@@ -187,8 +187,8 @@ namespace Discord.API
{
options = options ?? new RequestOptions();
options.HeaderOnly = true;
options.BucketId = bucketId;
options.ClientBucketId = AuthTokenType == TokenType.User ? clientBucketId : null;
options.BucketId = AuthTokenType == TokenType.User ? clientBucketId : bucketId;
options.IsClientBucket = AuthTokenType == TokenType.User;

var json = payload != null ? SerializeJson(payload) : null;
var request = new JsonRestRequest(_restClient, method, endpoint, json, options);
@@ -203,8 +203,8 @@ namespace Discord.API
{
options = options ?? new RequestOptions();
options.HeaderOnly = true;
options.BucketId = bucketId;
options.ClientBucketId = AuthTokenType == TokenType.User ? clientBucketId : null;
options.BucketId = AuthTokenType == TokenType.User ? clientBucketId : bucketId;
options.IsClientBucket = AuthTokenType == TokenType.User;

var request = new MultipartRestRequest(_restClient, method, endpoint, multipartArgs, options);
await SendInternalAsync(method, endpoint, request).ConfigureAwait(false);
@@ -217,8 +217,8 @@ namespace Discord.API
string bucketId = null, string clientBucketId = null, RequestOptions options = null) where TResponse : class
{
options = options ?? new RequestOptions();
options.BucketId = bucketId;
options.ClientBucketId = AuthTokenType == TokenType.User ? clientBucketId : null;
options.BucketId = AuthTokenType == TokenType.User ? clientBucketId : bucketId;
options.IsClientBucket = AuthTokenType == TokenType.User;

var request = new RestRequest(_restClient, method, endpoint, options);
return DeserializeJson<TResponse>(await SendInternalAsync(method, endpoint, request).ConfigureAwait(false));
@@ -231,8 +231,8 @@ namespace Discord.API
string bucketId = null, string clientBucketId = null, RequestOptions options = null) where TResponse : class
{
options = options ?? new RequestOptions();
options.BucketId = bucketId;
options.ClientBucketId = AuthTokenType == TokenType.User ? clientBucketId : null;
options.BucketId = AuthTokenType == TokenType.User ? clientBucketId : bucketId;
options.IsClientBucket = AuthTokenType == TokenType.User;

var json = payload != null ? SerializeJson(payload) : null;
var request = new JsonRestRequest(_restClient, method, endpoint, json, options);
@@ -246,8 +246,8 @@ namespace Discord.API
string bucketId = null, string clientBucketId = null, RequestOptions options = null)
{
options = options ?? new RequestOptions();
options.BucketId = bucketId;
options.ClientBucketId = AuthTokenType == TokenType.User ? clientBucketId : null;
options.BucketId = AuthTokenType == TokenType.User ? clientBucketId : bucketId;
options.IsClientBucket = AuthTokenType == TokenType.User;

var request = new MultipartRestRequest(_restClient, method, endpoint, multipartArgs, options);
return DeserializeJson<TResponse>(await SendInternalAsync(method, endpoint, request).ConfigureAwait(false));


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

@@ -29,8 +29,8 @@ namespace Discord.Net.Queue

_lock = new object();

if (request.Options.ClientBucketId != null)
WindowCount = ClientBucket.Get(request.Options.ClientBucketId).WindowCount;
if (request.Options.IsClientBucket)
WindowCount = ClientBucket.Get(request.Options.BucketId).WindowCount;
else
WindowCount = 1; //Only allow one request until we get a header back
_semaphore = WindowCount;
@@ -218,11 +218,11 @@ namespace Discord.Net.Queue
Debug.WriteLine($"[{id}] X-RateLimit-Reset: {info.Reset.Value.ToUnixTimeSeconds()} ({diff} ms, {lag.TotalMilliseconds} ms lag)");
#endif
}
else if (request.Options.ClientBucketId != null)
else if (request.Options.IsClientBucket && request.Options.BucketId != null)
{
resetTick = DateTimeOffset.UtcNow.AddSeconds(ClientBucket.Get(request.Options.ClientBucketId).WindowSeconds);
resetTick = DateTimeOffset.UtcNow.AddSeconds(ClientBucket.Get(request.Options.BucketId).WindowSeconds);
#if DEBUG_LIMITS
Debug.WriteLine($"[{id}] Client Bucket ({ClientBucket.Get(request.Options.ClientBucketId).WindowSeconds * 1000} ms)");
Debug.WriteLine($"[{id}] Client Bucket ({ClientBucket.Get(request.Options.BucketId).WindowSeconds * 1000} ms)");
#endif
}



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

@@ -10,7 +10,7 @@

internal bool IgnoreState { get; set; }
internal string BucketId { get; set; }
internal string ClientBucketId { get; set; }
internal bool IsClientBucket { get; set; }

internal static RequestOptions CreateOrClone(RequestOptions options)
{


Loading…
Cancel
Save