Skip to content

Commit

Permalink
More generous reset time on reaction ratelimits
Browse files Browse the repository at this point in the history
  • Loading branch information
abalabahaha committed Oct 15, 2017
1 parent c691282 commit 94c0767
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/rest/RequestHandler.js
Expand Up @@ -169,8 +169,9 @@ class RequestHandler {
this.latencyRef.raw.push(latency);
this.latencyRef.latency = ~~(this.latencyRef.latency - this.latencyRef.raw.shift() / 10 + latency / 10);

var headerNow = Date.parse(resp.headers["date"]);
if(this.latencyRef.lastTimeOffsetCheck < Date.now() - 5000) {
var timeOffset = ~~((this.latencyRef.lastTimeOffsetCheck = Date.now()) - Date.parse(resp.headers["date"]));
var timeOffset = ~~((this.latencyRef.lastTimeOffsetCheck = Date.now()) - headerNow);
if(this.latencyRef.timeOffset - this.latencyRef.latency >= this._client.options.latencyThreshold && timeOffset - this.latencyRef.latency >= this._client.options.latencyThreshold) {
this._client.emit("error", new Error(`Your clock is ${this.latencyRef.timeOffset}ms behind Discord's server clock. Please check your connection and system time.`));
}
Expand Down Expand Up @@ -218,8 +219,9 @@ class RequestHandler {
this.ratelimits[route].reset = (+resp.headers["retry-after"] || 1) + now;
}
} else if(resp.headers["x-ratelimit-reset"]) {
if(route.endsWith("/reactions/:id")) {
this.ratelimits[route].reset = now + Math.max(this.latencyRef.timeOffset, 250);
console.log(+resp.headers["x-ratelimit-reset"] * 1000, headerNow, +resp.headers["x-ratelimit-reset"] * 1000 - headerNow)
if((~route.lastIndexOf("/reactions/:id")) && (+resp.headers["x-ratelimit-reset"] * 1000 - headerNow) === 1000) {
this.ratelimits[route].reset = Math.max(now + 250 - this.latencyRef.timeOffset, now);
} else {
this.ratelimits[route].reset = Math.max(+resp.headers["x-ratelimit-reset"] * 1000 - this.latencyRef.timeOffset, now);
}
Expand Down

0 comments on commit 94c0767

Please sign in to comment.