From 3d44ff54f739094da503e6fdc916fd7acc892fd3 Mon Sep 17 00:00:00 2001 From: Elysia <71698422+aiko-chan-ai@users.noreply.github.com> Date: Sun, 5 Mar 2023 17:51:34 +0700 Subject: [PATCH] feat: capmonster --- src/client/Client.js | 2 ++ src/rest/APIRequest.js | 1 + src/rest/CaptchaSolver.js | 40 +++++++++++++++++++++++++++++++++++++++ src/util/Constants.js | 3 ++- src/util/Options.js | 2 +- typings/index.d.ts | 2 +- 6 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/client/Client.js b/src/client/Client.js index 3828dd3..a03532c 100644 --- a/src/client/Client.js +++ b/src/client/Client.js @@ -1033,6 +1033,8 @@ class Client extends BaseClient { throw new TypeError('CLIENT_INVALID_OPTION', 'captchaKey', 'a 32 character string'); } break; + case 'capmonster': + break; } } if (typeof options.captchaRetryLimit !== 'number' || isNaN(options.captchaRetryLimit)) { diff --git a/src/rest/APIRequest.js b/src/rest/APIRequest.js index e00b428..13b6856 100644 --- a/src/rest/APIRequest.js +++ b/src/rest/APIRequest.js @@ -46,6 +46,7 @@ class APIRequest { let headers = { ...this.client.options.http.headers, Accept: '*/*', + origin: 'https://discord.com', 'Accept-Language': 'en-US', 'Sec-Fetch-Dest': 'empty', 'Sec-Fetch-Mode': 'cors', diff --git a/src/rest/CaptchaSolver.js b/src/rest/CaptchaSolver.js index 6e68d37..24cfe56 100644 --- a/src/rest/CaptchaSolver.js +++ b/src/rest/CaptchaSolver.js @@ -1,9 +1,12 @@ 'use strict'; +const { setTimeout } = require('node:timers'); +const axios = require('axios'); module.exports = class CaptchaSolver { constructor(service, key, defaultCaptchaSolver) { this.service = 'custom'; this.solver = undefined; this.defaultCaptchaSolver = defaultCaptchaSolver; + this.key = null; this._setup(service, key); } _missingModule(name) { @@ -16,6 +19,7 @@ module.exports = class CaptchaSolver { try { const lib = require('2captcha'); this.service = '2captcha'; + this.key = key; this.solver = new lib.Solver(key); this.solve = (data, userAgent) => new Promise((resolve, reject) => { @@ -38,6 +42,42 @@ module.exports = class CaptchaSolver { throw this._missingModule('2captcha'); } } + case 'capmonster': { + if (!key || typeof key !== 'string') throw new Error('Capmonster key is not provided'); + this.service = 'capmonster'; + this.key = key; + this.solve = async (captchaData, userAgent) => { + // https://github.com/aiko-chan-ai/discord.js-selfbot-v13/issues/548#issuecomment-1452091328 + try { + const createTaskResponse = await axios.post('https://api.capmonster.cloud/createTask', { + clientKey: this.key, + task: { + type: 'HCaptchaTask', + websiteURL: 'https://discord.com/channels/@me', + websiteKey: captchaData.captcha_sitekey, + data: captchaData.captcha_rqdata, + isInvisible: !!captchaData.captcha_rqdata, + userAgent: userAgent, + }, + }); + const taskId = createTaskResponse.data.taskId; + let getResults = { status: 'processing' }; + while (getResults.status === 'processing') { + const getResultsResponse = await axios.post('https://api.capmonster.cloud/getTaskResult', { + clientKey: this.key, + taskId, + }); + getResults = getResultsResponse.data; + await new Promise(resolve => setTimeout(resolve, 1500).unref()); + } + const solution = getResults.solution.gRecaptchaResponse; + return await solution; + } catch (e) { + throw new Error('Capmonster API error', e); + } + }; + break; + } default: { this.solve = this.defaultCaptchaSolver; } diff --git a/src/util/Constants.js b/src/util/Constants.js index 205ca85..e6eeba0 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -17,9 +17,10 @@ exports.MaxBulkDeletableMessageAge = 1_209_600_000; /** * API captcha solver * * `2captcha` - 2captcha.com + * * `capmonster` - capmonster.cloud * @typedef {string[]} captchaServices */ -exports.captchaServices = ['2captcha', 'custom']; +exports.captchaServices = ['2captcha', 'capmonster', 'custom']; /** * Automatically scan and delete direct messages you receive that contain explicit media content. diff --git a/src/util/Options.js b/src/util/Options.js index 318e315..ebc2821 100644 --- a/src/util/Options.js +++ b/src/util/Options.js @@ -201,7 +201,7 @@ class Options extends null { os_version: '10.0.22621', os_arch: 'x64', system_locale: 'en-US', - client_build_number: 177662, + client_build_number: 178590, native_build_number: 29584, client_event_source: null, design_id: 0, diff --git a/typings/index.d.ts b/typings/index.d.ts index 27a5f02..3a9a36b 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -5044,7 +5044,7 @@ export interface ClientOptions { usingNewAttachmentAPI?: boolean; } -export type captchaServices = '2captcha'; +export type captchaServices = '2captcha' | 'capmonster'; // end copy