feat(general): 通用脚本支持在选定的时机自动更新配置文件

This commit is contained in:
DLmaster361
2025-07-18 21:48:39 +08:00
parent 9b492b5e0d
commit 1b4bb6fccc
5 changed files with 106 additions and 69 deletions

View File

@@ -614,6 +614,12 @@ class GeneralConfig(LQConfig):
"所有文件 (*)", "所有文件 (*)",
OptionsValidator(["所有文件 (*)", "文件夹"]), OptionsValidator(["所有文件 (*)", "文件夹"]),
) )
self.Script_UpdateConfigMode = OptionsConfigItem(
"Script",
"UpdateConfigMode",
"Never",
OptionsValidator(["Never", "Success", "Failure", "Always"]),
)
self.Script_LogPath = ConfigItem("Script", "LogPath", ".", FileValidator()) self.Script_LogPath = ConfigItem("Script", "LogPath", ".", FileValidator())
self.Script_LogPathFormat = ConfigItem("Script", "LogPathFormat", "%Y-%m-%d") self.Script_LogPathFormat = ConfigItem("Script", "LogPathFormat", "%Y-%m-%d")
self.Script_LogTimeStart = ConfigItem( self.Script_LogTimeStart = ConfigItem(

View File

@@ -280,8 +280,16 @@ class MaaManager(QObject):
user_data["Data"][ user_data["Data"][
"LastSklandDate" "LastSklandDate"
] = datetime.now().strftime("%Y-%m-%d") ] = datetime.now().strftime("%Y-%m-%d")
logger.success(
f"用户: {user[0]} - 森空岛签到成功",
module=f"MAA调度器-{self.name}",
)
self.play_sound.emit("森空岛签到成功") self.play_sound.emit("森空岛签到成功")
else: else:
logger.warning(
f"用户: {user[0]} - 森空岛签到失败",
module=f"MAA调度器-{self.name}",
)
self.play_sound.emit("森空岛签到失败") self.play_sound.emit("森空岛签到失败")
elif user_data["Info"]["IfSkland"]: elif user_data["Info"]["IfSkland"]:
@@ -580,44 +588,12 @@ class MaaManager(QObject):
self.log_check_mode = mode_book[mode] self.log_check_mode = mode_book[mode]
self.start_monitor() self.start_monitor()
# 处理MAA结果
if self.maa_result == "Success!": if self.maa_result == "Success!":
# 标记任务完成 # 标记任务完成
run_book[mode] = True 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( logger.info(
f"用户: {user[0]} - MAA进程完成代理任务", f"用户: {user[0]} - MAA进程完成代理任务",
module=f"MAA调度器-{self.name}", module=f"MAA调度器-{self.name}",
@@ -626,7 +602,6 @@ class MaaManager(QObject):
"检测到MAA进程完成代理任务\n正在等待相关程序结束\n请等待10s" "检测到MAA进程完成代理任务\n正在等待相关程序结束\n请等待10s"
) )
self.sleep(10)
else: else:
logger.error( logger.error(
f"用户: {user[0]} - 代理任务异常: {self.maa_result}", f"用户: {user[0]} - 代理任务异常: {self.maa_result}",
@@ -654,40 +629,6 @@ class MaaManager(QObject):
self.if_open_emulator = True 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( Notify.push_plyer(
"用户自动代理出现异常!", "用户自动代理出现异常!",
@@ -699,7 +640,8 @@ class MaaManager(QObject):
self.play_sound.emit("子任务失败") self.play_sound.emit("子任务失败")
else: else:
self.play_sound.emit(self.maa_result) self.play_sound.emit(self.maa_result)
self.sleep(10)
self.sleep(10)
# 任务结束后释放ADB # 任务结束后释放ADB
try: try:
@@ -737,6 +679,27 @@ class MaaManager(QObject):
self.emulator_process_manager.kill() self.emulator_process_manager.kill()
self.if_open_emulator = True 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 ( if (
mode == "Annihilation" mode == "Annihilation"

View File

@@ -384,6 +384,31 @@ class GeneralManager(QObject):
) )
self.sleep(10) 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: else:
logger.error( logger.error(
f"配置: {sub[0]} - 代理任务异常: {self.script_result}", f"配置: {sub[0]} - 代理任务异常: {self.script_result}",
@@ -421,8 +446,33 @@ class GeneralManager(QObject):
self.play_sound.emit("子任务失败") self.play_sound.emit("子任务失败")
else: else:
self.play_sound.emit(self.script_result) self.play_sound.emit(self.script_result)
self.sleep(10) 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 ( if (
sub_data["Info"]["IfScriptAfterTask"] sub_data["Info"]["IfScriptAfterTask"]

View File

@@ -2457,6 +2457,20 @@ class MemberManager(QWidget):
configItem=self.config.Script_ConfigPath, configItem=self.config.Script_ConfigPath,
parent=self, 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( self.card_LogPath = PathSettingCard(
icon=FluentIcon.FOLDER, icon=FluentIcon.FOLDER,
title="脚本日志文件路径 - [必填]", title="脚本日志文件路径 - [必填]",
@@ -2549,6 +2563,7 @@ class MemberManager(QWidget):
Layout.addWidget(self.card_Arguments) Layout.addWidget(self.card_Arguments)
Layout.addWidget(self.card_IfTrackProcess) Layout.addWidget(self.card_IfTrackProcess)
Layout.addWidget(self.card_ConfigPath) Layout.addWidget(self.card_ConfigPath)
Layout.addWidget(self.card_UpdateConfigMode)
Layout.addWidget(self.card_LogPath) Layout.addWidget(self.card_LogPath)
Layout.addWidget(self.card_LogPathFormat) Layout.addWidget(self.card_LogPathFormat)
Layout.addLayout(h_layout) Layout.addLayout(h_layout)

View File

@@ -2,6 +2,9 @@
"main_version": "4.4.1.1", "main_version": "4.4.1.1",
"version_info": { "version_info": {
"4.4.1.1": { "4.4.1.1": {
"新增功能": [
"通用脚本支持在选定的时机自动更新配置文件"
],
"修复BUG": [ "修复BUG": [
"修复MAA掉落物统计功能", "修复MAA掉落物统计功能",
"修复模拟器界面被异常关闭且无法重新打开的问题" "修复模拟器界面被异常关闭且无法重新打开的问题"