mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 19:43:29 +01:00
Merge branch 'master' of https://github.com/discordjs/discord.js into node-fetch
This commit is contained in:
@@ -3,23 +3,19 @@ const APIRequest = require('./APIRequest');
|
|||||||
const routeBuilder = require('./APIRouter');
|
const routeBuilder = require('./APIRouter');
|
||||||
const { Error } = require('../errors');
|
const { Error } = require('../errors');
|
||||||
const { Endpoints } = require('../util/Constants');
|
const { Endpoints } = require('../util/Constants');
|
||||||
|
const Collection = require('../util/Collection');
|
||||||
|
|
||||||
class RESTManager {
|
class RESTManager {
|
||||||
constructor(client, tokenPrefix = 'Bot') {
|
constructor(client, tokenPrefix = 'Bot') {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.handlers = {};
|
this.handlers = new Collection();
|
||||||
this.rateLimitedEndpoints = {};
|
|
||||||
this.globallyRateLimited = false;
|
this.globallyRateLimited = false;
|
||||||
this.tokenPrefix = tokenPrefix;
|
this.tokenPrefix = tokenPrefix;
|
||||||
this.versioned = true;
|
this.versioned = true;
|
||||||
this.timeDifferences = [];
|
this.timeDifferences = [];
|
||||||
if (client.options.restSweepInterval > 0) {
|
if (client.options.restSweepInterval > 0) {
|
||||||
client.setInterval(() => {
|
client.setInterval(() => {
|
||||||
for (const handler in this.handlers) {
|
this.handlers.sweep(handler => handler._inactive);
|
||||||
if (this.handlers[handler]._inactive) {
|
|
||||||
delete this.handlers[handler];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, client.options.restSweepInterval * 1000);
|
}, client.options.restSweepInterval * 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -69,11 +65,14 @@ class RESTManager {
|
|||||||
|
|
||||||
request(method, url, options = {}) {
|
request(method, url, options = {}) {
|
||||||
const apiRequest = new APIRequest(this, method, url, options);
|
const apiRequest = new APIRequest(this, method, url, options);
|
||||||
if (!this.handlers[apiRequest.route]) {
|
let handler = this.handlers.get(apiRequest.route);
|
||||||
this.handlers[apiRequest.route] = new handlers.RequestHandler(this, this.getRequestHandler());
|
|
||||||
|
if (!handler) {
|
||||||
|
handler = new handlers.RequestHandler(this, this.getRequestHandler());
|
||||||
|
this.handlers.set(apiRequest.route, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.push(this.handlers[apiRequest.route], apiRequest);
|
return this.push(handler, apiRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
set endpoint(endpoint) {
|
set endpoint(endpoint) {
|
||||||
|
|||||||
Reference in New Issue
Block a user