mirror of
https://github.com/babalae/bettergi-scripts-list.git
synced 2026-03-16 03:33:25 +08:00
JS : CD-Aware-AutoGather - 带CD管理的自动采集 1.7.9 (#2499)
先检查是否有可运行的路径再切换队伍、如果没有可运行路径即跳过任务、不再切换队伍
This commit is contained in:
@@ -144,11 +144,57 @@ async function runGatherMode() {
|
||||
let account = await get_profile_name();
|
||||
log.info("为{0}采集材料并管理CD", account);
|
||||
|
||||
// 1. 先检查是否有任何任务需要执行(CD已刷新)
|
||||
let hasExpiredTask = false;
|
||||
const defaultTimeValue = getDefaultTime();
|
||||
|
||||
for (const pathTask of selectedMaterials) {
|
||||
const recordFile = getRecordFilePath(account, pathTask);
|
||||
const jsonFiles = pathTask.jsonFiles;
|
||||
|
||||
// 读取记录文件(与原始逻辑完全相同)
|
||||
const recordMap = {};
|
||||
try {
|
||||
const text = file.readTextSync(recordFile);
|
||||
for (const line of text.split("\n")) {
|
||||
const [p, t] = line.trim().split("\t");
|
||||
if (p && t) {
|
||||
recordMap[p] = new Date(t);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
log.debug(`记录文件{0}不存在或格式错误`, recordFile);
|
||||
// 记录文件不存在或格式错误,说明有任务需要执行
|
||||
hasExpiredTask = true;
|
||||
break;
|
||||
}
|
||||
|
||||
// 检查是否有文件过期(使用相同的保底机制)
|
||||
for (const jsonPath of jsonFiles) {
|
||||
const fileName = basename(jsonPath);
|
||||
const lastTime = recordMap[fileName] || defaultTimeValue; // 相同的保底逻辑
|
||||
if (Date.now() > lastTime) {
|
||||
hasExpiredTask = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasExpiredTask) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasExpiredTask) {
|
||||
log.info("所有选中的材料都还在冷却中,无需执行");
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 有任务需要执行,现在才切换队伍
|
||||
await switchPartySafely(settings.partyName);
|
||||
currentParty = settings.partyName;
|
||||
|
||||
dispatcher.addTimer(new RealtimeTimer("AutoPick"));
|
||||
// 可在此处继续处理 selectedMaterials 列表
|
||||
// 3. 执行所有选中的任务(原始函数内部会再次检查CD)
|
||||
try {
|
||||
for (const pathTask of selectedMaterials) {
|
||||
await runPathTaskIfCooldownExpired(account, pathTask);
|
||||
@@ -583,4 +629,4 @@ function getSelectedMaterials() {
|
||||
}
|
||||
|
||||
return selectedMaterials;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"manifest_version": 1,
|
||||
"name": "带CD管理的自动采集",
|
||||
"version": "1.7.8",
|
||||
"version": "1.7.9",
|
||||
"bgi_version": "0.45.0",
|
||||
"description": "自动同步你通过BetterGI订阅的地图追踪任务,执行采集任务,并管理材料刷新时间(支持多账号)。\n首次使用前请先简单阅读说明(可在`全自动`——`JS脚本`页面,点击本脚本名称查看)",
|
||||
"authors": [
|
||||
|
||||
Reference in New Issue
Block a user