Update winona.js

优化推送逻辑
This commit is contained in:
hlt1995 authored and GitHub committed 2025-12-11 09:57:56 +08:00
1 parent 0ed9e26df8
commit 9488f02af0
1 file changed
+51 -21
+51 -21
View File
@@ -66,6 +66,28 @@ class WnnTask {
Connection: "keep-alive" Connection: "keep-alive"
}; };
this.hasCriticalError = false; this.hasCriticalError = false;
this.errorMessages = []; // 存储错误信息
}
// 记录错误信息
recordError(errorType, message) {
const fullMessage = `❌ ${this.remark} ${errorType}: ${message}`;
this.errorMessages.push(fullMessage);
console.log(fullMessage);
}
// 汇总并发送错误通知
async sendErrorsIfAny() {
if (this.errorMessages.length > 0) {
// 如果有致命错误,优先发送
if (this.hasCriticalError) {
addNotifyMessage(this.errorMessages[0]);
} else {
// 非致命错误合并发送
const summary = `${this.remark} 执行过程中出现以下问题:\n${this.errorMessages.join('\n')}`;
addNotifyMessage(summary);
}
}
} }
async checkin() { async checkin() {
@@ -86,22 +108,16 @@ class WnnTask {
log("✅ 签到成功!"); log("✅ 签到成功!");
break; break;
case 600: case 600:
const tokenErrorMsg = `❌ ${this.remark} Token 失效,请重新获取!`; this.recordError("Token 失效", "请重新获取!");
log(tokenErrorMsg);
addNotifyMessage(tokenErrorMsg);
this.hasCriticalError = true; this.hasCriticalError = true;
return false; return false;
default: default:
const signErrorMsg = `❌ ${this.remark} 签到失败: ${JSON.stringify(response.data)}`; this.recordError("签到失败", JSON.stringify(response.data));
log(signErrorMsg);
addNotifyMessage(signErrorMsg);
this.hasCriticalError = true; this.hasCriticalError = true;
return false; return false;
} }
} catch (error) { } catch (error) {
const requestErrorMsg = `❌ ${this.remark} 签到请求异常: ${error.message}`; this.recordError("签到请求异常", error.message);
log(requestErrorMsg);
addNotifyMessage(requestErrorMsg);
this.hasCriticalError = true; this.hasCriticalError = true;
return false; return false;
} }
@@ -119,10 +135,10 @@ class WnnTask {
if (response.data.code === 200) { if (response.data.code === 200) {
log(`🌳 树木签到成功,获得 ${response.data.data.waterGram}g 水滴`); log(`🌳 树木签到成功,获得 ${response.data.data.waterGram}g 水滴`);
} else { } else {
log(`❌ 树木签到失败: ${JSON.stringify(response.data)}`); this.recordError("树木签到失败", JSON.stringify(response.data));
} }
} catch (error) { } catch (error) {
log(`❌ 树木签到请求异常: ${error.message}`); this.recordError("树木签到请求异常", error.message);
} }
} }
@@ -134,7 +150,7 @@ class WnnTask {
{ headers: this.headers } { headers: this.headers }
); );
} catch (error) { } catch (error) {
// 静默处理异常 // 静默处理异常,不记录错误
} }
} }
@@ -149,10 +165,10 @@ class WnnTask {
if (response.data.code === 200) { if (response.data.code === 200) {
log("✅ 浏览商城任务完成!"); log("✅ 浏览商城任务完成!");
} else { } else {
log(`❌ 浏览商城失败: ${JSON.stringify(response.data)}`); this.recordError("浏览商城失败", JSON.stringify(response.data));
} }
} catch (error) { } catch (error) {
log(`❌ 浏览商城请求异常: ${error.message}`); this.recordError("浏览商城请求异常", error.message);
} }
} }
@@ -169,10 +185,10 @@ class WnnTask {
} else if (response.data.code === 703) { } else if (response.data.code === 703) {
log("⚠️ 请勿频繁操作!"); log("⚠️ 请勿频繁操作!");
} else { } else {
log(`❌ 阅读文章失败: ${JSON.stringify(response.data)}`); this.recordError("阅读文章失败", JSON.stringify(response.data));
} }
} catch (error) { } catch (error) {
log(`❌ 阅读文章请求异常: ${error.message}`); this.recordError("阅读文章请求异常", error.message);
} }
} }
@@ -189,10 +205,10 @@ class WnnTask {
log(`💧 当前水滴数量: ${waterDrops}g`); log(`💧 当前水滴数量: ${waterDrops}g`);
return waterDrops; return waterDrops;
} else { } else {
log(`❌ 获取水滴失败: ${JSON.stringify(response.data)}`); this.recordError("获取水滴失败", JSON.stringify(response.data));
} }
} catch (error) { } catch (error) {
log(`❌ 获取水滴请求异常: ${error.message}`); this.recordError("获取水滴请求异常", error.message);
} }
return 0; return 0;
} }
@@ -208,6 +224,8 @@ class WnnTask {
log(`🌿 计划浇水 ${waterTimes} 次...`); log(`🌿 计划浇水 ${waterTimes} 次...`);
let waterErrors = [];
for (let i = 1; i <= waterTimes; i++) { for (let i = 1; i <= waterTimes; i++) {
try { try {
const response = await axios.post( const response = await axios.post(
@@ -219,17 +237,26 @@ class WnnTask {
if (response.data.code === 200) { if (response.data.code === 200) {
log(`✅ 第 ${i} 次浇水成功!`); log(`✅ 第 ${i} 次浇水成功!`);
} else { } else {
log(`❌ 浇水失败: ${JSON.stringify(response.data)}`); waterErrors.push(`第 ${i} 次浇水失败: ${JSON.stringify(response.data)}`);
} }
} catch (error) { } catch (error) {
log(`❌ 浇水请求异常: ${error.message}`); waterErrors.push(`第 ${i} 次浇水请求异常: ${error.message}`);
} }
await delay(); await delay();
} }
// 汇总浇水错误
if (waterErrors.length > 0) {
this.recordError("浇水过程中出现错误", `共 ${waterErrors.length} 次失败\n${waterErrors.slice(0, 3).join('\n')}${waterErrors.length > 3 ? '\n...等' : ''}`);
}
} }
async run(shareCode) { async run(shareCode) {
if (!(await this.checkin())) return; if (!(await this.checkin())) {
// 如果有致命错误,立即记录并返回
await this.sendErrorsIfAny();
return;
}
await delay(); await delay();
await this.treeCheckin(); await this.treeCheckin();
@@ -241,6 +268,9 @@ class WnnTask {
await this.readArticle(); await this.readArticle();
await delay(); await delay();
await this.waterTree(); await this.waterTree();
// 执行完成后发送错误汇总
await this.sendErrorsIfAny();
} }
} }