mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
remove ua manager (#2015)
This commit is contained in:
@@ -69,7 +69,6 @@
|
||||
"node-opus": false,
|
||||
"tweetnacl": false,
|
||||
"sodium": false,
|
||||
"src/rest/UserAgentManager.js": false,
|
||||
"src/sharding/Shard.js": false,
|
||||
"src/sharding/ShardClientUtil.js": false,
|
||||
"src/sharding/ShardingManager.js": false,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const querystring = require('querystring');
|
||||
const snekfetch = require('snekfetch');
|
||||
const https = require('https');
|
||||
const { browser } = require('../util/Constants');
|
||||
const { browser, UserAgent } = require('../util/Constants');
|
||||
|
||||
if (https.Agent) var agent = new https.Agent({ keepAlive: true });
|
||||
|
||||
@@ -28,7 +28,7 @@ class APIRequest {
|
||||
|
||||
if (this.options.auth !== false) request.set('Authorization', this.rest.getAuth());
|
||||
if (this.options.reason) request.set('X-Audit-Log-Reason', encodeURIComponent(this.options.reason));
|
||||
if (!browser) request.set('User-Agent', this.rest.userAgentManager.userAgent);
|
||||
if (!browser) request.set('User-Agent', UserAgent);
|
||||
if (this.options.headers) request.set(this.options.headers);
|
||||
|
||||
if (this.options.files) {
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
const UserAgentManager = require('./UserAgentManager');
|
||||
const handlers = require('./handlers');
|
||||
const APIRequest = require('./APIRequest');
|
||||
const routeBuilder = require('./APIRouter');
|
||||
const { Error } = require('../errors');
|
||||
const { Endpoints, browser } = require('../util/Constants');
|
||||
const { Endpoints } = require('../util/Constants');
|
||||
|
||||
class RESTManager {
|
||||
constructor(client, tokenPrefix = 'Bot') {
|
||||
this.client = client;
|
||||
this.handlers = {};
|
||||
if (!browser) this.userAgentManager = new UserAgentManager(this);
|
||||
this.rateLimitedEndpoints = {};
|
||||
this.globallyRateLimited = false;
|
||||
this.tokenPrefix = tokenPrefix;
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
const { Package } = require('../util/Constants');
|
||||
|
||||
class UserAgentManager {
|
||||
constructor() {
|
||||
this.build(this.constructor.DEFAULT);
|
||||
}
|
||||
|
||||
set({ url, version } = {}) {
|
||||
this.build({
|
||||
url: url || this.constructor.DFEAULT.url,
|
||||
version: version || this.constructor.DEFAULT.version,
|
||||
});
|
||||
}
|
||||
|
||||
build(ua) {
|
||||
this.userAgent = `DiscordBot (${ua.url}, ${ua.version}) Node.js/${process.version}`;
|
||||
}
|
||||
}
|
||||
|
||||
UserAgentManager.DEFAULT = {
|
||||
url: Package.homepage.split('#')[0],
|
||||
version: Package.version,
|
||||
};
|
||||
|
||||
module.exports = UserAgentManager;
|
||||
@@ -1,6 +1,6 @@
|
||||
exports.Package = require('../../package.json');
|
||||
const Package = exports.Package = require('../../package.json');
|
||||
const { Error, RangeError } = require('../errors');
|
||||
exports.browser = typeof window !== 'undefined';
|
||||
const browser = exports.browser = typeof window !== 'undefined';
|
||||
|
||||
/**
|
||||
* Options for a client.
|
||||
@@ -57,9 +57,9 @@ exports.DefaultOptions = {
|
||||
*/
|
||||
ws: {
|
||||
large_threshold: 250,
|
||||
compress: !exports.browser,
|
||||
compress: !browser,
|
||||
properties: {
|
||||
$os: exports.browser ? 'browser' : process.platform,
|
||||
$os: browser ? 'browser' : process.platform,
|
||||
$browser: 'discord.js',
|
||||
$device: 'discord.js',
|
||||
},
|
||||
@@ -82,6 +82,9 @@ exports.DefaultOptions = {
|
||||
},
|
||||
};
|
||||
|
||||
exports.UserAgent = browser ? null :
|
||||
`DiscordBot (${Package.homepage.split('#')[0]}, ${Package.version}) Node.js/${process.version}`;
|
||||
|
||||
exports.WSCodes = {
|
||||
1000: 'Connection gracefully closed',
|
||||
4004: 'Tried to identify with an invalid token',
|
||||
|
||||
Reference in New Issue
Block a user