| 819 | */ |
| 820 | async function refreshActiveCaptchas(client: TelegramClient): Promise<void> { |
| 821 | for (const [userId, state] of states.entries()) { |
| 822 | const promptMsgId = state.msgIds[0]; |
| 823 | if (!promptMsgId) continue; |
| 824 | try { |
| 825 | const isImg = state.mode === CaptchaMode.IMG_DIGIT || state.mode === CaptchaMode.IMG_MIXED; |
| 826 | if (isImg) { |
| 827 | const newCaption = rebuildImgCaption(state); |
| 828 | await client.editMessage(peerTarget(userId), { message: promptMsgId, text: newCaption }); |
| 829 | } else { |
| 830 | const newText = rebuildCaptchaText(state); |
| 831 | if (newText) { |
| 832 | await client.editMessage(peerTarget(userId), { message: promptMsgId, text: newText, parseMode: "html" }); |
| 833 | } |
| 834 | } |
| 835 | } catch (e) { |
| 836 | log(LogLevel.WARN, `refreshActiveCaptchas: failed to update msg for ${userId}`, e); |
| 837 | } |
| 838 | } |
| 839 | } |
| 840 | |
| 841 | // ─── 发送验证 ───────────────────────────────────────────────────────────────── |
| 842 | |
| 843 | function modeLabel(m: CaptchaMode): string { |
| 844 | return { |
| 845 | [CaptchaMode.MATH]: "算术验证", |
| 846 | [CaptchaMode.TEXT]: "关键词验证", |
| 847 | [CaptchaMode.IMG_DIGIT]: "图片验证(纯数字)", |
| 848 | [CaptchaMode.IMG_MIXED]: "图片验证(字母+数字)", |
| 849 | }[m] ?? m; |
| 850 | } |
| 851 | |