Browse Source

feature: adjust the ratelimit for reactions

allows users to add reactions quickly
pull/1108/head
Christopher F 7 years ago
parent
commit
80b820c541
3 changed files with 9 additions and 1 deletions
  1. +2
    -1
      src/Discord.Net.Core/RequestOptions.cs
  2. +2
    -0
      src/Discord.Net.Rest/DiscordRestApiClient.cs
  3. +5
    -0
      src/Discord.Net.Rest/Net/Queue/RequestQueueBucket.cs

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

@@ -1,4 +1,4 @@
using System.Threading;
using System.Threading;

namespace Discord
{
@@ -22,6 +22,7 @@ namespace Discord
internal bool IgnoreState { get; set; }
internal string BucketId { get; set; }
internal bool IsClientBucket { get; set; }
internal bool IsReactionBucket { get; set; }

internal static RequestOptions CreateOrClone(RequestOptions options)
{


+ 2
- 0
src/Discord.Net.Rest/DiscordRestApiClient.cs View File

@@ -583,6 +583,7 @@ namespace Discord.API
Preconditions.NotNullOrWhitespace(emoji, nameof(emoji));

options = RequestOptions.CreateOrClone(options);
options.IsReactionBucket = true;

var ids = new BucketIds(channelId: channelId);

@@ -595,6 +596,7 @@ namespace Discord.API
Preconditions.NotNullOrWhitespace(emoji, nameof(emoji));

options = RequestOptions.CreateOrClone(options);
options.IsReactionBucket = true;

var ids = new BucketIds(channelId: channelId);



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

@@ -1,3 +1,4 @@
#define DEBUG_LIMITS
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
@@ -250,6 +251,10 @@ namespace Discord.Net.Queue
else if (info.Reset.HasValue)
{
resetTick = info.Reset.Value.AddSeconds(info.Lag?.TotalSeconds ?? 1.0);

if (request.Options.IsReactionBucket)
resetTick = new DateTimeOffset(resetTick.Value.Ticks / 4, TimeSpan.Zero);

int diff = (int)(resetTick.Value - DateTimeOffset.UtcNow).TotalMilliseconds;
#if DEBUG_LIMITS
Debug.WriteLine($"[{id}] X-RateLimit-Reset: {info.Reset.Value.ToUnixTimeSeconds()} ({diff} ms, {info.Lag?.TotalMilliseconds} ms lag)");


Loading…
Cancel
Save