let getTaskSolution = (src) => {
return new Promise((resolve, reject) => {
anticaptcha.getBalance(async (err, balance) => {
if (err) {
reject(err);
return;
}
anticaptcha.setMinLength(5);
if (balance > 0) {
anticaptcha.createImageToTextTask({
case: true, // or params can be set for every captcha specially
body: await image2base64(src).catch(reject)
}, (err, taskId) => {
if (err) {
reject(err);
return;
}
anticaptcha.getTaskSolution(taskId, (err, taskSolution) => {
if (err) {
reject(err);
return;
}
resolve(taskSolution)
});
});
}
});
});
};
(async () => {
setUTitle("Loading app");
if (!VK_TOKEN) {
let succ = await initToken();
if (!succ) {
process.exit();
}
}
vk.token = VK_TOKEN;
vk.captchaHandler = async ({src, type}, retry) => {
let key = await getTaskSolution(src).catch((error) => console.log(error));
try {
await retry(key);
con('Всё ок.');
} catch (e) {
con("Всё фигово. " + e.message, true);
}
};
})();