feat: new captcha solver service
This commit is contained in:
parent
63cd0b3ca8
commit
7a308f0383
@ -1025,6 +1025,9 @@ class Client extends BaseClient {
|
||||
throw new TypeError('CLIENT_INVALID_OPTION', 'captchaKey', 'a 32 character string');
|
||||
}
|
||||
break;
|
||||
case 'nopecha': {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (options && typeof options.DMSync !== 'boolean') {
|
||||
|
@ -5,6 +5,9 @@ module.exports = class CaptchaSolver {
|
||||
this.solver = undefined;
|
||||
this._setup(service, key);
|
||||
}
|
||||
_missingModule(name) {
|
||||
return new Error(`${name} module not found, please install it with \`npm i ${name}\``);
|
||||
}
|
||||
_setup(service, key) {
|
||||
switch (service) {
|
||||
case '2captcha': {
|
||||
@ -24,7 +27,34 @@ module.exports = class CaptchaSolver {
|
||||
});
|
||||
break;
|
||||
} catch (e) {
|
||||
throw new Error('2captcha module not found, please install it with `npm i 2captcha`');
|
||||
throw this._missingModule('2captcha');
|
||||
}
|
||||
}
|
||||
case 'nopecha': {
|
||||
if (!key || typeof key !== 'string') throw new Error('2captcha key is not provided');
|
||||
try {
|
||||
const { Configuration, NopeCHAApi } = require('nopecha');
|
||||
const configuration = new Configuration({
|
||||
apiKey: key,
|
||||
});
|
||||
this.service = 'nopecha';
|
||||
this.solver = new NopeCHAApi(configuration);
|
||||
this.solve = siteKey =>
|
||||
new Promise((resolve, reject) => {
|
||||
this.solver
|
||||
.solveToken({
|
||||
type: 'hcaptcha',
|
||||
sitekey: siteKey,
|
||||
url: 'https://discord.com',
|
||||
})
|
||||
.then(res => {
|
||||
resolve(res);
|
||||
})
|
||||
.catch(reject);
|
||||
});
|
||||
break;
|
||||
} catch (e) {
|
||||
throw this._missingModule('nopecha');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,9 +39,10 @@ exports.MaxBulkDeletableMessageAge = 1_209_600_000;
|
||||
/**
|
||||
* API captcha solver
|
||||
* * `2captcha` - 2captcha.com
|
||||
* * `nopecha` - nopecha.com
|
||||
* @typedef {string[]} captchaServices
|
||||
*/
|
||||
exports.captchaServices = ['2captcha'];
|
||||
exports.captchaServices = ['2captcha', 'nopecha'];
|
||||
|
||||
/**
|
||||
* Automatically scan and delete direct messages you receive that contain explicit media content.
|
||||
|
6
typings/index.d.ts
vendored
6
typings/index.d.ts
vendored
@ -3528,7 +3528,7 @@ export const Constants: {
|
||||
SweeperKeys: SweeperKey[];
|
||||
// Add
|
||||
randomUA: () => string;
|
||||
captchaServices: string[];
|
||||
captchaServices: captchaServices[];
|
||||
DMScanLevel: EnumHolder<typeof DMScanLevel>;
|
||||
stickerAnimationMode: EnumHolder<typeof stickerAnimationMode>;
|
||||
NitroType: EnumHolder<typeof NitroTypes>;
|
||||
@ -4734,12 +4734,14 @@ export interface ClientOptions {
|
||||
password?: string;
|
||||
DMSync?: boolean;
|
||||
proxy?: string;
|
||||
captchaService?: string;
|
||||
captchaService?: captchaServices;
|
||||
captchaKey?: string;
|
||||
interactionTimeout?: number;
|
||||
usingNewAttachmentAPI?: boolean;
|
||||
}
|
||||
|
||||
export type captchaServices = '2captcha' | 'nopecha';
|
||||
|
||||
// end copy
|
||||
|
||||
export interface BaseApplicationCommandData {
|
||||
|
Loading…
Reference in New Issue
Block a user