feature: Add support for setting X-RateLimit-Precision (#1354)
* support X-RateLimit-Reset sending integer or float values This changes the way that the X-RateLimit-Request header is parsed, so that it will work with both integer seconds and float values with seconds and milliseconds * Add RateLimitPrecision enum, set X-RateLimit-Precision Adds the RateLimitPrecision enum, with Second and Millisecond values. (Do we want to use an extension method to convert it into a string, or is ToString().ToLower() fine?) Adds RateLimitPrecision as a parameter to DiscordRestApiClient, and to DiscordConfig so that it can set the X-RateLimit-Precision header.
This commit is contained in:
committed by
Christopher F
parent
07f4d5f353
commit
9482204bcf
@@ -80,7 +80,8 @@ namespace Discord.WebSocket
|
||||
internal BaseSocketClient(DiscordSocketConfig config, DiscordRestApiClient client)
|
||||
: base(config, client) => BaseConfig = config;
|
||||
private static DiscordSocketApiClient CreateApiClient(DiscordSocketConfig config)
|
||||
=> new DiscordSocketApiClient(config.RestClientProvider, config.WebSocketProvider, DiscordRestConfig.UserAgent);
|
||||
=> new DiscordSocketApiClient(config.RestClientProvider, config.WebSocketProvider, DiscordRestConfig.UserAgent,
|
||||
rateLimitPrecision: config.RateLimitPrecision);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a Discord application information for the logged-in user.
|
||||
|
||||
@@ -85,7 +85,8 @@ namespace Discord.WebSocket
|
||||
}
|
||||
}
|
||||
private static API.DiscordSocketApiClient CreateApiClient(DiscordSocketConfig config)
|
||||
=> new API.DiscordSocketApiClient(config.RestClientProvider, config.WebSocketProvider, DiscordRestConfig.UserAgent);
|
||||
=> new API.DiscordSocketApiClient(config.RestClientProvider, config.WebSocketProvider, DiscordRestConfig.UserAgent,
|
||||
rateLimitPrecision: config.RateLimitPrecision);
|
||||
|
||||
internal override async Task OnLoginAsync(TokenType tokenType, string token)
|
||||
{
|
||||
|
||||
@@ -38,8 +38,9 @@ namespace Discord.API
|
||||
public ConnectionState ConnectionState { get; private set; }
|
||||
|
||||
public DiscordSocketApiClient(RestClientProvider restClientProvider, WebSocketProvider webSocketProvider, string userAgent,
|
||||
string url = null, RetryMode defaultRetryMode = RetryMode.AlwaysRetry, JsonSerializer serializer = null)
|
||||
: base(restClientProvider, userAgent, defaultRetryMode, serializer)
|
||||
string url = null, RetryMode defaultRetryMode = RetryMode.AlwaysRetry, JsonSerializer serializer = null,
|
||||
RateLimitPrecision rateLimitPrecision = RateLimitPrecision.Second)
|
||||
: base(restClientProvider, userAgent, defaultRetryMode, serializer, rateLimitPrecision)
|
||||
{
|
||||
_gatewayUrl = url;
|
||||
if (url != null)
|
||||
|
||||
@@ -176,7 +176,8 @@ namespace Discord.WebSocket
|
||||
_largeGuilds = new ConcurrentQueue<ulong>();
|
||||
}
|
||||
private static API.DiscordSocketApiClient CreateApiClient(DiscordSocketConfig config)
|
||||
=> new API.DiscordSocketApiClient(config.RestClientProvider, config.WebSocketProvider, DiscordRestConfig.UserAgent, config.GatewayHost);
|
||||
=> new API.DiscordSocketApiClient(config.RestClientProvider, config.WebSocketProvider, DiscordRestConfig.UserAgent, config.GatewayHost,
|
||||
rateLimitPrecision: config.RateLimitPrecision);
|
||||
/// <inheritdoc />
|
||||
internal override void Dispose(bool disposing)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user