From fb79c178727314de4d2d44e3de389ad0e64ba763 Mon Sep 17 00:00:00 2001 From: Elysia <71698422+aiko-chan-ai@users.noreply.github.com> Date: Tue, 15 Aug 2023 18:36:54 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20idk=20#798?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rest/CaptchaSolver.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/rest/CaptchaSolver.js b/src/rest/CaptchaSolver.js index 0c6c932..340bb7c 100644 --- a/src/rest/CaptchaSolver.js +++ b/src/rest/CaptchaSolver.js @@ -34,6 +34,18 @@ const proxyParser = proxy => { return proxyConfig; }; +function findStringWithRegex(obj, regex) { + const matchingKeys = []; + for (const key in obj) { + if (obj[key] && typeof obj[key] === 'object') { + matchingKeys.push(...findStringWithRegex(obj[key], regex)); + } else if (typeof obj[key] === 'string' && regex.test(obj[key])) { + matchingKeys.push(key); + } + } + return matchingKeys; +} + module.exports = class CaptchaSolver { constructor(service, key, defaultCaptchaSolver, proxyString = '') { this.service = 'custom'; @@ -58,9 +70,13 @@ module.exports = class CaptchaSolver { this.solve = (data, userAgent) => new Promise((resolve, reject) => { const siteKey = data.captcha_sitekey; - let postD = {}; + let postD = { + invisible: 1, + userAgent, + }; if (this.proxy !== null) { postD = { + ...postD, proxytype: this.proxy.protocol?.toUpperCase(), proxy: `${'auth' in this.proxy ? `${this.proxy.auth.username}:${this.proxy.auth.password}@` : ''}${ this.proxy.host @@ -71,13 +87,14 @@ module.exports = class CaptchaSolver { postD = { ...postD, data: data.captcha_rqdata, - userAgent, }; } this.solver - .hcaptcha(siteKey, 'https://discord.com/channels/@me', postD) + .hcaptcha(siteKey, 'discord.com', postD) .then(res => { - resolve(res.data); + let result = findStringWithRegex(res, /^P\d_\w+/)[0]; + if (!result) throw new Error('Invalid captcha response'); + resolve(result); }) .catch(reject); });