feat: captcha solver with proxy
i dont like it
This commit is contained in:
@@ -1,11 +1,46 @@
|
||||
'use strict';
|
||||
|
||||
const proxyParser = proxy => {
|
||||
const protocolSplit = proxy.split('://');
|
||||
const protocol = protocolSplit.length === 1 ? null : protocolSplit[0];
|
||||
const rest = protocolSplit.length === 1 ? protocolSplit[0] : protocolSplit[1];
|
||||
const authSplit = rest.split('@');
|
||||
if (authSplit.length === 1) {
|
||||
const host = authSplit[0].split(':')[0];
|
||||
const port = Number(authSplit[0].split(':')[1]);
|
||||
const proxyConfig = {
|
||||
host,
|
||||
port,
|
||||
};
|
||||
if (protocol != null) {
|
||||
proxyConfig.protocol = protocol;
|
||||
}
|
||||
return proxyConfig;
|
||||
}
|
||||
const host = authSplit[1].split(':')[0];
|
||||
const port = Number(authSplit[1].split(':')[1]);
|
||||
const [username, password] = authSplit[0].split(':');
|
||||
const proxyConfig = {
|
||||
host,
|
||||
port,
|
||||
auth: {
|
||||
username,
|
||||
password,
|
||||
},
|
||||
};
|
||||
if (protocol != null) {
|
||||
proxyConfig.protocol = protocol;
|
||||
}
|
||||
return proxyConfig;
|
||||
};
|
||||
|
||||
module.exports = class CaptchaSolver {
|
||||
constructor(service, key, defaultCaptchaSolver) {
|
||||
constructor(service, key, defaultCaptchaSolver, proxyString = '') {
|
||||
this.service = 'custom';
|
||||
this.solver = undefined;
|
||||
this.defaultCaptchaSolver = defaultCaptchaSolver;
|
||||
this.key = null;
|
||||
this.proxy = proxyString.length ? proxyParser(proxyString) : null;
|
||||
this._setup(service, key);
|
||||
}
|
||||
_missingModule(name) {
|
||||
@@ -23,12 +58,22 @@ module.exports = class CaptchaSolver {
|
||||
this.solve = (data, userAgent) =>
|
||||
new Promise((resolve, reject) => {
|
||||
const siteKey = data.captcha_sitekey;
|
||||
const postD = data.captcha_rqdata
|
||||
? {
|
||||
data: data.captcha_rqdata,
|
||||
userAgent,
|
||||
}
|
||||
: undefined;
|
||||
let postD = {};
|
||||
if (this.proxy !== null) {
|
||||
postD = {
|
||||
proxytype: this.proxy.protocol?.toUpperCase(),
|
||||
proxy: `${'auth' in this.proxy ? `${this.proxy.auth.username}:${this.proxy.auth.password}@` : ''}${
|
||||
this.proxy.host
|
||||
}:${this.proxy.port}`,
|
||||
};
|
||||
}
|
||||
if (data.captcha_rqdata) {
|
||||
postD = {
|
||||
...postD,
|
||||
data: data.captcha_rqdata,
|
||||
userAgent,
|
||||
};
|
||||
}
|
||||
this.solver
|
||||
.hcaptcha(siteKey, 'https://discord.com/channels/@me', postD)
|
||||
.then(res => {
|
||||
@@ -51,6 +96,15 @@ module.exports = class CaptchaSolver {
|
||||
this.solve = (captchaData, userAgent) =>
|
||||
new Promise((resolve, reject) => {
|
||||
if (userAgent) client.setUserAgent(userAgent);
|
||||
if (this.proxy !== null) {
|
||||
client.setProxy(
|
||||
this.proxy.protocol,
|
||||
this.proxy.host,
|
||||
this.proxy.port,
|
||||
'auth' in this.proxy ? this.proxy.auth.username : undefined,
|
||||
'auth' in this.proxy ? this.proxy.auth.password : undefined,
|
||||
);
|
||||
}
|
||||
client
|
||||
.createWithTask(
|
||||
client.task({
|
||||
|
@@ -32,6 +32,7 @@ class RESTManager {
|
||||
this.client.options.captchaService,
|
||||
this.client.options.captchaKey,
|
||||
this.client.options.captchaSolver,
|
||||
this.client.options.captchaWithProxy ? this.client.options.proxy : '',
|
||||
);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user