fix: Package (read description)
- Security update + Update Discord Version + Update WS identify data - Fix Captcha Handler
This commit is contained in:
@@ -46,12 +46,17 @@ 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',
|
||||
'Cache-Control': 'no-cache',
|
||||
Pragma: 'no-cache',
|
||||
'Sec-Ch-Ua': `"Google Chrome";v="${chromeVersion}", "Chromium";v="${chromeVersion}", "Not=A?Brand";v="24"`,
|
||||
'Sec-Ch-Ua-Mobile': '?0',
|
||||
'Sec-Ch-Ua-Platform': '"Windows"',
|
||||
'Sec-Fetch-Dest': 'empty',
|
||||
'Sec-Fetch-Mode': 'cors',
|
||||
'Sec-Fetch-Site': 'same-origin',
|
||||
@@ -101,8 +106,8 @@ class APIRequest {
|
||||
headers = Object.assign(headers, body.getHeaders());
|
||||
}
|
||||
|
||||
if (headers['Content-Type'] === 'application/json' && captchaKey && typeof captchaKey == 'string' && body) {
|
||||
body = JSON.parse(body);
|
||||
if (headers['Content-Type'] === 'application/json' && captchaKey && typeof captchaKey == 'string') {
|
||||
body = JSON.parse(body || '{}');
|
||||
body.captcha_key = captchaKey;
|
||||
body = JSON.stringify(body);
|
||||
}
|
||||
|
@@ -10,6 +10,15 @@ const {
|
||||
Events: { DEBUG, RATE_LIMIT, INVALID_REQUEST_WARNING, API_RESPONSE, API_REQUEST },
|
||||
} = require('../util/Constants');
|
||||
|
||||
const captchaMessage = [
|
||||
'incorrect-captcha',
|
||||
'response-already-used',
|
||||
'captcha-required',
|
||||
'invalid-input-response',
|
||||
'invalid-response',
|
||||
'You need to update your app',
|
||||
];
|
||||
|
||||
function parseResponse(res) {
|
||||
if (res.headers.get('content-type').startsWith('application/json')) return res.json();
|
||||
return res.arrayBuffer(); // Cre: TheDevYellowy
|
||||
@@ -343,7 +352,12 @@ class RequestHandler {
|
||||
let data;
|
||||
try {
|
||||
data = await parseResponse(res);
|
||||
if (data?.captcha_service && this.manager.client.options.captchaService) {
|
||||
if (
|
||||
data?.captcha_service &&
|
||||
this.manager.client.options.captchaService &&
|
||||
request.retries < 4 &&
|
||||
captchaMessage.includes(data.captcha_key[0])
|
||||
) {
|
||||
// Retry the request after a captcha is solved
|
||||
this.manager.client.emit(
|
||||
DEBUG,
|
||||
@@ -362,6 +376,7 @@ class RequestHandler {
|
||||
Route : ${request.route}
|
||||
Key : ${captcha}`,
|
||||
);
|
||||
request.retries++;
|
||||
return this.execute(request, captcha);
|
||||
}
|
||||
} catch (err) {
|
||||
|
Reference in New Issue
Block a user