fix: captcha data

This commit is contained in:
Elysia 2023-06-03 13:34:56 +07:00
parent 18e7f8171f
commit c33767095c
5 changed files with 21 additions and 22 deletions

View File

@ -70,6 +70,7 @@
"safe-base64": "^2.0.1-0", "safe-base64": "^2.0.1-0",
"string_decoder": "^1.3.0", "string_decoder": "^1.3.0",
"string-similarity": "^4.0.4", "string-similarity": "^4.0.4",
"tough-cookie": "^4.1.2",
"ws": "^8.13.0" "ws": "^8.13.0"
}, },
"engines": { "engines": {

View File

@ -6,8 +6,10 @@ const { setTimeout } = require('node:timers');
const makeFetchCookie = require('fetch-cookie'); const makeFetchCookie = require('fetch-cookie');
const FormData = require('form-data'); const FormData = require('form-data');
const fetchOriginal = require('node-fetch'); const fetchOriginal = require('node-fetch');
const { CookieJar } = require('tough-cookie');
const fetch = makeFetchCookie(fetchOriginal); const cookieJar = new CookieJar();
const fetch = makeFetchCookie(fetchOriginal, cookieJar);
let agent = null; let agent = null;
@ -85,6 +87,10 @@ class APIRequest {
'User-Agent': this.client.options.http.headers['User-Agent'], 'User-Agent': this.client.options.http.headers['User-Agent'],
}; };
} }
if (captchaKey && typeof captchaKey == 'string') {
headers['x-captcha-key'] = captchaKey;
if (captchaRqtoken) headers['x-captcha-rqtoken'] = captchaRqtoken;
}
let body; let body;
if (this.options.files?.length) { if (this.options.files?.length) {
@ -98,29 +104,18 @@ class APIRequest {
} else { } else {
body.append('payload_json', JSON.stringify(this.options.data)); body.append('payload_json', JSON.stringify(this.options.data));
} }
} else if (typeof this.options.body !== 'undefined') {
if (this.options.dontUsePayloadJSON) {
for (const [key, value] of Object.entries(this.options.body)) body.append(key, value);
} else {
body.append('payload_json', JSON.stringify(this.options.body));
}
} }
headers = Object.assign(headers, body.getHeaders()); headers = Object.assign(headers, body.getHeaders());
// eslint-disable-next-line eqeqeq // eslint-disable-next-line eqeqeq
} else if (this.options.data != null) { } else if (this.options.data != null) {
headers['Content-Type'] = 'application/json'; if (this.options.useFormDataPayloadJSON) {
if (captchaKey && typeof captchaKey == 'string') { body = new FormData();
if (!this.options.data) this.options.data = {}; body.append('payload_json', JSON.stringify(this.options.data));
// Delete cookie (https://t.me/DMDGOBugsAndFeatures/626) Wtf Unknown Message Error ??? headers = Object.assign(headers, body.getHeaders());
headers.Cookie = undefined; } else {
this.options.data.captcha_key = captchaKey; body = JSON.stringify(this.options.data);
if (captchaRqtoken) this.options.data.captcha_rqtoken = captchaRqtoken; headers['Content-Type'] = 'application/json';
} }
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());
} }
const controller = new AbortController(); const controller = new AbortController();

View File

@ -18,6 +18,7 @@ const captchaMessage = [
'invalid-input-response', 'invalid-input-response',
'invalid-response', 'invalid-response',
'You need to update your app', 'You need to update your app',
'response-already-used-error',
]; ];
function parseResponse(res) { function parseResponse(res) {

View File

@ -879,7 +879,8 @@ class ApplicationCommand extends Base {
let nonce = SnowflakeUtil.generate(); let nonce = SnowflakeUtil.generate();
const data = getDataPost(optionsData, nonce); const data = getDataPost(optionsData, nonce);
await this.client.api.interactions.post({ await this.client.api.interactions.post({
body: data, data,
useFormDataPayloadJSON: true,
files: attachmentsBuffer, files: attachmentsBuffer,
}); });
this.client._interactionCache.set(nonce, { this.client._interactionCache.set(nonce, {
@ -975,7 +976,8 @@ class ApplicationCommand extends Base {
data.data.guild_id = message.guildId; data.data.guild_id = message.guildId;
} }
await this.client.api.interactions.post({ await this.client.api.interactions.post({
body: data, data,
useFormDataPayloadJSON: true,
}); });
this.client._interactionCache.set(nonce, { this.client._interactionCache.set(nonce, {
channelId: message.channelId, channelId: message.channelId,

View File

@ -205,7 +205,7 @@ class Options extends null {
system_locale: 'en-US', system_locale: 'en-US',
browser_user_agent: defaultUA, browser_user_agent: defaultUA,
browser_version: '22.3.2', browser_version: '22.3.2',
client_build_number: 199933, client_build_number: 201332,
native_build_number: 32266, native_build_number: 32266,
client_event_source: null, client_event_source: null,
design_id: 0, design_id: 0,