From f60b15cf4436d397333039af9b2663fc57458e9c Mon Sep 17 00:00:00 2001 From: this-Fish Date: Mon, 15 Dec 2025 09:50:25 +0800 Subject: [PATCH] =?UTF-8?q?=20JS=20:=20CD-Aware-AutoGather=20-=20=E5=B8=A6?= =?UTF-8?q?CD=E7=AE=A1=E7=90=86=E7=9A=84=E8=87=AA=E5=8A=A8=E9=87=87?= =?UTF-8?q?=E9=9B=86=201.7.9=20(#2499)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 先检查是否有可运行的路径再切换队伍、如果没有可运行路径即跳过任务、不再切换队伍 --- repo/js/CD-Aware-AutoGather/main.js | 50 ++++++++++++++++++++++- repo/js/CD-Aware-AutoGather/manifest.json | 2 +- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/repo/js/CD-Aware-AutoGather/main.js b/repo/js/CD-Aware-AutoGather/main.js index f17f988d1..423632a21 100644 --- a/repo/js/CD-Aware-AutoGather/main.js +++ b/repo/js/CD-Aware-AutoGather/main.js @@ -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; -} +} \ No newline at end of file diff --git a/repo/js/CD-Aware-AutoGather/manifest.json b/repo/js/CD-Aware-AutoGather/manifest.json index b7713678c..a164d1ace 100644 --- a/repo/js/CD-Aware-AutoGather/manifest.json +++ b/repo/js/CD-Aware-AutoGather/manifest.json @@ -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": [