Skip to content

Commit 43f1f42

Browse files
committed
feat: 电报机器人消息推送
1 parent 724e572 commit 43f1f42

File tree

4 files changed

+1920
-55
lines changed

4 files changed

+1920
-55
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ USERNAMES=hahaha2,hahaha1,ha1,ha2,DrKBoogieWoogie,lsp,lsb #888存在问题
33
PASSWORDS="BfdSGt}F4!5pLHt,BfdSGt}F4!5pLHt,iTs9Wx4+3Eavkhk,W$RhQUVn5E?BBBq,]\"w%2Qd%M8Z6-SS,HU5B6Ee]kRB%Qj',uYE)46Ej8phu$#u" # 密码外面要加上双引号,密码内部如果有双引号,需要加上转义字符 反斜杠 \
44
WEBSITE=https://linux.do # 需要阅读的网站,支持后面那些:https://meta.discourse.org, https://meta.appinn.net, https://community.openai.com
55
RUN_TIME_LIMIT_MINUTES=15 #运行时间,分钟为单位
6+
TELEGRAM_BOT_TOKEN = yourtoken
7+
TELEGRAM_CHAT_ID= yourid

bypasscf.js

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,26 @@ import StealthPlugin from "puppeteer-extra-plugin-stealth";
55
import dotenv from "dotenv";
66
import { fileURLToPath } from "url";
77
import { dirname, join } from "path";
8+
import TelegramBot from "node-telegram-bot-api";
9+
810
dotenv.config();
11+
const token = process.env.TELEGRAM_BOT_TOKEN;
12+
const chatId = process.env.TELEGRAM_CHAT_ID;
13+
14+
if (token && chatId) {
15+
bot = new TelegramBot(token);
16+
}
17+
function sendToTelegram(message) {
18+
bot
19+
.sendMessage(chatId, message)
20+
.then(() => {
21+
console.log("Telegram message sent successfully");
22+
})
23+
.catch((error) => {
24+
console.error("Error sending Telegram message:", error);
25+
});
26+
}
27+
928
// 读取以分钟为单位的运行时间限制
1029
const runTimeLimitMinutes = process.env.RUN_TIME_LIMIT_MINUTES || 15;
1130

@@ -79,6 +98,9 @@ function delayClick(time) {
7998
} catch (error) {
8099
// 错误处理逻辑
81100
console.error("发生错误:", error);
101+
if (token && chatId) {
102+
sendToTelegram(`发生错误:${error.message}`);
103+
}
82104
}
83105
})();
84106
async function launchBrowserForUser(username, password) {
@@ -196,7 +218,7 @@ async function launchBrowserForUser(username, password) {
196218
});
197219
}
198220
} catch (err) {
199-
console.log(err);
221+
throw new Error(err);
200222
}
201223
}
202224
async function login(page, username, password) {
@@ -246,7 +268,7 @@ async function login(page, username, password) {
246268
// 等待密码输入框加载
247269
await page.waitForSelector("#login-account-password");
248270
// 模拟人类在输入用户名后的短暂停顿
249-
delayClick; // 清空输入框并输入密码
271+
// delayClick; // 清空输入框并输入密码
250272
await page.click("#login-account-password", { clickCount: 3 });
251273
await page.type("#login-account-password", password, {
252274
delay: 100,
@@ -265,11 +287,10 @@ async function login(page, username, password) {
265287
page.click("#login-button"), // 点击登录按钮触发跳转
266288
]); //注意如果登录失败,这里会一直等待跳转,导致脚本执行失败 这点四个月之前你就发现了结果今天又遇到(有个用户遇到了https://linux.do/t/topic/169209/82),但是你没有在这个报错你提示我8.5
267289
} catch (error) {
268-
console.error(
269-
"Navigation timed out in login.请检查用户名密码是否正确(注意密码中是否有特殊字符,需要外面加上双引号指明这是字符串,如果密码里面有双引号则需要转义), 此外GitHub action似乎不能识别特殊字符,不能登录的话建议改密码",'失败用户:',username,
270-
error
290+
throw new Error(
291+
`Navigation timed out in login.请检查用户名密码是否正确(注意密码中是否有特殊字符,需要外面加上双引号指明这是字符串,如果密码里面有双引号则需要转义), 此外GitHub action似乎不能识别特殊字符,不能登录的话建议改密码,失败用户:,${username},错误信息:,
292+
${error}`
271293
);
272-
throw new Error("Navigation timed out in login.");
273294
}
274295
await delayClick(1000);
275296
}

0 commit comments

Comments
 (0)