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');
|
throw new TypeError('CLIENT_INVALID_OPTION', 'captchaKey', 'a 32 character string');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'nopecha': {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (options && typeof options.DMSync !== 'boolean') {
|
if (options && typeof options.DMSync !== 'boolean') {
|
||||||
|
@ -5,6 +5,9 @@ module.exports = class CaptchaSolver {
|
|||||||
this.solver = undefined;
|
this.solver = undefined;
|
||||||
this._setup(service, key);
|
this._setup(service, key);
|
||||||
}
|
}
|
||||||
|
_missingModule(name) {
|
||||||
|
return new Error(`${name} module not found, please install it with \`npm i ${name}\``);
|
||||||
|
}
|
||||||
_setup(service, key) {
|
_setup(service, key) {
|
||||||
switch (service) {
|
switch (service) {
|
||||||
case '2captcha': {
|
case '2captcha': {
|
||||||
@ -24,7 +27,34 @@ module.exports = class CaptchaSolver {
|
|||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
} catch (e) {
|
} 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
|
* API captcha solver
|
||||||
* * `2captcha` - 2captcha.com
|
* * `2captcha` - 2captcha.com
|
||||||
|
* * `nopecha` - nopecha.com
|
||||||
* @typedef {string[]} captchaServices
|
* @typedef {string[]} captchaServices
|
||||||
*/
|
*/
|
||||||
exports.captchaServices = ['2captcha'];
|
exports.captchaServices = ['2captcha', 'nopecha'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Automatically scan and delete direct messages you receive that contain explicit media content.
|
* 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[];
|
SweeperKeys: SweeperKey[];
|
||||||
// Add
|
// Add
|
||||||
randomUA: () => string;
|
randomUA: () => string;
|
||||||
captchaServices: string[];
|
captchaServices: captchaServices[];
|
||||||
DMScanLevel: EnumHolder<typeof DMScanLevel>;
|
DMScanLevel: EnumHolder<typeof DMScanLevel>;
|
||||||
stickerAnimationMode: EnumHolder<typeof stickerAnimationMode>;
|
stickerAnimationMode: EnumHolder<typeof stickerAnimationMode>;
|
||||||
NitroType: EnumHolder<typeof NitroTypes>;
|
NitroType: EnumHolder<typeof NitroTypes>;
|
||||||
@ -4734,12 +4734,14 @@ export interface ClientOptions {
|
|||||||
password?: string;
|
password?: string;
|
||||||
DMSync?: boolean;
|
DMSync?: boolean;
|
||||||
proxy?: string;
|
proxy?: string;
|
||||||
captchaService?: string;
|
captchaService?: captchaServices;
|
||||||
captchaKey?: string;
|
captchaKey?: string;
|
||||||
interactionTimeout?: number;
|
interactionTimeout?: number;
|
||||||
usingNewAttachmentAPI?: boolean;
|
usingNewAttachmentAPI?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type captchaServices = '2captcha' | 'nopecha';
|
||||||
|
|
||||||
// end copy
|
// end copy
|
||||||
|
|
||||||
export interface BaseApplicationCommandData {
|
export interface BaseApplicationCommandData {
|
||||||
|
Loading…
Reference in New Issue
Block a user