mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 04:23:31 +01:00
Add options.api_request_method
This commit is contained in:
@@ -2,6 +2,7 @@ const UserAgentManager = require('./UserAgentManager');
|
|||||||
const RESTMethods = require('./RESTMethods');
|
const RESTMethods = require('./RESTMethods');
|
||||||
const SequentialRequestHandler = require('./RequestHandlers/Sequential');
|
const SequentialRequestHandler = require('./RequestHandlers/Sequential');
|
||||||
const APIRequest = require('./APIRequest');
|
const APIRequest = require('./APIRequest');
|
||||||
|
const Constants = require('../../util/Constants');
|
||||||
|
|
||||||
class RESTManager {
|
class RESTManager {
|
||||||
|
|
||||||
@@ -23,11 +24,21 @@ class RESTManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getRequestHandler() {
|
||||||
|
switch (this.client.options.api_request_method) {
|
||||||
|
case 'sequential':
|
||||||
|
return SequentialRequestHandler;
|
||||||
|
default:
|
||||||
|
throw Constants.Errors.INVALID_RATE_LIMIT_METHOD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
makeRequest(method, url, auth, data, file) {
|
makeRequest(method, url, auth, data, file) {
|
||||||
const apiRequest = new APIRequest(this, method, url, auth, data, file);
|
const apiRequest = new APIRequest(this, method, url, auth, data, file);
|
||||||
|
|
||||||
if (!this.handlers[apiRequest.getEndpoint()]) {
|
if (!this.handlers[apiRequest.getEndpoint()]) {
|
||||||
this.handlers[apiRequest.getEndpoint()] = new SequentialRequestHandler(this);
|
const RequestHandlerType = this.getRequestHandler();
|
||||||
|
this.handlers[apiRequest.getEndpoint()] = new RequestHandlerType(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.push(this.handlers[apiRequest.getEndpoint()], apiRequest);
|
return this.push(this.handlers[apiRequest.getEndpoint()], apiRequest);
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ exports.DefaultOptions = {
|
|||||||
protocol_version: 6,
|
protocol_version: 6,
|
||||||
max_message_cache: 200,
|
max_message_cache: 200,
|
||||||
rest_ws_bridge_timeout: 5000,
|
rest_ws_bridge_timeout: 5000,
|
||||||
|
api_request_method: 'sequential',
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.Status = {
|
exports.Status = {
|
||||||
@@ -37,6 +38,7 @@ exports.Errors = {
|
|||||||
BAD_WS_MESSAGE: new Error('a bad message was received from the websocket - bad compression or not json'),
|
BAD_WS_MESSAGE: new Error('a bad message was received from the websocket - bad compression or not json'),
|
||||||
TOOK_TOO_LONG: new Error('something took too long to do'),
|
TOOK_TOO_LONG: new Error('something took too long to do'),
|
||||||
NOT_A_PERMISSION: new Error('that is not a valid permission number'),
|
NOT_A_PERMISSION: new Error('that is not a valid permission number'),
|
||||||
|
INVALID_RATE_LIMIT_METHOD: new Error('unknown rate limiting method'),
|
||||||
};
|
};
|
||||||
|
|
||||||
const API = 'https://discordapp.com/api';
|
const API = 'https://discordapp.com/api';
|
||||||
|
|||||||
Reference in New Issue
Block a user