2022-11-04 18:40:19 +07:00
|
|
|
'use strict';
|
2023-04-22 00:00:55 +07:00
|
|
|
|
2022-11-04 18:40:19 +07:00
|
|
|
module.exports = class CaptchaSolver {
|
2023-01-03 13:56:24 +07:00
|
|
|
constructor(service, key, defaultCaptchaSolver) {
|
|
|
|
|
this.service = 'custom';
|
2022-11-04 18:40:19 +07:00
|
|
|
this.solver = undefined;
|
2023-01-03 13:56:24 +07:00
|
|
|
this.defaultCaptchaSolver = defaultCaptchaSolver;
|
2023-03-05 17:51:34 +07:00
|
|
|
this.key = null;
|
2022-11-04 18:40:19 +07:00
|
|
|
this._setup(service, key);
|
|
|
|
|
}
|
2022-12-04 16:38:15 +07:00
|
|
|
_missingModule(name) {
|
|
|
|
|
return new Error(`${name} module not found, please install it with \`npm i ${name}\``);
|
|
|
|
|
}
|
2022-11-04 18:40:19 +07:00
|
|
|
_setup(service, key) {
|
|
|
|
|
switch (service) {
|
|
|
|
|
case '2captcha': {
|
|
|
|
|
if (!key || typeof key !== 'string') throw new Error('2captcha key is not provided');
|
|
|
|
|
try {
|
|
|
|
|
const lib = require('2captcha');
|
|
|
|
|
this.service = '2captcha';
|
2023-03-05 17:51:34 +07:00
|
|
|
this.key = key;
|
2022-11-04 18:40:19 +07:00
|
|
|
this.solver = new lib.Solver(key);
|
2022-12-27 17:27:34 +07:00
|
|
|
this.solve = (data, userAgent) =>
|
2022-11-04 18:40:19 +07:00
|
|
|
new Promise((resolve, reject) => {
|
2022-12-27 17:27:34 +07:00
|
|
|
const siteKey = data.captcha_sitekey;
|
|
|
|
|
const postD = data.captcha_rqdata
|
|
|
|
|
? {
|
|
|
|
|
data: data.captcha_rqdata,
|
|
|
|
|
userAgent,
|
|
|
|
|
}
|
|
|
|
|
: undefined;
|
2022-11-04 18:40:19 +07:00
|
|
|
this.solver
|
2022-12-27 17:27:34 +07:00
|
|
|
.hcaptcha(siteKey, 'https://discord.com/channels/@me', postD)
|
2022-11-04 18:40:19 +07:00
|
|
|
.then(res => {
|
|
|
|
|
resolve(res.data);
|
|
|
|
|
})
|
|
|
|
|
.catch(reject);
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
} catch (e) {
|
2022-12-04 16:38:15 +07:00
|
|
|
throw this._missingModule('2captcha');
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-05 17:51:34 +07:00
|
|
|
case 'capmonster': {
|
|
|
|
|
if (!key || typeof key !== 'string') throw new Error('Capmonster key is not provided');
|
2023-04-22 00:00:55 +07:00
|
|
|
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({
|
2023-03-05 19:04:04 +07:00
|
|
|
websiteURL: 'https://discord.com/channels/@me',
|
|
|
|
|
websiteKey: captchaData.captcha_sitekey,
|
|
|
|
|
isInvisible: !!captchaData.captcha_rqdata,
|
2023-04-22 00:00:55 +07:00
|
|
|
data: captchaData.captcha_rqdata,
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
.then(id => client.joinTaskResult(id))
|
|
|
|
|
.then(result => resolve(result.gRecaptchaResponse))
|
|
|
|
|
.catch(reject);
|
|
|
|
|
});
|
|
|
|
|
} catch (e) {
|
|
|
|
|
throw this._missingModule('node-capmonster');
|
|
|
|
|
}
|
2023-03-05 17:51:34 +07:00
|
|
|
break;
|
|
|
|
|
}
|
2023-01-03 13:56:24 +07:00
|
|
|
default: {
|
|
|
|
|
this.solve = this.defaultCaptchaSolver;
|
|
|
|
|
}
|
2022-11-04 18:40:19 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
solve() {}
|
|
|
|
|
};
|