feat(CaptchaSolver): using lib node-capmonster
This commit is contained in:
parent
2357170e0f
commit
8f43b9028e
@ -1,6 +1,5 @@
|
||||
'use strict';
|
||||
const { setTimeout } = require('node:timers');
|
||||
const axios = require('axios');
|
||||
|
||||
module.exports = class CaptchaSolver {
|
||||
constructor(service, key, defaultCaptchaSolver) {
|
||||
this.service = 'custom';
|
||||
@ -44,51 +43,30 @@ module.exports = class CaptchaSolver {
|
||||
}
|
||||
case 'capmonster': {
|
||||
if (!key || typeof key !== 'string') throw new Error('Capmonster key is not provided');
|
||||
this.service = 'capmonster';
|
||||
this.key = key;
|
||||
this.solve = (captchaData, userAgent) =>
|
||||
// https://github.com/aiko-chan-ai/discord.js-selfbot-v13/issues/548#issuecomment-1452091328
|
||||
// eslint-disable-next-line no-async-promise-executor
|
||||
new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const createTaskResponse = await axios.post(
|
||||
'https://api.capmonster.cloud/createTask',
|
||||
{
|
||||
clientKey: this.key,
|
||||
task: {
|
||||
type: 'HCaptchaTask',
|
||||
try {
|
||||
const { HCaptchaTask } = require('node-capmonster');
|
||||
this.service = 'capmonster';
|
||||
this.key = key;
|
||||
const client = new HCaptchaTask(this.key);
|
||||
this.solve = (captchaData, userAgent) =>
|
||||
new Promise((resolve, reject) => {
|
||||
if (userAgent) client.setUserAgent(userAgent);
|
||||
client
|
||||
.createWithTask(
|
||||
client.task({
|
||||
websiteURL: 'https://discord.com/channels/@me',
|
||||
websiteKey: captchaData.captcha_sitekey,
|
||||
data: captchaData.captcha_rqdata,
|
||||
isInvisible: !!captchaData.captcha_rqdata,
|
||||
userAgent: userAgent,
|
||||
},
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'user-agent': 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 resolve(await solution);
|
||||
} catch (e) {
|
||||
// !console.error(e);
|
||||
reject(new Error(`Capmonster error: ${e.message}`, e?.response?.data));
|
||||
}
|
||||
return true;
|
||||
});
|
||||
data: captchaData.captcha_rqdata,
|
||||
}),
|
||||
)
|
||||
.then(id => client.joinTaskResult(id))
|
||||
.then(result => resolve(result.gRecaptchaResponse))
|
||||
.catch(reject);
|
||||
});
|
||||
} catch (e) {
|
||||
throw this._missingModule('node-capmonster');
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
Loading…
Reference in New Issue
Block a user