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",
"string_decoder": "^1.3.0",
"string-similarity": "^4.0.4",
"tough-cookie": "^4.1.2",
"ws": "^8.13.0"
},
"engines": {

View File

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

View File

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

View File

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

View File

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