mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +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 { 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) {
|
||||
|
||||
Reference in New Issue
Block a user