Downgrade to v13

[vi] cảm giác đau khổ
This commit is contained in:
March 7th
2022-03-24 17:55:32 +07:00
parent 9596b1a210
commit 7dfdef46a5
218 changed files with 8584 additions and 9108 deletions

View File

@@ -2,7 +2,8 @@
const https = require('node:https');
const { setTimeout } = require('node:timers');
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
const FormData = require('form-data');
const fetch = require('node-fetch');
const { UserAgent } = require('../util/Constants');
let agent = null;
@@ -16,6 +17,9 @@ class APIRequest {
this.options = options;
this.retries = 0;
const { userAgentSuffix } = this.client.options;
this.fullUserAgent = `${UserAgent}${userAgentSuffix.length ? `, ${userAgentSuffix.join(', ')}` : ''}`;
let queryString = '';
if (options.query) {
const query = Object.entries(options.query)
@@ -26,7 +30,7 @@ class APIRequest {
this.path = `${path}${queryString && `?${queryString}`}`;
}
async make() {
make() {
agent ??= new https.Agent({ ...this.client.options.http.agent, keepAlive: true });
const API =
@@ -37,7 +41,7 @@ class APIRequest {
let headers = {
...this.client.options.http.headers,
'User-Agent': UserAgent,
'User-Agent': this.fullUserAgent,
};
if (this.options.auth !== false) headers.Authorization = this.rest.getAuth();
@@ -46,32 +50,23 @@ class APIRequest {
let body;
if (this.options.files?.length) {
body = new FormData();
for (const [index, file] of this.options.files.entries()) {
if (file?.file)
body.append(file.key ?? `files[${index}]`, file.file, file.name);
}
if (
typeof this.options.data !== 'undefined' ||
typeof this.options.body !== 'undefined'
) {
if (this.options.dontUsePayloadJSON) {
for (const [key, value] of Object.entries(this.options.data || this.options.body)) {
body.append(key, value);
}
} else {
body.append('payload_json', JSON.stringify(this.options.data || this.options.body));
}
}
headers = Object.assign(headers, body.getHeaders());
// eslint-disable-next-line eqeqeq
} else if (this.options.data != null) {
body = JSON.stringify(this.options.data);
headers['Content-Type'] = 'application/json';
} else if (this.options.body != null) {
body = JSON.stringify(this.options.body);
headers['Content-Type'] = 'application/json';
}
body = new FormData();
for (const [index, file] of this.options.files.entries()) {
if (file?.file) body.append(file.key ?? `files[${index}]`, file.file, file.name);
}
if (typeof this.options.data !== 'undefined') {
if (this.options.dontUsePayloadJSON) {
for (const [key, value] of Object.entries(this.options.data)) body.append(key, value);
} else {
body.append('payload_json', JSON.stringify(this.options.data));
}
}
headers = Object.assign(headers, body.getHeaders());
// eslint-disable-next-line eqeqeq
} else if (this.options.data != null) {
body = JSON.stringify(this.options.data);
headers['Content-Type'] = 'application/json';
}
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), this.client.options.restRequestTimeout).unref();
@@ -85,4 +80,4 @@ class APIRequest {
}
}
module.exports = APIRequest;
module.exports = APIRequest;

View File

@@ -50,4 +50,4 @@ function buildRoute(manager) {
return new Proxy(noop, handler);
}
module.exports = buildRoute;
module.exports = buildRoute;

View File

@@ -79,4 +79,4 @@ module.exports = DiscordAPIError;
/**
* @external APIError
* @see {@link https://discord.com/developers/docs/reference#error-messages}
*/
*/

View File

@@ -58,4 +58,4 @@ class HTTPError extends Error {
}
}
module.exports = HTTPError;
module.exports = HTTPError;

View File

@@ -29,9 +29,11 @@ class RESTManager {
}
getAuth() {
const token = this.client.token ?? this.client.accessToken;
if (token && !this.client.bot) return `${token}`;
else if(token && this.client.bot) return `Bot ${token}`;
if (this.client.token && this.client.user && this.client.user.bot) {
return `Bot ${this.client.token}`;
} else if (this.client.token) {
return this.client.token;
}
throw new Error('TOKEN_MISSING');
}
@@ -60,4 +62,4 @@ class RESTManager {
}
}
module.exports = RESTManager;
module.exports = RESTManager;

View File

@@ -52,4 +52,4 @@ class RateLimitError extends Error {
}
}
module.exports = RateLimitError;
module.exports = RateLimitError;

View File

@@ -376,4 +376,4 @@ module.exports = RequestHandler;
/**
* @external Response
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Response}
*/
*/