feat: Bark 增加开始运行与获得学分提醒
收尾通知去掉重复的积分台账与完成门数;学习统计在无 TTY 时照常累计,保证 Docker 里也能推送学分提醒。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
18c5e5a3be
commit
6b508a0b1a
15 files changed
+188
-51
No files matched your search
+27
-10
@@ -10,6 +10,7 @@ import {
|
||||
exprStartBatch, exprAutoLogin,
|
||||
} from './page.mjs';
|
||||
import { runSelfCheck } from './selfcheck.mjs';
|
||||
import { notifyCreditEarned } from './notify.mjs';
|
||||
|
||||
/** 看护循环间隔:既不能太密(CDP 往返),也要能及时补注入 */
|
||||
export const WATCHDOG_MS = 1500;
|
||||
@@ -185,17 +186,16 @@ export async function runSession(o) {
|
||||
// 不会出现「浏览器重启后自动接着刷」或「未登录就报运行中」。
|
||||
const raw = await page.tryEval(`JSON.stringify((function () {
|
||||
var a = window.__yunXueTangAuto;
|
||||
return { route: a.route(), batchRunning: a.S.batchRunning, batchFinished: a.S.batchFinished, completed: a.S.completedThisRun };
|
||||
return { route: a.route(), batchRunning: a.S.batchRunning, batchFinished: a.S.batchFinished,
|
||||
status: (document.getElementById('yun-xue-tang-status') || {}).textContent || '' };
|
||||
})())`);
|
||||
if (!raw) return; // 路由跳转中,下一轮再试
|
||||
const st = JSON.parse(raw);
|
||||
|
||||
if (st.batchFinished) {
|
||||
if (cfg.RESTART_MINUTES > 0) {
|
||||
finishReason = '脚本已停止(本次完成 ' + st.completed + ' 门),按 YUN_XUE_TANG_RESTART_MINUTES 稍后重新开始';
|
||||
} else {
|
||||
finishReason = '脚本已停止(本次完成 ' + st.completed + ' 门;无更多可学课程)';
|
||||
}
|
||||
// 完成门数由收尾日志和通知正文另行给出,这里只留页面给出的停止原因
|
||||
finishReason = String(st.status || '').trim().slice(0, 120) ||
|
||||
(cfg.RESTART_MINUTES > 0 ? '无更多可学课程,稍后重新开始' : '无更多可学课程');
|
||||
finished = true;
|
||||
return;
|
||||
}
|
||||
@@ -276,8 +276,8 @@ export async function runSession(o) {
|
||||
continue;
|
||||
}
|
||||
lastStateAt = Date.now();
|
||||
// 面板每一轮都刷(快照本身就是最新状态,不需要另算);未启用时是空操作
|
||||
tui.snap(snap);
|
||||
// 面板每一轮都刷(快照本身就是最新状态,不需要另算);面板未启用时也照常累计学时/学分
|
||||
const study = tui.snap(snap);
|
||||
if (!finishReason) {
|
||||
if (snap.runFinished) tui.set({ phase: '脚本已停止', tone: 'ok' });
|
||||
else if (snap.retryWait > 0) tui.set({ phase: '等待重试', tone: 'warn' });
|
||||
@@ -285,6 +285,19 @@ export async function runSession(o) {
|
||||
else if (snap.route === 'list') tui.set({ phase: '列表页排队中', tone: 'info' });
|
||||
else tui.set({ phase: '运行中', tone: 'info' });
|
||||
}
|
||||
// 每刷完一门课推一条学分提醒;study.earned 已经按课程去重,重试不会重复推
|
||||
if (study && study.earned && study.earned.length && !stop.stopping) {
|
||||
for (const ev of study.earned) {
|
||||
tui.set({ phase: '发送 Bark 通知', tone: 'info' });
|
||||
await notifyCreditEarned(cfg, {
|
||||
course: ev.course,
|
||||
credit: ev.credit,
|
||||
total: study.creditEarned,
|
||||
completed: snap.completed,
|
||||
}, { log, warn });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 编解码器缺失:视频元素有源但解码错误(MEDIA_ERR_DECODE / SRC_NOT_SUPPORTED)
|
||||
if (!codecWarned && snap.video && snap.video.src && snap.video.err >= 3) {
|
||||
@@ -322,10 +335,14 @@ export async function runSession(o) {
|
||||
}
|
||||
|
||||
// 脚本停止 / 长时间无进展
|
||||
if (snap.runFinished) { finishReason = '脚本已停止:' + (snap.status || '未知原因'); break; }
|
||||
if (snap.runFinished) {
|
||||
// 标题已经说明「结束了」,这里只要有具体原因就够了
|
||||
finishReason = String(snap.status || '').trim() || '页面脚本已停止';
|
||||
break;
|
||||
}
|
||||
if (Date.now() - lastProgressAt > stallLimit) {
|
||||
finishReason = '超过 ' + Math.round(stallLimit / 60000) + ' 分钟没有任何进展(最后停在 ' +
|
||||
(snap.course || '列表') + '),退出等待重启';
|
||||
(snap.course || '列表') + ')';
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user