()
| 508 | |
| 509 | async 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 | |
| 528 | async 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 | |
| 538 | let _canvas: any = null; |
| 539 | let _canvasInstalling = false; |
| 540 | |
| 541 | async 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; |
no test coverage detected