snowtransfer
Advanced tools
Comparing version 0.5.2 to 0.5.3
@@ -39,14 +39,20 @@ "use strict"; | ||
set global(value) { | ||
if (value && this.globalReset) { | ||
if (value && this.globalReset !== 0) { | ||
if (this.globalResetTimeout) | ||
clearTimeout(this.globalResetTimeout); | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias | ||
const instance = this; | ||
this.globalResetTimeout = setTimeout(() => { | ||
this.globalResetTimeout = null; | ||
this.globalReset = 0; | ||
this.global = false; | ||
for (const bkt of Object.values(this.buckets)) { | ||
bkt.checkQueue(); | ||
} | ||
instance.global = false; | ||
}, this.globalReset); | ||
} | ||
else { | ||
if (this.globalResetTimeout) | ||
clearTimeout(this.globalResetTimeout); | ||
this.globalResetTimeout = null; | ||
this.globalReset = 0; | ||
for (const bkt of Object.values(this.buckets)) { | ||
bkt.checkQueue(); | ||
} | ||
} | ||
this._global = value; | ||
@@ -53,0 +59,0 @@ } |
@@ -97,9 +97,13 @@ "use strict"; | ||
if (request.statusCode === 429) { | ||
const b = JSON.parse(request.body.toString()); // Discord says it will be a JSON, so if there's an error, sucks | ||
if (b.reset_after) | ||
this.ratelimiter.globalReset = b.reset_after * 1000; | ||
if (b.global) | ||
this.ratelimiter.global = true; | ||
if (!this.ratelimiter.global) { | ||
const b = JSON.parse(request.body.toString()); // Discord says it will be a JSON, so if there's an error, sucks | ||
if (b.reset_after !== undefined) | ||
this.ratelimiter.globalReset = b.reset_after * 1000; | ||
else | ||
this.ratelimiter.globalReset = 1000; // Should realistically never happen, but you never know | ||
if (b.global !== undefined) | ||
this.ratelimiter.global = b.global; | ||
} | ||
this.emit("rateLimit", { timeout: bkt.reset, limit: bkt.limit, method: method, path: endpoint, route: this.ratelimiter.routify(endpoint, method) }); | ||
throw new DiscordAPIError(endpoint, b.message || "unknnown", method, request.statusCode); | ||
throw new DiscordAPIError(endpoint, "You're being ratelimited", method, request.statusCode); | ||
} | ||
@@ -106,0 +110,0 @@ this.emit("done", reqID, request); |
{ | ||
"name": "snowtransfer", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"description": "Minimalistic Rest client for the Discord Api", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
366792
7352