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