feat: capmonster

This commit is contained in:
Elysia
2023-03-05 17:51:34 +07:00
parent ee906b544e
commit 3d44ff54f7
6 changed files with 47 additions and 3 deletions

View File

@@ -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',

View File

@@ -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;
}