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 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) {