js:狗粮pro1.3.1,采集cd管理1.3.2,多层文件夹处理 (#1130)
This commit is contained in:
@@ -52,8 +52,6 @@ const DEFAULT_FIGHT_TIMEOUT_SECONDS = 120;
|
||||
// 检查记录文件是否存在
|
||||
let indexDoExist = false;
|
||||
for (const filePath of filesInSubFolder) {
|
||||
log.info(filePath);
|
||||
log.info(`records\\${accountName}.txt`);
|
||||
if (filePath === `records\\${accountName}.txt`) {
|
||||
indexDoExist = true;
|
||||
break;
|
||||
@@ -219,49 +217,6 @@ const DEFAULT_FIGHT_TIMEOUT_SECONDS = 120;
|
||||
runRouteA = Math.floor((now - epochTime) / (24 * 60 * 60 * 1000)) % 2 === 0;
|
||||
}
|
||||
|
||||
// 根据 runRouteA 的值给 runningRoute 赋值
|
||||
const runningRoute = runRouteA ? "A" : "B";
|
||||
const folderName = `${runningRoute}路线`;
|
||||
const filePathPreparation = `assets/ArtifactsPath/${folderName}/00准备`;
|
||||
// 运行准备路线
|
||||
prepare: {
|
||||
if (runnedToday) {
|
||||
break prepare;
|
||||
}
|
||||
//切换至好感队
|
||||
await switchPartyIfNeeded(friendshipPartyName);
|
||||
|
||||
// 读取文件夹中的文件名并处理
|
||||
const filePaths = file.readPathSync(filePathPreparation);
|
||||
const jsonFileNames = [];
|
||||
|
||||
for (const filePath of filePaths) {
|
||||
const fileName = basename(filePath); // 提取文件名
|
||||
if (fileName.endsWith('.json')) { // 检查文件名是否以 .json 结尾
|
||||
jsonFileNames.push(fileName); // 存储文件名
|
||||
}
|
||||
}
|
||||
|
||||
let currentTask = 0; // 当前任务计数器
|
||||
|
||||
// 执行准备路线的地图追踪文件
|
||||
for (const fileName of jsonFileNames) {
|
||||
const fullPath = fileName;
|
||||
await fakeLog(fileName, false, true, 0);
|
||||
currentTask += 1; // 更新当前任务计数器
|
||||
log.info(`当前进度:${fullPath}为准备${folderName}第${currentTask}/${jsonFileNames.length}个`);
|
||||
await pathingScript.runFile(fullPath);
|
||||
//捕获任务取消的信息并跳出循环
|
||||
try {
|
||||
await sleep(10); // 假设 sleep 是一个异步函数,休眠 10 毫秒
|
||||
} catch (error) {
|
||||
log.error(`发生错误: ${error}`);
|
||||
return false; // 终止循环
|
||||
}
|
||||
await fakeLog(fileName, false, false, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// 启用自动拾取的实时任务
|
||||
dispatcher.addTimer(new RealtimeTimer("AutoPick"));
|
||||
|
||||
@@ -446,7 +401,43 @@ async function runArtifactsPaths(runRouteA) {
|
||||
const filePathNormal = `assets/ArtifactsPath/${folderName}/01普通`;
|
||||
const filePathEnding = `assets/ArtifactsPath/${folderName}/02收尾`;
|
||||
const filePathExtra = `assets/ArtifactsPath/${folderName}/03额外`;
|
||||
const filePathPreparation = `assets/ArtifactsPath/${folderName}/00准备`;
|
||||
|
||||
// 运行准备路线(关闭拾取)
|
||||
dispatcher.ClearAllTriggers();
|
||||
{
|
||||
// 读取文件夹中的文件名并处理
|
||||
const filePaths = file.readPathSync(filePathPreparation);
|
||||
const jsonFileNames = [];
|
||||
|
||||
for (const filePath of filePaths) {
|
||||
const fileName = basename(filePath); // 提取文件名
|
||||
if (fileName.endsWith('.json')) { // 检查文件名是否以 .json 结尾
|
||||
jsonFileNames.push(fileName); // 存储文件名
|
||||
}
|
||||
}
|
||||
|
||||
let currentTask = 0; // 当前任务计数器
|
||||
|
||||
// 执行准备路线的地图追踪文件
|
||||
for (const fileName of jsonFileNames) {
|
||||
const fullPath = fileName;
|
||||
await fakeLog(fileName, false, true, 0);
|
||||
currentTask += 1; // 更新当前任务计数器
|
||||
log.info(`当前进度:${fullPath}为准备${folderName}第${currentTask}/${jsonFileNames.length}个`);
|
||||
await pathingScript.runFile(fullPath);
|
||||
//捕获任务取消的信息并跳出循环
|
||||
try {
|
||||
await sleep(10); // 假设 sleep 是一个异步函数,休眠 10 毫秒
|
||||
} catch (error) {
|
||||
log.error(`发生错误: ${error}`);
|
||||
return false; // 终止循环
|
||||
}
|
||||
await fakeLog(fileName, false, false, 0);
|
||||
}
|
||||
}
|
||||
// 启用自动拾取的实时任务
|
||||
dispatcher.addTimer(new RealtimeTimer("AutoPick"));
|
||||
// 运行普通路线
|
||||
{
|
||||
// 读取文件夹中的文件名并处理
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"manifest_version": 1,
|
||||
"name": "自动狗粮重制版",
|
||||
"version": "1.3.0",
|
||||
"version": "1.3.1",
|
||||
"tags": ["好感", "盗宝团", "愚人众", "鳄鱼", "兽肉", "狗粮"],
|
||||
"description": "通过不同好感任务卡时间后运行狗粮任务以提高狗粮总收益,需要正确配置好感队伍的战斗策略,并在自定义配置中指定好感和狗粮队伍名称",
|
||||
"authors": [
|
||||
|
||||
0
repo/js/多层文件夹处理/assets/文件1.txt
Normal file
0
repo/js/多层文件夹处理/assets/文件1.txt
Normal file
0
repo/js/多层文件夹处理/assets/文件2.json
Normal file
0
repo/js/多层文件夹处理/assets/文件2.json
Normal file
0
repo/js/多层文件夹处理/assets/文件3.json
Normal file
0
repo/js/多层文件夹处理/assets/文件3.json
Normal file
0
repo/js/多层文件夹处理/assets/文件夹1/子文件夹1/文件6.json
Normal file
0
repo/js/多层文件夹处理/assets/文件夹1/子文件夹1/文件6.json
Normal file
0
repo/js/多层文件夹处理/assets/文件夹1/文件4.json
Normal file
0
repo/js/多层文件夹处理/assets/文件夹1/文件4.json
Normal file
0
repo/js/多层文件夹处理/assets/文件夹1/文件5.json
Normal file
0
repo/js/多层文件夹处理/assets/文件夹1/文件5.json
Normal file
0
repo/js/多层文件夹处理/assets/文件夹2/文件7.json
Normal file
0
repo/js/多层文件夹处理/assets/文件夹2/文件7.json
Normal file
73
repo/js/多层文件夹处理/main.js
Normal file
73
repo/js/多层文件夹处理/main.js
Normal file
@@ -0,0 +1,73 @@
|
||||
// 定义 readFolder 函数
|
||||
/*
|
||||
该函数可以实现输入要处理的文件夹路径后,将其中所有文件/仅json文件按照原顺序存储在一个对象中,具体使用参考主函数
|
||||
*/
|
||||
async function readFolder(folderPath, onlyJson) {
|
||||
log.info(`开始读取文件夹:${folderPath}`);
|
||||
|
||||
// 新增一个堆栈,初始时包含 folderPath
|
||||
const folderStack = [folderPath];
|
||||
|
||||
// 新增一个数组,用于存储文件信息对象
|
||||
const files = [];
|
||||
|
||||
// 当堆栈不为空时,继续处理
|
||||
while (folderStack.length > 0) {
|
||||
// 从堆栈中弹出一个路径
|
||||
const currentPath = folderStack.pop();
|
||||
|
||||
// 读取当前路径下的所有文件和子文件夹路径
|
||||
const filesInSubFolder = file.ReadPathSync(currentPath);
|
||||
|
||||
// 临时数组,用于存储子文件夹路径
|
||||
const subFolders = [];
|
||||
for (const filePath of filesInSubFolder) {
|
||||
if (file.IsFolder(filePath)) {
|
||||
// 如果是文件夹,先存储到临时数组中
|
||||
subFolders.push(filePath);
|
||||
} else {
|
||||
// 如果是文件,根据 onlyJson 判断是否存储
|
||||
if (onlyJson) {
|
||||
if (filePath.endsWith(".json")) {
|
||||
const fileName = filePath.split('\\').pop(); // 提取文件名
|
||||
const folderPathArray = filePath.split('\\').slice(0, -1); // 提取文件夹路径数组
|
||||
files.push({
|
||||
fullPath: filePath,
|
||||
fileName: fileName,
|
||||
folderPathArray: folderPathArray
|
||||
});
|
||||
//log.info(`找到 JSON 文件:${filePath}`);
|
||||
}
|
||||
} else {
|
||||
const fileName = filePath.split('\\').pop(); // 提取文件名
|
||||
const folderPathArray = filePath.split('\\').slice(0, -1); // 提取文件夹路径数组
|
||||
files.push({
|
||||
fullPath: filePath,
|
||||
fileName: fileName,
|
||||
folderPathArray: folderPathArray
|
||||
});
|
||||
//log.info(`找到文件:${filePath}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 将临时数组中的子文件夹路径按原顺序压入堆栈
|
||||
folderStack.push(...subFolders.reverse()); // 反转子文件夹路径
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
// 主函数
|
||||
(async function () {
|
||||
// 调用 readFolder 函数测试
|
||||
const folderPath = settings.folderPath; // 文件夹路径
|
||||
const onlyJson = settings.onlyJson; // 是否只返回 JSON 文件
|
||||
|
||||
const files = await readFolder(folderPath, onlyJson);
|
||||
log.info(`处理结果:`);
|
||||
files.forEach(file => {
|
||||
log.info(`完整路径:${file.fullPath}`);
|
||||
log.info(`文件名:${file.fileName}`);
|
||||
log.info(`文件夹路径数组:${file.folderPathArray.join(", ")}`);//允许通过访问该数组的不同层级,例如判断材料种类等
|
||||
});
|
||||
})();
|
||||
13
repo/js/多层文件夹处理/manifest.json
Normal file
13
repo/js/多层文件夹处理/manifest.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"manifest_version": 1,
|
||||
"name": "多层文件夹处理",
|
||||
"version": "1.0",
|
||||
"description": "读取多层文件夹并进行处理的一种方法",
|
||||
"authors": [
|
||||
{
|
||||
"name": "mno"
|
||||
}
|
||||
],
|
||||
"settings_ui": "settings.json",
|
||||
"main": "main.js"
|
||||
}
|
||||
14
repo/js/多层文件夹处理/settings.json
Normal file
14
repo/js/多层文件夹处理/settings.json
Normal file
@@ -0,0 +1,14 @@
|
||||
[
|
||||
|
||||
{
|
||||
"name": "folderPath",
|
||||
"type": "input-text",
|
||||
"label": "要处理的文件夹在js文件夹中的路径",
|
||||
"default": "assets"
|
||||
},
|
||||
{
|
||||
"name": "onlyJson",
|
||||
"type": "checkbox",
|
||||
"label": "是否只处理json文件"
|
||||
}
|
||||
]
|
||||
@@ -86,7 +86,7 @@ async function fakeLog(name, isJs, isStart, duration) {
|
||||
|
||||
// 定义目标文件夹路径和记录文件路径
|
||||
const recordFolder = "record"; // 存储记录文件的文件夹路径
|
||||
const defaultTimeStamp = "2000-01-01T00:00:00.000Z"; // 固定的时间戳
|
||||
const defaultTimeStamp = "2023-10-13T00:00:00.000Z"; // 固定的时间戳
|
||||
|
||||
// 从 settings 中读取用户配置,并设置默认值
|
||||
const userSettings = {
|
||||
@@ -139,6 +139,62 @@ function removeJsonSuffix(fileName) {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
async function readFolder(folderPath, onlyJson) {
|
||||
log.info(`开始读取文件夹:${folderPath}`);
|
||||
|
||||
// 新增一个堆栈,初始时包含 folderPath
|
||||
const folderStack = [folderPath];
|
||||
|
||||
// 新增一个数组,用于存储文件信息对象
|
||||
const files = [];
|
||||
|
||||
// 当堆栈不为空时,继续处理
|
||||
while (folderStack.length > 0) {
|
||||
// 从堆栈中弹出一个路径
|
||||
const currentPath = folderStack.pop();
|
||||
|
||||
// 读取当前路径下的所有文件和子文件夹路径
|
||||
const filesInSubFolder = file.ReadPathSync(currentPath);
|
||||
|
||||
// 临时数组,用于存储子文件夹路径
|
||||
const subFolders = [];
|
||||
for (const filePath of filesInSubFolder) {
|
||||
if (file.IsFolder(filePath)) {
|
||||
// 如果是文件夹,先存储到临时数组中
|
||||
subFolders.push(filePath);
|
||||
} else {
|
||||
// 如果是文件,根据 onlyJson 判断是否存储
|
||||
if (onlyJson) {
|
||||
if (filePath.endsWith(".json")) {
|
||||
const fileName = filePath.split('\\').pop(); // 提取文件名
|
||||
const folderPathArray = filePath.split('\\').slice(0, -1); // 提取文件夹路径数组
|
||||
files.push({
|
||||
fullPath: filePath,
|
||||
fileName: fileName,
|
||||
folderPathArray: folderPathArray
|
||||
});
|
||||
//log.info(`找到 JSON 文件:${filePath}`);
|
||||
}
|
||||
} else {
|
||||
const fileName = filePath.split('\\').pop(); // 提取文件名
|
||||
const folderPathArray = filePath.split('\\').slice(0, -1); // 提取文件夹路径数组
|
||||
files.push({
|
||||
fullPath: filePath,
|
||||
fileName: fileName,
|
||||
folderPathArray: folderPathArray
|
||||
});
|
||||
//log.info(`找到文件:${filePath}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 将临时数组中的子文件夹路径按原顺序压入堆栈
|
||||
folderStack.push(...subFolders.reverse()); // 反转子文件夹路径
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
|
||||
(async function () {
|
||||
try {
|
||||
// 获取子文件夹路径
|
||||
@@ -166,7 +222,8 @@ function removeJsonSuffix(fileName) {
|
||||
if (!indexDoExist) {
|
||||
log.info("路径组1.txt 文件不存在,将尝试生成索引文件");
|
||||
}
|
||||
|
||||
dispatcher.addTimer(new RealtimeTimer("AutoPick"));
|
||||
await fakeLog("采集cd管理", true, false, 1000);
|
||||
// 循环处理多个路径组
|
||||
for (let i = 1; ; i++) {
|
||||
// 检查当前路径组的 cdtype 是否为空
|
||||
@@ -177,14 +234,13 @@ function removeJsonSuffix(fileName) {
|
||||
}
|
||||
|
||||
const targetFolder = `pathing/路径组${i}`; // 动态生成目标文件夹路径
|
||||
const filePaths = file.ReadPathSync(targetFolder);
|
||||
|
||||
const files = await readFolder(targetFolder, true);
|
||||
const filePaths = files.map(file => file.fullPath);
|
||||
// 如果文件夹为空,退出循环
|
||||
if (filePaths.length === 0) {
|
||||
log.info(`路径组${i} 文件夹为空,停止处理`);
|
||||
break;
|
||||
}
|
||||
|
||||
// 用于存储符合条件的文件名的数组
|
||||
const jsonFileNames = [];
|
||||
const entryMap = {};
|
||||
@@ -241,203 +297,193 @@ function removeJsonSuffix(fileName) {
|
||||
} else {
|
||||
log.error(`写入文件失败: ${recordFilePath}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
//当选择“执行任务(若不存在索引文件则自动创建)”时,执行类似路径执行的逻辑
|
||||
if (userSettings.operationMode === "执行任务(若不存在索引文件则自动创建)") {
|
||||
log.info("启用自动拾取的实时任务");
|
||||
|
||||
// 新增逻辑:当选择“执行任务(若不存在索引文件则自动创建)”时,执行类似路径执行的逻辑
|
||||
if (userSettings.operationMode === "执行任务(若不存在索引文件则自动创建)") {
|
||||
log.info("启用自动拾取的实时任务");
|
||||
dispatcher.addTimer(new RealtimeTimer("AutoPick"));
|
||||
await fakeLog("采集cd管理", true, false, 1000);
|
||||
// 获取子文件夹内的所有文件路径
|
||||
const recordFiles = file.ReadPathSync(subFolderPath);
|
||||
// 直接获取文件数量作为路径组数量
|
||||
const totalPathGroups = recordFiles.length;
|
||||
let groupNumber = i;
|
||||
const pathGroupFilePath = `${subFolderPath}/路径组${groupNumber}.txt`; // 动态生成路径组文件路径
|
||||
|
||||
// 外层循环:依次处理每个路径组
|
||||
for (let groupNumber = 1; groupNumber <= totalPathGroups; groupNumber++) {
|
||||
const pathGroupFilePath = `${subFolderPath}/路径组${groupNumber}.txt`; // 动态生成路径组文件路径
|
||||
genshin.returnMainUi();
|
||||
|
||||
genshin.returnMainUi();
|
||||
//切换到指定配队
|
||||
if (partyNamesArray[groupNumber - 1] !== "") {
|
||||
await genshin.switchParty(partyNamesArray[groupNumber - 1])
|
||||
}
|
||||
|
||||
//切换到指定配队
|
||||
if (partyNamesArray[groupNumber - 1] !== "") {
|
||||
await genshin.switchParty(partyNamesArray[groupNumber - 1])
|
||||
}
|
||||
genshin.returnMainUi();
|
||||
|
||||
genshin.returnMainUi();
|
||||
try {
|
||||
let pathGroupContent = await file.readText(pathGroupFilePath);
|
||||
let pathGroupEntries = pathGroupContent.trim().split('\n');
|
||||
for (let i = 0; i < pathGroupEntries.length; i++) {
|
||||
const entryWithTimestamp = pathGroupEntries[i].trim();
|
||||
const [entryName, entryTimestamp] = entryWithTimestamp.split('::');
|
||||
|
||||
try {
|
||||
let pathGroupContent = await file.readText(pathGroupFilePath);
|
||||
let pathGroupEntries = pathGroupContent.trim().split('\n');
|
||||
for (let i = 0; i < pathGroupEntries.length; i++) {
|
||||
const entryWithTimestamp = pathGroupEntries[i].trim();
|
||||
const [entryName, entryTimestamp] = entryWithTimestamp.split('::');
|
||||
// 查找对应的完整路径
|
||||
const fileEntry = files.find(file => file.fileName === `${entryName}.json`);
|
||||
const pathingFilePath = fileEntry.fullPath;
|
||||
|
||||
// 构造路径文件路径
|
||||
const pathingFilePath = `pathing/路径组${groupNumber}/${entryName}.json`;
|
||||
// 获取开始时间
|
||||
const startTime = new Date();
|
||||
|
||||
// 获取开始时间
|
||||
const startTime = new Date();
|
||||
|
||||
// 比较当前时间戳与任务的时间戳
|
||||
const entryDate = new Date(entryTimestamp);
|
||||
if (startTime <= entryDate) {
|
||||
log.info(`当前任务 ${entryName} 未刷新,跳过任务 ${i + 1}/${pathGroupEntries.length} 个`);
|
||||
await sleep(10);
|
||||
continue; // 跳过当前任务
|
||||
}
|
||||
|
||||
// 新增校验:若当前时间的小时数和 skipTimeRanges 一致,则跳过任务
|
||||
const currentHour = startTime.getHours(); // 获取当前时间的小时数
|
||||
const skipHours = userSettings.skipTimeRanges.split(';').map(Number); // 将 skipTimeRanges 转换为数字数组
|
||||
if (skipHours.includes(currentHour)) {
|
||||
log.info(`当前时间的小时数为 ${currentHour},在跳过时间范围内,跳过任务 ${entryName}`);
|
||||
continue; // 跳过当前任务
|
||||
}
|
||||
|
||||
|
||||
//伪造地图追踪开始的日志
|
||||
await fakeLog(entryName, false, true, 0);
|
||||
|
||||
// 日志输出当前任务信息
|
||||
log.info(`当前任务 ${entryName} 为第 ${i + 1}/${pathGroupEntries.length} 个`);
|
||||
|
||||
// 执行路径文件
|
||||
try {
|
||||
await pathingScript.runFile(pathingFilePath);
|
||||
log.info(`执行任务: ${entryName}`);
|
||||
} catch (error) {
|
||||
log.error(`路径文件 ${pathingFilePath} 不存在或执行失败: ${error}`);
|
||||
continue; // 跳过当前任务
|
||||
}
|
||||
|
||||
|
||||
|
||||
//捕获任务取消的信息并跳出循环
|
||||
try {
|
||||
await sleep(10); // 假设 sleep 是一个异步函数,休眠 10 毫秒
|
||||
} catch (error) {
|
||||
log.error(`发生错误: ${error}`);
|
||||
break; // 终止循环
|
||||
}
|
||||
|
||||
// 获取结束时间
|
||||
const endTime = new Date();
|
||||
|
||||
// 比较开始时间与结束时间
|
||||
const timeDiff = endTime.getTime() - startTime.getTime(); // 时间差(毫秒)
|
||||
|
||||
//伪造地图追踪结束的日志
|
||||
await fakeLog(entryName, false, false, timeDiff);
|
||||
|
||||
if (timeDiff > 3000) { // 时间差大于3秒
|
||||
// 获取当前路径组的 cdtype
|
||||
const currentCdType = pathGroupCdType[groupNumber - 1] || "未知类型";
|
||||
|
||||
// 初始化 newTimestamp 和 nextAvailableTime
|
||||
let newTimestamp;
|
||||
let nextAvailableTime;
|
||||
|
||||
// 根据 cdtype 执行不同的操作
|
||||
switch (currentCdType) {
|
||||
case "1次0点刷新":
|
||||
// 将任务文件中对应的时间戳改为下一个0点
|
||||
const tomorrow = new Date(startTime.getTime() + 24 * 60 * 60 * 1000);
|
||||
tomorrow.setHours(0, 0, 0, 0); // 设置为下一个0点
|
||||
newTimestamp = tomorrow.toISOString();
|
||||
nextAvailableTime = new Date(newTimestamp).toLocaleString(); // 转换为本地时间格式
|
||||
//log.info(`下一次可用时间为 ${nextAvailableTime}`);
|
||||
break;
|
||||
|
||||
case "2次0点刷新":
|
||||
// 将任务文件中对应的时间戳改为下下个0点
|
||||
const dayAfterTomorrow = new Date(startTime.getTime() + 48 * 60 * 60 * 1000);
|
||||
dayAfterTomorrow.setHours(0, 0, 0, 0); // 设置为下下个0点
|
||||
newTimestamp = dayAfterTomorrow.toISOString();
|
||||
nextAvailableTime = new Date(newTimestamp).toLocaleString(); // 转换为本地时间格式
|
||||
//log.info(`下一次可用时间为 ${nextAvailableTime}`);
|
||||
break;
|
||||
|
||||
case "3次0点刷新":
|
||||
// 将任务文件中对应的时间戳改为下下下个0点
|
||||
const twoDaysAfterTomorrow = new Date(startTime.getTime() + 72 * 60 * 60 * 1000);
|
||||
twoDaysAfterTomorrow.setHours(0, 0, 0, 0); // 设置为下下下个0点
|
||||
newTimestamp = twoDaysAfterTomorrow.toISOString();
|
||||
nextAvailableTime = new Date(newTimestamp).toLocaleString(); // 转换为本地时间格式
|
||||
//log.info(`下一次可用时间为 ${nextAvailableTime}`);
|
||||
break;
|
||||
|
||||
case "4点刷新":
|
||||
// 将任务文件中对应的时间戳改为下一个4点
|
||||
const next4AM = new Date(startTime.getTime());
|
||||
next4AM.setHours(4, 0, 0, 0); // 设置为当天的4点
|
||||
if (next4AM <= startTime) {
|
||||
next4AM.setDate(next4AM.getDate() + 1); // 如果当前时间已过4点,则设置为下一天的4点
|
||||
}
|
||||
newTimestamp = next4AM.toISOString();
|
||||
nextAvailableTime = new Date(newTimestamp).toLocaleString(); // 转换为本地时间格式
|
||||
//log.info(`下一次可用时间为 ${nextAvailableTime}`);
|
||||
break;
|
||||
|
||||
case "12小时刷新":
|
||||
// 将任务文件中对应的时间戳改为开始时间后12小时0分0秒
|
||||
newTimestamp = new Date(startTime.getTime() + 12 * 60 * 60 * 1000).toISOString();
|
||||
nextAvailableTime = new Date(newTimestamp).toLocaleString(); // 转换为本地时间格式
|
||||
//log.info(`下一次可用时间为 ${nextAvailableTime}`);
|
||||
break;
|
||||
|
||||
case "24小时刷新":
|
||||
// 将任务文件中对应的时间戳改为开始时间后24小时0分0秒
|
||||
newTimestamp = new Date(startTime.getTime() + 24 * 60 * 60 * 1000).toISOString();
|
||||
nextAvailableTime = new Date(newTimestamp).toLocaleString(); // 转换为本地时间格式
|
||||
//log.info(`下一次可用时间为 ${nextAvailableTime}`);
|
||||
break;
|
||||
|
||||
case "46小时刷新":
|
||||
// 将任务文件中对应的时间戳改为开始时间后46小时0分0秒
|
||||
newTimestamp = new Date(startTime.getTime() + 46 * 60 * 60 * 1000).toISOString();
|
||||
nextAvailableTime = new Date(newTimestamp).toLocaleString(); // 转换为本地时间格式
|
||||
//log.info(`下一次可用时间为 ${nextAvailableTime}`);
|
||||
break;
|
||||
|
||||
default:
|
||||
log.warn(`路径组${groupNumber} 的 cdtype 是 ${currentCdType},执行默认操作`);
|
||||
// 默认操作:将下一个可用时间设置为开始时间
|
||||
newTimestamp = startTime.toISOString();
|
||||
nextAvailableTime = startTime.toLocaleString(); // 转换为本地时间格式
|
||||
break;
|
||||
// 比较当前时间戳与任务的时间戳
|
||||
const entryDate = new Date(entryTimestamp);
|
||||
if (startTime <= entryDate) {
|
||||
log.info(`当前任务 ${entryName} 未刷新,跳过任务 ${i + 1}/${pathGroupEntries.length} 个`);
|
||||
await sleep(10);
|
||||
continue; // 跳过当前任务
|
||||
}
|
||||
|
||||
// 更新任务文件中的时间戳
|
||||
// 首先根据newTimestamp修改pathGroupEntries中对应项
|
||||
pathGroupEntries = pathGroupEntries.map(entry => {
|
||||
const [name, timestamp] = entry.split('::');
|
||||
if (name === entryName) {
|
||||
return `${name}::${newTimestamp}`;
|
||||
// 新增校验:若当前时间的小时数和 skipTimeRanges 一致,则跳过任务
|
||||
const currentHour = startTime.getHours(); // 获取当前时间的小时数
|
||||
const skipHours = userSettings.skipTimeRanges.split(';').map(Number); // 将 skipTimeRanges 转换为数字数组
|
||||
if (skipHours.includes(currentHour)) {
|
||||
log.info(`当前时间的小时数为 ${currentHour},在跳过时间范围内,跳过任务 ${entryName}`);
|
||||
continue; // 跳过当前任务
|
||||
}
|
||||
|
||||
|
||||
//伪造地图追踪开始的日志
|
||||
await fakeLog(entryName, false, true, 0);
|
||||
|
||||
// 日志输出当前任务信息
|
||||
log.info(`当前任务 ${entryName} 为第 ${i + 1}/${pathGroupEntries.length} 个`);
|
||||
|
||||
// 执行路径文件
|
||||
try {
|
||||
await pathingScript.runFile(pathingFilePath);
|
||||
log.info(`执行任务: ${entryName}`);
|
||||
} catch (error) {
|
||||
log.error(`路径文件 ${pathingFilePath} 不存在或执行失败: ${error}`);
|
||||
continue; // 跳过当前任务
|
||||
}
|
||||
|
||||
//捕获任务取消的信息并跳出循环
|
||||
try {
|
||||
await sleep(10); // 假设 sleep 是一个异步函数,休眠 10 毫秒
|
||||
} catch (error) {
|
||||
log.error(`发生错误: ${error}`);
|
||||
break; // 终止循环
|
||||
}
|
||||
|
||||
// 获取结束时间
|
||||
const endTime = new Date();
|
||||
|
||||
// 比较开始时间与结束时间
|
||||
const timeDiff = endTime.getTime() - startTime.getTime(); // 时间差(毫秒)
|
||||
|
||||
//伪造地图追踪结束的日志
|
||||
await fakeLog(entryName, false, false, timeDiff);
|
||||
|
||||
if (timeDiff > 3000) { // 时间差大于3秒
|
||||
// 获取当前路径组的 cdtype
|
||||
const currentCdType = pathGroupCdType[groupNumber - 1] || "未知类型";
|
||||
|
||||
// 初始化 newTimestamp 和 nextAvailableTime
|
||||
let newTimestamp;
|
||||
let nextAvailableTime;
|
||||
|
||||
// 根据 cdtype 执行不同的操作
|
||||
switch (currentCdType) {
|
||||
case "1次0点刷新":
|
||||
// 将任务文件中对应的时间戳改为下一个0点
|
||||
const tomorrow = new Date(startTime.getTime() + 24 * 60 * 60 * 1000);
|
||||
tomorrow.setHours(0, 0, 0, 0); // 设置为下一个0点
|
||||
newTimestamp = tomorrow.toISOString();
|
||||
nextAvailableTime = new Date(newTimestamp).toLocaleString(); // 转换为本地时间格式
|
||||
//log.info(`下一次可用时间为 ${nextAvailableTime}`);
|
||||
break;
|
||||
|
||||
case "2次0点刷新":
|
||||
// 将任务文件中对应的时间戳改为下下个0点
|
||||
const dayAfterTomorrow = new Date(startTime.getTime() + 48 * 60 * 60 * 1000);
|
||||
dayAfterTomorrow.setHours(0, 0, 0, 0); // 设置为下下个0点
|
||||
newTimestamp = dayAfterTomorrow.toISOString();
|
||||
nextAvailableTime = new Date(newTimestamp).toLocaleString(); // 转换为本地时间格式
|
||||
//log.info(`下一次可用时间为 ${nextAvailableTime}`);
|
||||
break;
|
||||
|
||||
case "3次0点刷新":
|
||||
// 将任务文件中对应的时间戳改为下下下个0点
|
||||
const twoDaysAfterTomorrow = new Date(startTime.getTime() + 72 * 60 * 60 * 1000);
|
||||
twoDaysAfterTomorrow.setHours(0, 0, 0, 0); // 设置为下下下个0点
|
||||
newTimestamp = twoDaysAfterTomorrow.toISOString();
|
||||
nextAvailableTime = new Date(newTimestamp).toLocaleString(); // 转换为本地时间格式
|
||||
//log.info(`下一次可用时间为 ${nextAvailableTime}`);
|
||||
break;
|
||||
|
||||
case "4点刷新":
|
||||
// 将任务文件中对应的时间戳改为下一个4点
|
||||
const next4AM = new Date(startTime.getTime());
|
||||
next4AM.setHours(4, 0, 0, 0); // 设置为当天的4点
|
||||
if (next4AM <= startTime) {
|
||||
next4AM.setDate(next4AM.getDate() + 1); // 如果当前时间已过4点,则设置为下一天的4点
|
||||
}
|
||||
newTimestamp = next4AM.toISOString();
|
||||
nextAvailableTime = new Date(newTimestamp).toLocaleString(); // 转换为本地时间格式
|
||||
//log.info(`下一次可用时间为 ${nextAvailableTime}`);
|
||||
break;
|
||||
|
||||
case "12小时刷新":
|
||||
// 将任务文件中对应的时间戳改为开始时间后12小时0分0秒
|
||||
newTimestamp = new Date(startTime.getTime() + 12 * 60 * 60 * 1000).toISOString();
|
||||
nextAvailableTime = new Date(newTimestamp).toLocaleString(); // 转换为本地时间格式
|
||||
//log.info(`下一次可用时间为 ${nextAvailableTime}`);
|
||||
break;
|
||||
|
||||
case "24小时刷新":
|
||||
// 将任务文件中对应的时间戳改为开始时间后24小时0分0秒
|
||||
newTimestamp = new Date(startTime.getTime() + 24 * 60 * 60 * 1000).toISOString();
|
||||
nextAvailableTime = new Date(newTimestamp).toLocaleString(); // 转换为本地时间格式
|
||||
//log.info(`下一次可用时间为 ${nextAvailableTime}`);
|
||||
break;
|
||||
|
||||
case "46小时刷新":
|
||||
// 将任务文件中对应的时间戳改为开始时间后46小时0分0秒
|
||||
newTimestamp = new Date(startTime.getTime() + 46 * 60 * 60 * 1000).toISOString();
|
||||
nextAvailableTime = new Date(newTimestamp).toLocaleString(); // 转换为本地时间格式
|
||||
//log.info(`下一次可用时间为 ${nextAvailableTime}`);
|
||||
break;
|
||||
|
||||
default:
|
||||
log.warn(`路径组${groupNumber} 的 cdtype 是 ${currentCdType},执行默认操作`);
|
||||
// 默认操作:将下一个可用时间设置为开始时间
|
||||
newTimestamp = startTime.toISOString();
|
||||
nextAvailableTime = startTime.toLocaleString(); // 转换为本地时间格式
|
||||
break;
|
||||
}
|
||||
return entry;
|
||||
});
|
||||
|
||||
// 然后根据pathGroupEntries修改pathGroupContent
|
||||
pathGroupContent = pathGroupEntries.join('\n');
|
||||
// 更新任务文件中的时间戳
|
||||
// 首先根据newTimestamp修改pathGroupEntries中对应项
|
||||
pathGroupEntries = pathGroupEntries.map(entry => {
|
||||
const [name, timestamp] = entry.split('::');
|
||||
if (name === entryName) {
|
||||
return `${name}::${newTimestamp}`;
|
||||
}
|
||||
return entry;
|
||||
});
|
||||
|
||||
// 最后将pathGroupContent写回原文件
|
||||
await file.writeText(pathGroupFilePath, pathGroupContent);
|
||||
log.info(`本任务执行大于3秒,cd信息已更新,下一次可用时间为 ${nextAvailableTime}`);
|
||||
// 然后根据pathGroupEntries修改pathGroupContent
|
||||
pathGroupContent = pathGroupEntries.join('\n');
|
||||
|
||||
// 最后将pathGroupContent写回原文件
|
||||
await file.writeText(pathGroupFilePath, pathGroupContent);
|
||||
log.info(`本任务执行大于3秒,cd信息已更新,下一次可用时间为 ${nextAvailableTime}`);
|
||||
}
|
||||
}
|
||||
log.info(`路径组${groupNumber} 的所有任务运行完成`);
|
||||
} catch (error) {
|
||||
log.error(`读取路径组文件 ${pathGroupFilePath} 时出错: ${error}`);
|
||||
}
|
||||
log.info(`路径组${groupNumber} 的所有任务运行完成`);
|
||||
} catch (error) {
|
||||
log.error(`读取路径组文件 ${pathGroupFilePath} 时出错: ${error}`);
|
||||
}
|
||||
}
|
||||
log.info('所有路径组的任务运行完成');
|
||||
|
||||
//伪造js开始的日志
|
||||
await fakeLog("采集cd管路", true, true, 0);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
log.error(`操作失败: ${error}`);
|
||||
}
|
||||
|
||||
//伪造js开始的日志
|
||||
await fakeLog("采集cd管路", true, true, 0);
|
||||
})();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"manifest_version": 1,
|
||||
"name": "采集cd管理",
|
||||
"version": "1.2",
|
||||
"version": "1.3.2",
|
||||
"bgi_version": "0.44.8",
|
||||
"description": "仅面对会操作文件和读readme的用户,基于文件夹操作自动管理采集路线的cd,会按照路径组的顺序依次运行,直到指定的时间,并会按照给定的cd类型,自动跳过未刷新的路线",
|
||||
"authors": [
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"label": "选择操作模式",
|
||||
"options": [
|
||||
"执行任务(若不存在索引文件则自动创建)",
|
||||
"重新生成索引文件(用于强制刷新CD或更新文件)"
|
||||
"重新生成索引文件(用于强制刷新CD)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user