mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 18:13:29 +01:00
chore: consistency/prettier (#3852)
* chore: consistency/prettier * chore: rebase * chore: rebase * chore: include typings * fix: include typings file in prettier lint-staged
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
const FormData = require('form-data');
|
||||
const https = require('https');
|
||||
const { browser, UserAgent } = require('../util/Constants');
|
||||
const fetch = require('node-fetch');
|
||||
const AbortController = require('abort-controller');
|
||||
const FormData = require('form-data');
|
||||
const fetch = require('node-fetch');
|
||||
const { browser, UserAgent } = require('../util/Constants');
|
||||
|
||||
if (https.Agent) var agent = new https.Agent({ keepAlive: true });
|
||||
|
||||
@@ -26,8 +26,10 @@ class APIRequest {
|
||||
}
|
||||
|
||||
make() {
|
||||
const API = this.options.versioned === false ? this.client.options.http.api :
|
||||
`${this.client.options.http.api}/v${this.client.options.http.version}`;
|
||||
const API =
|
||||
this.options.versioned === false
|
||||
? this.client.options.http.api
|
||||
: `${this.client.options.http.api}/v${this.client.options.http.version}`;
|
||||
const url = API + this.path;
|
||||
let headers = {};
|
||||
|
||||
@@ -42,7 +44,8 @@ class APIRequest {
|
||||
for (const file of this.options.files) if (file && file.file) body.append(file.name, file.file, file.name);
|
||||
if (typeof this.options.data !== 'undefined') body.append('payload_json', JSON.stringify(this.options.data));
|
||||
if (!browser) headers = Object.assign(headers, body.getHeaders());
|
||||
} else if (this.options.data != null) { // eslint-disable-line eqeqeq
|
||||
// eslint-disable-next-line eqeqeq
|
||||
} else if (this.options.data != null) {
|
||||
body = JSON.stringify(this.options.data);
|
||||
headers['Content-Type'] = 'application/json';
|
||||
}
|
||||
|
||||
@@ -3,8 +3,12 @@
|
||||
const noop = () => {}; // eslint-disable-line no-empty-function
|
||||
const methods = ['get', 'post', 'delete', 'patch', 'put'];
|
||||
const reflectors = [
|
||||
'toString', 'valueOf', 'inspect', 'constructor',
|
||||
Symbol.toPrimitive, Symbol.for('nodejs.util.inspect.custom'),
|
||||
'toString',
|
||||
'valueOf',
|
||||
'inspect',
|
||||
'constructor',
|
||||
Symbol.toPrimitive,
|
||||
Symbol.for('nodejs.util.inspect.custom'),
|
||||
];
|
||||
|
||||
function buildRoute(manager) {
|
||||
@@ -22,10 +26,18 @@ function buildRoute(manager) {
|
||||
// All other parts of the route should be considered as part of the bucket identifier
|
||||
else routeBucket.push(route[i]);
|
||||
}
|
||||
return options => manager.request(name, route.join('/'), Object.assign({
|
||||
versioned: manager.versioned,
|
||||
route: routeBucket.join('/'),
|
||||
}, options));
|
||||
return options =>
|
||||
manager.request(
|
||||
name,
|
||||
route.join('/'),
|
||||
Object.assign(
|
||||
{
|
||||
versioned: manager.versioned,
|
||||
route: routeBucket.join('/'),
|
||||
},
|
||||
options,
|
||||
),
|
||||
);
|
||||
}
|
||||
route.push(name);
|
||||
return new Proxy(noop, handler);
|
||||
|
||||
@@ -48,7 +48,7 @@ class DiscordAPIError extends Error {
|
||||
|
||||
for (const [k, v] of Object.entries(obj)) {
|
||||
if (k === 'message') continue;
|
||||
const newKey = key ? isNaN(k) ? `${key}.${k}` : `${key}[${k}]` : k;
|
||||
const newKey = key ? (isNaN(k) ? `${key}.${k}` : `${key}[${k}]`) : k;
|
||||
|
||||
if (v._errors) {
|
||||
messages.push(`${newKey}: ${v._errors.map(e => e.message).join(' ')}`);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
const RequestHandler = require('./RequestHandler');
|
||||
const APIRequest = require('./APIRequest');
|
||||
const routeBuilder = require('./APIRouter');
|
||||
const RequestHandler = require('./RequestHandler');
|
||||
const { Error } = require('../errors');
|
||||
const { Endpoints } = require('../util/Constants');
|
||||
const Collection = require('../util/Collection');
|
||||
const { Endpoints } = require('../util/Constants');
|
||||
|
||||
class RESTManager {
|
||||
constructor(client, tokenPrefix = 'Bot') {
|
||||
@@ -37,12 +37,14 @@ class RESTManager {
|
||||
|
||||
push(handler, apiRequest) {
|
||||
return new Promise((resolve, reject) => {
|
||||
handler.push({
|
||||
request: apiRequest,
|
||||
resolve,
|
||||
reject,
|
||||
retries: 0,
|
||||
}).catch(reject);
|
||||
handler
|
||||
.push({
|
||||
request: apiRequest,
|
||||
resolve,
|
||||
reject,
|
||||
retries: 0,
|
||||
})
|
||||
.catch(reject);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,11 @@
|
||||
|
||||
const DiscordAPIError = require('./DiscordAPIError');
|
||||
const HTTPError = require('./HTTPError');
|
||||
const {
|
||||
Events: { RATE_LIMIT },
|
||||
browser,
|
||||
} = require('../util/Constants');
|
||||
const Util = require('../util/Util');
|
||||
const { Events: { RATE_LIMIT }, browser } = require('../util/Constants');
|
||||
|
||||
function parseResponse(res) {
|
||||
if (res.headers.get('content-type').startsWith('application/json')) return res.json();
|
||||
@@ -52,7 +55,6 @@ class RequestHandler {
|
||||
return this.queue.length === 0 && !this.limited && this.busy !== true;
|
||||
}
|
||||
|
||||
/* eslint-disable-next-line complexity */
|
||||
async execute(item) {
|
||||
// Insert item back to the beginning if currently busy
|
||||
if (this.busy) {
|
||||
@@ -102,9 +104,7 @@ class RequestHandler {
|
||||
} catch (error) {
|
||||
// NodeFetch error expected for all "operational" errors, such as 500 status code
|
||||
this.busy = false;
|
||||
return reject(
|
||||
new HTTPError(error.message, error.constructor.name, error.status, request.method, request.path),
|
||||
);
|
||||
return reject(new HTTPError(error.message, error.constructor.name, error.status, request.method, request.path));
|
||||
}
|
||||
|
||||
if (res && res.headers) {
|
||||
@@ -171,9 +171,7 @@ class RequestHandler {
|
||||
}
|
||||
return null;
|
||||
} catch (err) {
|
||||
return reject(
|
||||
new HTTPError(err.message, err.constructor.name, err.status, request.method, request.path),
|
||||
);
|
||||
return reject(new HTTPError(err.message, err.constructor.name, err.status, request.method, request.path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user