i hate discord 😭
This commit is contained in:
Elysia
2023-02-09 19:26:39 +07:00
parent 9bab1f1983
commit 756a241051
11 changed files with 41 additions and 92 deletions

View File

@@ -4,7 +4,7 @@ const Buffer = require('node:buffer').Buffer;
const https = require('node:https');
const { setTimeout } = require('node:timers');
const FormData = require('form-data');
const fetch = require('node-fetch');
const fetch = (...args) => import('node-fetch').then(({ default: fetch }) => fetch(...args));
let agent = null;
@@ -43,29 +43,21 @@ class APIRequest {
: `${this.client.options.http.api}/v${this.client.options.http.version}`;
const url = API + this.path;
const chromeVersion = this.client.options.ws.properties.browser_version.split('.')[0];
let headers = {
...this.client.options.http.headers,
Accept: '*/*',
'Accept-Language': 'en-US,en;q=0.9',
'Sec-Ch-Ua': `"Not?A_Brand";v="8", "Chromium";v="${chromeVersion}", "Google Chrome";v="${chromeVersion}"`,
'Sec-Ch-Ua-Mobile': '?0',
'Sec-Ch-Ua-Platform': 'Windows',
'Accept-Language': 'en-US',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
'X-Debug-Options': 'bugReporterEnabled',
'X-Super-Properties': `${Buffer.from(
this.client.options.jsonTransformer({
...this.client.options.ws.properties,
browser_user_agent: this.client.options.http.headers['User-Agent'],
}),
this.client.options.jsonTransformer(this.client.options.ws.properties),
'ascii',
).toString('base64')}`,
'X-Discord-Locale': 'en-US',
'User-Agent': this.client.options.http.headers['User-Agent'],
Origin: 'https://discord.com',
Referer: 'https://discord.com/channels/@me',
Connection: 'keep-alive',
};
@@ -100,23 +92,22 @@ class APIRequest {
headers = Object.assign(headers, body.getHeaders());
// eslint-disable-next-line eqeqeq
} else if (this.options.data != null) {
body = this.options.data ? JSON.stringify(this.options.data) : undefined;
headers['Content-Type'] = 'application/json';
if (captchaKey && typeof captchaKey == 'string') {
if (!this.options.data) this.options.data = {};
this.options.data.captcha_key = captchaKey;
if (captchaRqtoken) this.options.data.captcha_rqtoken = captchaRqtoken;
}
body = this.options.data ? JSON.stringify(this.options.data) : undefined;
} else if (this.options.body != null) {
body = new FormData();
body.append('payload_json', JSON.stringify(this.options.body));
headers = Object.assign(headers, body.getHeaders());
}
if (headers['Content-Type'] === 'application/json' && captchaKey && typeof captchaKey == 'string') {
body = JSON.parse(body || '{}');
body.captcha_key = captchaKey;
if (captchaRqtoken) body.captcha_rqtoken = captchaRqtoken;
body = JSON.stringify(body);
}
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), this.client.options.restRequestTimeout).unref();
return fetch(url, {
method: this.method,
headers,

View File

@@ -411,7 +411,8 @@ class RequestHandler {
Method : ${request.method}
Path : ${request.path}
Route : ${request.route}
Key : ${captcha}`,
Key : ${captcha}
rqToken : ${data.captcha_rqtoken}`,
);
request.retries++;
return this.execute(request, captcha, data.captcha_rqtoken);