MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / tryGetCanvas

Function tryGetCanvas

pmcaptcha/pmcaptcha.ts:510–555  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

508
509async function runFailActions(client: TelegramClient, userId: number) {
510 await archiveChat(client, userId);
511 await muteChat(client, userId);
512
513 for (const a of cfg.failActions()) {
514 if (a === FailAction.BLOCK) await blockUser(client, userId);
515 if (a === FailAction.DELETE) {
516 try {
517 const peer = await resolveInputPeer(client, userId);
518 await client.invoke(new Api.messages.DeleteHistory({ peer, revoke: true, maxId: 0 }));
519 log(LogLevel.INFO, `Deleted history (revoke both sides) ${userId}`);
520 } catch (e) { log(LogLevel.ERROR, `delete failed ${userId}`, e); }
521 }
522 if (a === FailAction.REPORT) await reportSpam(client, userId);
523 if (a === FailAction.MUTE) await muteChat(client, userId);
524 if (a === FailAction.ARCHIVE) await archiveChat(client, userId);
525 }
526}
527
528async function runPassActions(client: TelegramClient, userId: number) {
529 for (const a of cfg.passActions()) {
530 if (a === PassAction.UNMUTE) await unmuteChat(client, userId);
531 if (a === PassAction.UNARCHIVE) await unarchiveChat(client, userId);
532 if (a === PassAction.WL) wl.add(userId);
533 }
534}
535
536// ─── 图片验证码生成 ───────────────────────────────────────────────────────────
537
538let _canvas: any = null;
539let _canvasInstalling = false;
540
541async function tryGetCanvas(): Promise<any> {
542 if (_canvas !== null) return _canvas;
543
544 try {
545 _canvas = await import("canvas");
546 log(LogLevel.INFO, "canvas module loaded");
547 return _canvas;
548 } catch {}
549
550 if (_canvasInstalling) {
551 const deadline = Date.now() + 60_000;
552 while (_canvasInstalling && Date.now() < deadline) {
553 if (!(await generationDelay(500))) return false;
554 }
555 return _canvas ?? false;
556 }
557
558 _canvasInstalling = true;

Callers 1

generateImageCaptchaFunction · 0.85

Calls 2

logFunction · 0.85
generationDelayFunction · 0.85

Tested by

no test coverage detected