js: CD-Aware-AutoGather: 跳过不存在json的文件夹; 按七国顺序排序地方特产 (#1101)

This commit is contained in:
Patrick-Ze
2025-06-15 14:26:27 +08:00
committed by GitHub
parent 93261c55ee
commit 13c7d366e3
4 changed files with 34 additions and 19 deletions

View File

@@ -14,7 +14,9 @@
扫描完成后,将自动更新脚本可用的配置菜单。此时再次打开右键的`修改JS脚本自定义配置`,将看到新增了多个配置项,其中包含刚刚扫描到的材料目录。
![preview.png](https://github.com/user-attachments/assets/62961d83-cde4-4de6-9b87-bdaaf63896db)
<!-- ![preview.png](https://github.com/user-attachments/assets/62961d83-cde4-4de6-9b87-bdaaf63896db) -->
![preview.png](https://foruda.gitee.com/images/1749967868807757262/ada1abf2_9716310.png)
如果你订阅了很多地图追踪任务,那么扫描结果也会比较多,选项列表也会比较长,但不影响脚本运行。
@@ -37,9 +39,12 @@
如果不同的采集任务需要不同队伍,那请在调度器配置组里添加多次本脚本,然后分别设置不同的采集物和采集队伍。
> 采集任务可能用到的元素共有`火水雷风`4种此外还有挖矿类如钟离以及纳西妲两个类型可以考虑建立两支队伍`钟纳火水`和`钟纳雷风`,即可满足所有采集任务的需要。
支持使用配置组`更多功能`——`日志分析`分析运行记录(参考了[mno](https://github.com/Bedrockx)大佬的写法)。
![log_analysis.png](https://github.com/user-attachments/assets/9496d191-b46a-4705-b5b9-4e00fa7ef2a5)
<!-- ![log_analysis.png](https://github.com/user-attachments/assets/9496d191-b46a-4705-b5b9-4e00fa7ef2a5) -->
![log_analysis.png](https://foruda.gitee.com/images/1749967993135535153/3bbeecd3_9716310.png)
## 3. 清除运行记录(重置材料刷新时间)

View File

@@ -107,15 +107,16 @@ class ReachStopTime extends Error {
}
const runMode = settings.runMode;
const scriptName = getScriptItselfName();
// 结束真正由BGI产生的那次开始记录
startTime = fakeLogCore(scriptName, true);
log.info("当前运行模式:{0}", runMode);
if (runMode === "扫描文件夹更新可选材料列表") {
await runScanMode();
} else if (runMode === "采集选中的材料") {
const scriptName = getScriptItselfName();
// 配对关闭真正由BGI产生的那次开始记录
startTime = fakeLogCore(scriptName, true);
await runGatherMode();
// 重新开始一条记录与BGI产生的结束记录配对
fakeLogCore(scriptName, true, startTime);
} else if (runMode === "清除运行记录(重置材料刷新时间)") {
await runClearMode();
} else {
@@ -123,8 +124,6 @@ class ReachStopTime extends Error {
await sleep(3000);
await runScanMode();
}
// 重新开始一条记录与BGI产生的结束记录配对
fakeLogCore(scriptName, true, startTime);
})();
// 扫描文件夹更新可选材料列表
@@ -137,19 +136,31 @@ async function runScanMode() {
const templateText = file.readTextSync("settings.template.json");
let config = JSON.parse(templateText);
// 将地方特产按照国家顺序排序
const countryList = ["蒙德", "璃月", "稻妻", "须弥", "枫丹", "纳塔", "至冬"];
const sortedList = pathList.slice().sort((a, b) => {
const getRegion = p => p.split("\\")[2];
const aIndex = countryList.indexOf(getRegion(a));
const bIndex = countryList.indexOf(getRegion(b));
return (aIndex === -1 ? Infinity : aIndex) - (bIndex === -1 ? Infinity : bIndex);
});
// 3. 处理每个路径
let count = 0;
for (const path of pathList) {
for (const path of sortedList) {
const info = getCooldownInfoFromPath(path);
if (info.coolType !== CooldownType.Unknown) {
const jsonFiles = filterFilesInTaskDir(info.label);
if (jsonFiles.length === 0) {
log.info("{0}内无json文件跳过", path);
} else if (info.coolType === CooldownType.Unknown) {
log.warn("路径{0}未找到对应的刷新机制,跳过", path);
} else {
config.push({
name: info.name,
label: "⬇️ " + info.label,
type: "checkbox"
});
count += 1;
} else {
log.warn("路径{0}未找到对应的刷新机制,跳过", path);
}
}
// 4. 写入新的配置(格式化输出)
@@ -221,7 +232,7 @@ async function runClearMode() {
const resetTime = strftime(baseTime);
let account = await getCurrentAccount();
for (const pathTask of selectedMaterials) {
const jsonFiles = filterFilesInTaskDir(pathTask);
const jsonFiles = filterFilesInTaskDir(pathTask.label);
const recordFile = getRecordFilePath(account, pathTask);
const lines = jsonFiles.map((filePath) => {
return `${basename(filePath)}\t${resetTime}`;
@@ -238,8 +249,7 @@ function getRecordFilePath(account, pathTask) {
return `record/${account}/${taskName}.txt`;
}
function filterFilesInTaskDir(pathTask, ext=".json") {
const taskDir = pathTask.label;
function filterFilesInTaskDir(taskDir, ext=".json") {
const allFilesRaw = file.ReadPathSync("pathing\\" + taskDir);
const extFiles = [];
@@ -255,7 +265,7 @@ function filterFilesInTaskDir(pathTask, ext=".json") {
async function runPathTaskIfCooldownExpired(account, pathTask) {
const recordFile = getRecordFilePath(account, pathTask);
const jsonFiles = filterFilesInTaskDir(pathTask);
const jsonFiles = filterFilesInTaskDir(pathTask.label);
log.info("{0}共有{1}条路线", pathTask.label, jsonFiles.length);

View File

@@ -1,9 +1,9 @@
{
"manifest_version": 1,
"name": "带CD管理的自动采集",
"version": "1.0",
"version": "1.1",
"bgi_version": "0.45.0",
"description": "自动同步你通过BetterGI订阅的地图追踪任务执行采集任务并管理材料刷新时间支持多账号。\n首次运行前请先简单阅读说明推荐在线版 https://github.com/babalae/bettergi-scripts-list/tree/main/repo/js/CD-Aware-AutoGather \n本地版说明见脚本目录内的 README.md 文件",
"description": "自动同步你通过BetterGI订阅的地图追踪任务执行采集任务并管理材料刷新时间支持多账号。\n首次运行前请先简单阅读说明推荐在线版 https://gitee.com/babalae/bettergi-scripts-list/tree/main/repo/js/CD-Aware-AutoGather \n本地版说明见脚本目录内的 README.md 文件",
"authors": [
{
"name": "Ayaka-Main",

View File

@@ -2,7 +2,7 @@
{
"name": "runMode",
"type": "select",
"label": "首次运行前请先简单阅读说明,推荐在线版\n https://github.com/babalae/bettergi-scripts-list\n/tree/main/repo/js/CD-Aware-AutoGather \n本地版说明见脚本目录内的 README.md 文件",
"label": "首次运行前请先简单阅读说明,推荐在线版\n https://gitee.com/babalae/bettergi-scripts-list\n/tree/main/repo/js/CD-Aware-AutoGather \n本地版说明见脚本目录内的 README.md 文件",
"options": [
"扫描文件夹更新可选材料列表"
]