Skip to content

Commit

Permalink
misc: Change ratelimit messages (#1678)
Browse files Browse the repository at this point in the history
  • Loading branch information
SubZero0 authored Nov 15, 2020
1 parent be60d81 commit 47ed806
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/Discord.Net.Rest/BaseDiscordClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ internal BaseDiscordClient(DiscordRestConfig config, API.DiscordRestApiClient cl
_restLogger = LogManager.CreateLogger("Rest");
_isFirstLogin = config.DisplayInitialLog;

ApiClient.RequestQueue.RateLimitTriggered += async (id, info) =>
ApiClient.RequestQueue.RateLimitTriggered += async (id, info, endpoint) =>
{
if (info == null)
await _restLogger.VerboseAsync($"Preemptive Rate limit triggered: {id?.ToString() ?? "null"}").ConfigureAwait(false);
await _restLogger.VerboseAsync($"Preemptive Rate limit triggered: {endpoint} {(id.IsHashBucket ? $"(Bucket: {id.BucketHash})" : "")}").ConfigureAwait(false);
else
await _restLogger.WarningAsync($"Rate limit triggered: {id?.ToString() ?? "null"}").ConfigureAwait(false);
await _restLogger.WarningAsync($"Rate limit triggered: {endpoint} {(id.IsHashBucket ? $"(Bucket: {id.BucketHash})" : "")}").ConfigureAwait(false);
};
ApiClient.SentRequest += async (method, endpoint, millis) => await _restLogger.VerboseAsync($"{method} {endpoint}: {millis} ms").ConfigureAwait(false);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Discord.Net.Rest/Net/Queue/RequestQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Discord.Net.Queue
{
internal class RequestQueue : IDisposable
{
public event Func<BucketId, RateLimitInfo?, Task> RateLimitTriggered;
public event Func<BucketId, RateLimitInfo?, string, Task> RateLimitTriggered;

private readonly ConcurrentDictionary<BucketId, object> _buckets;
private readonly SemaphoreSlim _tokenLock;
Expand Down Expand Up @@ -121,9 +121,9 @@ private RequestBucket GetOrCreateBucket(RequestOptions options, RestRequest requ
}
return (RequestBucket)obj;
}
internal async Task RaiseRateLimitTriggered(BucketId bucketId, RateLimitInfo? info)
internal async Task RaiseRateLimitTriggered(BucketId bucketId, RateLimitInfo? info, string endpoint)
{
await RateLimitTriggered(bucketId, info).ConfigureAwait(false);
await RateLimitTriggered(bucketId, info, endpoint).ConfigureAwait(false);
}
internal (RequestBucket, BucketId) UpdateBucketHash(BucketId id, string discordHash)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Discord.Net.Rest/Net/Queue/RequestQueueBucket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public async Task<Stream> SendAsync(RestRequest request)
#endif
UpdateRateLimit(id, request, info, true);
}
await _queue.RaiseRateLimitTriggered(Id, info).ConfigureAwait(false);
await _queue.RaiseRateLimitTriggered(Id, info, $"{request.Method} {request.Endpoint}").ConfigureAwait(false);
continue; //Retry
case HttpStatusCode.BadGateway: //502
#if DEBUG_LIMITS
Expand Down Expand Up @@ -187,7 +187,7 @@ private async Task EnterAsync(int id, RestRequest request)
if (!isRateLimited)
{
isRateLimited = true;
await _queue.RaiseRateLimitTriggered(Id, null).ConfigureAwait(false);
await _queue.RaiseRateLimitTriggered(Id, null, $"{request.Method} {request.Endpoint}").ConfigureAwait(false);
}

ThrowRetryLimit(request);
Expand Down
6 changes: 3 additions & 3 deletions src/Discord.Net.Webhook/DiscordWebhookClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ private DiscordWebhookClient(DiscordRestConfig config)

_restLogger = LogManager.CreateLogger("Rest");

ApiClient.RequestQueue.RateLimitTriggered += async (id, info) =>
ApiClient.RequestQueue.RateLimitTriggered += async (id, info, endpoint) =>
{
if (info == null)
await _restLogger.VerboseAsync($"Preemptive Rate limit triggered: {id?.ToString() ?? "null"}").ConfigureAwait(false);
await _restLogger.VerboseAsync($"Preemptive Rate limit triggered: {endpoint} {(id.IsHashBucket ? $"(Bucket: {id.BucketHash})" : "")}").ConfigureAwait(false);
else
await _restLogger.WarningAsync($"Rate limit triggered: {id?.ToString() ?? "null"}").ConfigureAwait(false);
await _restLogger.WarningAsync($"Rate limit triggered: {endpoint} {(id.IsHashBucket ? $"(Bucket: {id.BucketHash})" : "")}").ConfigureAwait(false);
};
ApiClient.SentRequest += async (method, endpoint, millis) => await _restLogger.VerboseAsync($"{method} {endpoint}: {millis} ms").ConfigureAwait(false);
}
Expand Down

0 comments on commit 47ed806

Please sign in to comment.