feat(general): 通用脚本支持在选定的时机自动更新配置文件
This commit is contained in:
@@ -614,6 +614,12 @@ class GeneralConfig(LQConfig):
|
||||
"所有文件 (*)",
|
||||
OptionsValidator(["所有文件 (*)", "文件夹"]),
|
||||
)
|
||||
self.Script_UpdateConfigMode = OptionsConfigItem(
|
||||
"Script",
|
||||
"UpdateConfigMode",
|
||||
"Never",
|
||||
OptionsValidator(["Never", "Success", "Failure", "Always"]),
|
||||
)
|
||||
self.Script_LogPath = ConfigItem("Script", "LogPath", ".", FileValidator())
|
||||
self.Script_LogPathFormat = ConfigItem("Script", "LogPathFormat", "%Y-%m-%d")
|
||||
self.Script_LogTimeStart = ConfigItem(
|
||||
|
||||
@@ -280,8 +280,16 @@ class MaaManager(QObject):
|
||||
user_data["Data"][
|
||||
"LastSklandDate"
|
||||
] = datetime.now().strftime("%Y-%m-%d")
|
||||
logger.success(
|
||||
f"用户: {user[0]} - 森空岛签到成功",
|
||||
module=f"MAA调度器-{self.name}",
|
||||
)
|
||||
self.play_sound.emit("森空岛签到成功")
|
||||
else:
|
||||
logger.warning(
|
||||
f"用户: {user[0]} - 森空岛签到失败",
|
||||
module=f"MAA调度器-{self.name}",
|
||||
)
|
||||
self.play_sound.emit("森空岛签到失败")
|
||||
|
||||
elif user_data["Info"]["IfSkland"]:
|
||||
@@ -580,44 +588,12 @@ class MaaManager(QObject):
|
||||
self.log_check_mode = mode_book[mode]
|
||||
self.start_monitor()
|
||||
|
||||
# 处理MAA结果
|
||||
if self.maa_result == "Success!":
|
||||
|
||||
# 标记任务完成
|
||||
run_book[mode] = True
|
||||
|
||||
# 从配置文件中解析所需信息
|
||||
while not self.isInterruptionRequested:
|
||||
try:
|
||||
with self.maa_set_path.open(
|
||||
mode="r", encoding="utf-8"
|
||||
) as f:
|
||||
data = json.load(f)
|
||||
break
|
||||
except Exception as e:
|
||||
logger.exception(
|
||||
f"解析MAA配置文件时出现异常:{e}",
|
||||
module=f"MAA调度器-{self.name}",
|
||||
)
|
||||
self.sleep(1)
|
||||
|
||||
if not self.isInterruptionRequested:
|
||||
# 记录自定义基建索引
|
||||
user_data["Data"]["CustomInfrastPlanIndex"] = data[
|
||||
"Configurations"
|
||||
]["Default"]["Infrast.CustomInfrastPlanIndex"]
|
||||
|
||||
# 记录更新包路径
|
||||
if (
|
||||
data["Global"]["VersionUpdate.package"]
|
||||
and (
|
||||
self.maa_root_path
|
||||
/ data["Global"]["VersionUpdate.package"]
|
||||
).exists()
|
||||
):
|
||||
self.maa_update_package = data["Global"][
|
||||
"VersionUpdate.package"
|
||||
]
|
||||
|
||||
logger.info(
|
||||
f"用户: {user[0]} - MAA进程完成代理任务",
|
||||
module=f"MAA调度器-{self.name}",
|
||||
@@ -626,7 +602,6 @@ class MaaManager(QObject):
|
||||
"检测到MAA进程完成代理任务\n正在等待相关程序结束\n请等待10s"
|
||||
)
|
||||
|
||||
self.sleep(10)
|
||||
else:
|
||||
logger.error(
|
||||
f"用户: {user[0]} - 代理任务异常: {self.maa_result}",
|
||||
@@ -654,40 +629,6 @@ class MaaManager(QObject):
|
||||
|
||||
self.if_open_emulator = True
|
||||
|
||||
# 从配置文件中解析所需信息
|
||||
while not self.isInterruptionRequested:
|
||||
try:
|
||||
with self.maa_set_path.open(
|
||||
mode="r", encoding="utf-8"
|
||||
) as f:
|
||||
data = json.load(f)
|
||||
break
|
||||
except Exception as e:
|
||||
logger.exception(
|
||||
f"解析MAA配置文件时出现异常:{e}",
|
||||
module=f"MAA调度器-{self.name}",
|
||||
)
|
||||
self.sleep(1)
|
||||
|
||||
if not self.isInterruptionRequested:
|
||||
# 记录自定义基建索引
|
||||
if self.task_dict["Base"] == "False":
|
||||
user_data["Data"]["CustomInfrastPlanIndex"] = data[
|
||||
"Configurations"
|
||||
]["Default"]["Infrast.CustomInfrastPlanIndex"]
|
||||
|
||||
# 记录更新包路径
|
||||
if (
|
||||
data["Global"]["VersionUpdate.package"]
|
||||
and (
|
||||
self.maa_root_path
|
||||
/ data["Global"]["VersionUpdate.package"]
|
||||
).exists()
|
||||
):
|
||||
self.maa_update_package = data["Global"][
|
||||
"VersionUpdate.package"
|
||||
]
|
||||
|
||||
# 推送异常通知
|
||||
Notify.push_plyer(
|
||||
"用户自动代理出现异常!",
|
||||
@@ -699,6 +640,7 @@ class MaaManager(QObject):
|
||||
self.play_sound.emit("子任务失败")
|
||||
else:
|
||||
self.play_sound.emit(self.maa_result)
|
||||
|
||||
self.sleep(10)
|
||||
|
||||
# 任务结束后释放ADB
|
||||
@@ -737,6 +679,27 @@ class MaaManager(QObject):
|
||||
self.emulator_process_manager.kill()
|
||||
self.if_open_emulator = True
|
||||
|
||||
# 从配置文件中解析所需信息
|
||||
with self.maa_set_path.open(mode="r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
|
||||
# 记录自定义基建索引
|
||||
user_data["Data"]["CustomInfrastPlanIndex"] = data[
|
||||
"Configurations"
|
||||
]["Default"]["Infrast.CustomInfrastPlanIndex"]
|
||||
|
||||
# 记录更新包路径
|
||||
if (
|
||||
data["Global"]["VersionUpdate.package"]
|
||||
and (
|
||||
self.maa_root_path
|
||||
/ data["Global"]["VersionUpdate.package"]
|
||||
).exists()
|
||||
):
|
||||
self.maa_update_package = data["Global"][
|
||||
"VersionUpdate.package"
|
||||
]
|
||||
|
||||
# 记录剿灭情况
|
||||
if (
|
||||
mode == "Annihilation"
|
||||
|
||||
@@ -384,6 +384,31 @@ class GeneralManager(QObject):
|
||||
)
|
||||
|
||||
self.sleep(10)
|
||||
|
||||
# 更新脚本配置文件
|
||||
if self.set["Script"]["UpdateConfigMode"] in [
|
||||
"Success",
|
||||
"Always",
|
||||
]:
|
||||
|
||||
if self.set["Script"]["ConfigPathMode"] == "文件夹":
|
||||
shutil.copytree(
|
||||
self.script_config_path,
|
||||
self.data[sub[2]]["Path"] / "ConfigFiles",
|
||||
dirs_exist_ok=True,
|
||||
)
|
||||
else:
|
||||
shutil.copy(
|
||||
self.script_config_path,
|
||||
self.data[sub[2]]["Path"]
|
||||
/ "ConfigFiles"
|
||||
/ self.script_config_path.name,
|
||||
)
|
||||
logger.success(
|
||||
"通用脚本配置文件已更新",
|
||||
module=f"通用调度器-{self.name}",
|
||||
)
|
||||
|
||||
else:
|
||||
logger.error(
|
||||
f"配置: {sub[0]} - 代理任务异常: {self.script_result}",
|
||||
@@ -421,8 +446,33 @@ class GeneralManager(QObject):
|
||||
self.play_sound.emit("子任务失败")
|
||||
else:
|
||||
self.play_sound.emit(self.script_result)
|
||||
|
||||
self.sleep(10)
|
||||
|
||||
# 更新脚本配置文件
|
||||
if self.set["Script"]["UpdateConfigMode"] in [
|
||||
"Failure",
|
||||
"Always",
|
||||
]:
|
||||
|
||||
if self.set["Script"]["ConfigPathMode"] == "文件夹":
|
||||
shutil.copytree(
|
||||
self.script_config_path,
|
||||
self.data[sub[2]]["Path"] / "ConfigFiles",
|
||||
dirs_exist_ok=True,
|
||||
)
|
||||
else:
|
||||
shutil.copy(
|
||||
self.script_config_path,
|
||||
self.data[sub[2]]["Path"]
|
||||
/ "ConfigFiles"
|
||||
/ self.script_config_path.name,
|
||||
)
|
||||
logger.success(
|
||||
"通用脚本配置文件已更新",
|
||||
module=f"通用调度器-{self.name}",
|
||||
)
|
||||
|
||||
# 执行任务后脚本
|
||||
if (
|
||||
sub_data["Info"]["IfScriptAfterTask"]
|
||||
|
||||
@@ -2457,6 +2457,20 @@ class MemberManager(QWidget):
|
||||
configItem=self.config.Script_ConfigPath,
|
||||
parent=self,
|
||||
)
|
||||
self.card_UpdateConfigMode = ComboBoxSettingCard(
|
||||
icon=FluentIcon.PAGE_RIGHT,
|
||||
title="脚本配置文件更新时机",
|
||||
content="在选定的时机自动更新配置文件",
|
||||
texts=[
|
||||
"从不",
|
||||
"仅任务成功后",
|
||||
"仅任务失败后",
|
||||
"任务完成后",
|
||||
],
|
||||
qconfig=self.config,
|
||||
configItem=self.config.Script_UpdateConfigMode,
|
||||
parent=self,
|
||||
)
|
||||
self.card_LogPath = PathSettingCard(
|
||||
icon=FluentIcon.FOLDER,
|
||||
title="脚本日志文件路径 - [必填]",
|
||||
@@ -2549,6 +2563,7 @@ class MemberManager(QWidget):
|
||||
Layout.addWidget(self.card_Arguments)
|
||||
Layout.addWidget(self.card_IfTrackProcess)
|
||||
Layout.addWidget(self.card_ConfigPath)
|
||||
Layout.addWidget(self.card_UpdateConfigMode)
|
||||
Layout.addWidget(self.card_LogPath)
|
||||
Layout.addWidget(self.card_LogPathFormat)
|
||||
Layout.addLayout(h_layout)
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
"main_version": "4.4.1.1",
|
||||
"version_info": {
|
||||
"4.4.1.1": {
|
||||
"新增功能": [
|
||||
"通用脚本支持在选定的时机自动更新配置文件"
|
||||
],
|
||||
"修复BUG": [
|
||||
"修复MAA掉落物统计功能",
|
||||
"修复模拟器界面被异常关闭且无法重新打开的问题"
|
||||
|
||||
Reference in New Issue
Block a user