-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCaptchaSolver.ts
More file actions
47 lines (43 loc) · 1.5 KB
/
CaptchaSolver.ts
File metadata and controls
47 lines (43 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import fetch from "node-fetch";
export async function invisibleCaptchaSolver(captchaIdentifier: string, twoCaptchaAPIKey: string): Promise<string> {
const request =
"http://2captcha.com/in.php?key=" +
twoCaptchaAPIKey +
"&method=userrecaptcha&googlekey=" +
captchaIdentifier +
"&json=true&pageurl=https://www.dofus.com/fr/creer-un-compte" +
"&invisible=1";
const result = await fetch(request);
const resultJSON = await result.json();
const requestID: string = resultJSON.request;
let captchaInterval: NodeJS.Timeout;
const solvedCaptcha: string = await new Promise((resolve, reject) => {
setTimeout(async () => {
const responseRequest = "http://2captcha.com/res.php?key=" + twoCaptchaAPIKey + "&action=get&id=" + requestID + "&json=true";
let responseResult = await fetch(responseRequest);
let responseJSON = await responseResult.json();
let response = responseJSON.request;
if (response == "CAPCHA_NOT_READY") {
captchaInterval = setInterval(async () => {
responseResult = await fetch(responseRequest);
responseJSON = await responseResult.json();
response = responseJSON.request;
if (response !== "CAPCHA_NOT_READY") {
if (captchaInterval) {
clearInterval(captchaInterval);
}
resolve(response);
}
}, 15000);
} else if (response === "CAPCHA_NOT_SOLVABLE") {
reject(response());
} else {
if (captchaInterval) {
clearInterval(captchaInterval);
}
resolve(response);
}
}, 30000);
});
return solvedCaptcha;
}