hk_bot/automatization.ts

24 lines
1.1 KiB
TypeScript

import Hero from "@ulixee/hero";
import * as telegram from 'telegram';
import { sleep } from "telegram/Helpers";
import { AccountInterface } from "./interfaces/databaseInterface";
import { waitNewMessages } from "./utils";
export const vertification=async function vertification(client: telegram.TelegramClient,worker: AccountInterface,hero: Omit<Hero, "then">,url: string,botEntity: telegram.Api.Chat | telegram.Api.User,idOfLastMessage: number) {
await hero.goto(url,{timeoutMs:180_000});
await hero.waitForLoad('AllContentLoaded');
const captchaButton=hero.document.querySelector('button.g-recaptcha.btn.btn-primary');
if (captchaButton!=null){
let verify=hero.document.querySelector('body > section > h2');
while (verify!=null && (await verify.textContent)!.includes('All right!')==false){
await hero.interact({click:{element: captchaButton, verification: 'exactElement'}});
await sleep(5000);
verify=hero.document.querySelector('body > section > h2');
}
} else {
throw new Error('Cant find captcha button');
}
}