Merge branch 'master' of https://github.com/discordjs/discord.js into node-fetch

This commit is contained in:
Will Nelson
2018-06-09 20:46:21 -07:00

View File

@@ -3,23 +3,19 @@ const APIRequest = require('./APIRequest');
const routeBuilder = require('./APIRouter');
const { Error } = require('../errors');
const { Endpoints } = require('../util/Constants');
const Collection = require('../util/Collection');
class RESTManager {
constructor(client, tokenPrefix = 'Bot') {
this.client = client;
this.handlers = {};
this.rateLimitedEndpoints = {};
this.handlers = new Collection();
this.globallyRateLimited = false;
this.tokenPrefix = tokenPrefix;
this.versioned = true;
this.timeDifferences = [];
if (client.options.restSweepInterval > 0) {
client.setInterval(() => {
for (const handler in this.handlers) {
if (this.handlers[handler]._inactive) {
delete this.handlers[handler];
}
}
this.handlers.sweep(handler => handler._inactive);
}, client.options.restSweepInterval * 1000);
}
}
@@ -69,11 +65,14 @@ class RESTManager {
request(method, url, options = {}) {
const apiRequest = new APIRequest(this, method, url, options);
if (!this.handlers[apiRequest.route]) {
this.handlers[apiRequest.route] = new handlers.RequestHandler(this, this.getRequestHandler());
let handler = this.handlers.get(apiRequest.route);
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) {