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

Function sendCaptcha

pmcaptcha/pmcaptcha.ts:872–1026  ·  view source on GitHub ↗
(client: TelegramClient, userId: number)

Source from the content-addressed store, hash-verified

870 }
871
872 const mode = cfg.mode();
873 const timeout = cfg.timeout();
874 const tries = cfg.maxTries();
875 const actions = cfg.failActions();
876 const custom = cfg.prompt();
877
878 const actionDesc = actions.length
879 ? actions.map(a => FAIL_ACTION_LABEL[a] ?? a).join("、")
880 : "仅归档并静音";
881
882 function buildFooter(): string {
883 const lines: string[] = [];
884 if (timeout > 0) lines.push(`⏱ 验证时间:<b>${htmlEscape(timeout)}</b> 秒`);
885 if (tries > 0) lines.push(`🔢 剩余次数:<b>${htmlEscape(tries)}</b> 次`);
886 lines.push(`⚠️ 验证失败将会:${htmlEscape(actionDesc)}`);
887 return lines.length ? "\n\n" + lines.join("\n") : "";
888 }
889
890 let answer = "";
891 let question = "";
892 let isQA = false;
893 const msgIds: number[] = [];
894
895 try {
896 switch (mode) {
897
898 case CaptchaMode.MATH: {
899 const { question: q, answer: ans } = mathQuestion();
900 answer = ans;
901 question = q;
902 const footer = buildFooter();
903 const text = custom
904 ? htmlEscape(custom).replace("{question}", htmlEscape(q))
905 : `🔒 <b>人机验证</b>\n\n请回复以下算式的答案:\n\n${codeTag(`${q} = ?`)}${footer}`;
906 const m = await client.sendMessage(userId, { message: text, parseMode: "html" });
907 msgIds.push(m.id);
908 break;
909 }
910
911 case CaptchaMode.TEXT: {
912 const kw = cfg.keyword();
913 const footer = buildFooter();
914 if (kw === "我同意" && !custom) {
915 const qa = textQuestion();
916 answer = qa.answer;
917 question = qa.question;
918 isQA = true;
919 const text = `🔒 <b>人机验证</b>\n\n请回答以下问题:\n\n<b>${htmlEscape(qa.question)}</b>${footer}`;
920 const m = await client.sendMessage(userId, { message: text, parseMode: "html" });
921 msgIds.push(m.id);
922 } else {
923 answer = kw;
924 question = kw;
925 isQA = false;
926 const text = custom
927 ? htmlEscape(custom).replace("{keyword}", htmlEscape(kw))
928 : `🔒 <b>人机验证</b>\n\n请回复以下关键词以证明你不是机器人:\n\n${codeTag(kw)}${footer}`;
929 const m = await client.sendMessage(userId, { message: text, parseMode: "html" });

Callers 1

messageListenerFunction · 0.85

Calls 15

getActiveLifecycleFunction · 0.85
removeCaptchaStateFunction · 0.85
cleanupCaptchaMessagesFunction · 0.85
mathQuestionFunction · 0.85
buildFooterFunction · 0.85
textQuestionFunction · 0.85
generateImageCaptchaFunction · 0.85
logFunction · 0.85
buildImgCaptionFunction · 0.85
isStateCurrentFunction · 0.85
runFailActionsFunction · 0.85
htmlEscapeFunction · 0.70

Tested by

no test coverage detected