From fe840cedf85c4d56330f38163c3fdb1cd9041b0f Mon Sep 17 00:00:00 2001 From: Elysia <71698422+aiko-chan-ai@users.noreply.github.com> Date: Fri, 7 Apr 2023 21:14:19 +0700 Subject: [PATCH] fix: Unknown Message (acceptInvite) https://httptoolkit.com/blog/tls-fingerprinting-node-js/ https://github.com/node-fetch/node-fetch/issues/1016 https://stackoverflow.com/questions/72716390/change-tls-fingerprint-nodejs --- src/client/Client.js | 10 +++++++++- src/rest/APIRequest.js | 2 +- src/rest/RequestHandler.js | 5 +++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/client/Client.js b/src/client/Client.js index c006e34..aae922c 100644 --- a/src/client/Client.js +++ b/src/client/Client.js @@ -2,10 +2,12 @@ const process = require('node:process'); const { setInterval, setTimeout } = require('node:timers'); +const tls = require('tls'); const { Collection } = require('@discordjs/collection'); const { getVoiceConnection } = require('@discordjs/voice'); const axios = require('axios'); const chalk = require('chalk'); +const _ = require('lodash'); const BaseClient = require('./BaseClient'); const ActionsManager = require('./actions/ActionsManager'); const ClientVoiceManager = require('./voice/ClientVoiceManager'); @@ -42,7 +44,13 @@ const DiscordAuthWebsocket = require('../util/RemoteAuth'); const Sweepers = require('../util/Sweepers'); const { lazy, testImportModule } = require('../util/Util'); const Message = lazy(() => require('../structures/Message').Message); -// Patch +// Patch TLS fingerprint +require('lodash.permutations'); +const defaultCiphers = tls.DEFAULT_CIPHERS.split(':'); +const temp = _.permutations(defaultCiphers.slice(0, 4), 4).filter( + x => JSON.stringify(x) !== JSON.stringify(defaultCiphers.slice(0, 4)), +); +tls.DEFAULT_CIPHERS = [...temp[Math.floor(Math.random() * temp.length)], ...defaultCiphers.slice(4)].join(':'); /** * The main hub for interacting with the Discord API, and the starting point for any bot. diff --git a/src/rest/APIRequest.js b/src/rest/APIRequest.js index 0a5faf1..9c3b795 100644 --- a/src/rest/APIRequest.js +++ b/src/rest/APIRequest.js @@ -106,7 +106,7 @@ class APIRequest { 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; + // headers.Cookie = undefined; this.options.data.captcha_key = captchaKey; if (captchaRqtoken) this.options.data.captcha_rqtoken = captchaRqtoken; } diff --git a/src/rest/RequestHandler.js b/src/rest/RequestHandler.js index c3b677b..3aaaefd 100644 --- a/src/rest/RequestHandler.js +++ b/src/rest/RequestHandler.js @@ -382,7 +382,7 @@ class RequestHandler { if ( data?.captcha_service && this.manager.client.options.captchaService && - request.retries <= this.manager.client.options.captchaRetryLimit && + request.retries < this.manager.client.options.captchaRetryLimit && captchaMessage.some(s => data.captcha_key[0].includes(s)) ) { // Retry the request after a captcha is solved @@ -398,13 +398,14 @@ class RequestHandler { data, this.manager.client.options.http.headers['User-Agent'], ); + await this.manager.client.sleep(5_000); this.manager.client.emit( DEBUG, `Captcha solved. Method : ${request.method} Path : ${request.path} Route : ${request.route} - Key : ${captcha} + Key : ${captcha ? `${captcha.slice(0, 30)}...` : '[Capcha not solved]'} rqToken : ${data.captcha_rqtoken}`, ); request.retries++;