fix: 主要核心后端添加报错捕获机制

This commit is contained in:
DLmaster361
2025-09-28 20:38:54 +08:00
parent dfc403733f
commit 06770eb3cc
36 changed files with 357 additions and 264 deletions

View File

@@ -1,5 +1,6 @@
# AUTO-MAS: A Multi-Script, Multi-Config Management and Automation Software
# Copyright © 2024-2025 DLmaster361
# Copyright © 2025 AUTO-MAS Team
# This file is part of AUTO-MAS.
@@ -47,7 +48,7 @@ class MaaManager:
"""MAA控制器"""
def __init__(
self, mode: str, script_id: uuid.UUID, user_id: Optional[uuid.UUID], ws_id: str
self, mode: str, script_id: uuid.UUID, user_id: Optional[uuid.UUID], ws_id: str
):
super().__init__()
@@ -100,7 +101,7 @@ class MaaManager:
if not self.maa_set_path.exists():
return "MAA配置文件不存在, 请检查MAA路径设置"
if (self.mode != "设置脚本" or self.user_id is not None) and not (
Path.cwd() / f"data/{self.script_id}/Default/ConfigFile/gui.json"
Path.cwd() / f"data/{self.script_id}/Default/ConfigFile/gui.json"
).exists():
return "未完成 MAA 全局设置, 请先设置 MAA"
return "Success!"
@@ -141,7 +142,7 @@ class MaaManager:
}
for uid, config in self.user_config.items()
if config.get("Info", "Status")
and config.get("Info", "RemainedDay") != 0
and config.get("Info", "RemainedDay") != 0
]
self.user_list = sorted(
self.user_list,
@@ -160,10 +161,10 @@ class MaaManager:
# # 执行情况预处理
for _ in self.user_list:
if (
self.user_config[uuid.UUID(_["user_id"])].get(
"Data", "LastProxyDate"
)
!= self.curdate
self.user_config[uuid.UUID(_["user_id"])].get(
"Data", "LastProxyDate"
)
!= self.curdate
):
await self.user_config[uuid.UUID(_["user_id"])].set(
"Data", "LastProxyDate", self.curdate
@@ -178,8 +179,8 @@ class MaaManager:
self.cur_user_data = self.user_config[uuid.UUID(user["user_id"])]
if (self.script_config.get("Run", "ProxyTimesLimit") == 0) or (
self.cur_user_data.get("Data", "ProxyTimes")
< self.script_config.get("Run", "ProxyTimesLimit")
self.cur_user_data.get("Data", "ProxyTimes")
< self.script_config.get("Run", "ProxyTimesLimit")
):
user["status"] = "运行"
await Config.send_json(
@@ -212,18 +213,18 @@ class MaaManager:
self.cur_user_data.get("Info", "Annihilation") == "Close"
),
"Routine": self.cur_user_data.get("Info", "Mode") == "复杂"
and not self.cur_user_data.get("Info", "Routine"),
and not self.cur_user_data.get("Info", "Routine"),
}
self.user_logs_list = []
self.user_start_time = datetime.now()
if self.cur_user_data.get(
"Info", "IfSkland"
"Info", "IfSkland"
) and self.cur_user_data.get("Info", "SklandToken"):
if self.cur_user_data.get(
"Data", "LastSklandDate"
"Data", "LastSklandDate"
) != datetime.now().strftime("%Y-%m-%d"):
await Config.send_json(
@@ -268,8 +269,8 @@ class MaaManager:
)
if (
skland_result["总计"] > 0
and len(skland_result["失败"]) == 0
skland_result["总计"] > 0
and len(skland_result["失败"]) == 0
):
await self.cur_user_data.set(
"Data",
@@ -299,13 +300,13 @@ class MaaManager:
# 剿灭模式;满足条件跳过剿灭
if (
mode == "Annihilation"
and self.script_config.get("Run", "AnnihilationWeeklyLimit")
and datetime.strptime(
self.cur_user_data.get("Data", "LastAnnihilationDate"),
"%Y-%m-%d",
).isocalendar()[:2]
== datetime.strptime(self.curdate, "%Y-%m-%d").isocalendar()[:2]
mode == "Annihilation"
and self.script_config.get("Run", "AnnihilationWeeklyLimit")
and datetime.strptime(
self.cur_user_data.get("Data", "LastAnnihilationDate"),
"%Y-%m-%d",
).isocalendar()[:2]
== datetime.strptime(self.curdate, "%Y-%m-%d").isocalendar()[:2]
):
logger.info(
f"用户: {user['user_id']} - 本周剿灭模式已达上限, 跳过执行剿灭任务"
@@ -316,11 +317,11 @@ class MaaManager:
self.weekly_annihilation_limit_reached = False
if (
self.cur_user_data.get("Info", "Mode") == "详细"
and not (
self.cur_user_data.get("Info", "Mode") == "详细"
and not (
Path.cwd()
/ f"data/{self.script_id}/{user['user_id']}/ConfigFile/gui.json"
).exists()
).exists()
):
logger.error(
f"用户: {user['user_id']} - 未找到日常详细配置文件"
@@ -410,8 +411,8 @@ class MaaManager:
].split()
# 如果是快捷方式, 进行解析
if (
self.emulator_path.suffix == ".lnk"
and self.emulator_path.exists()
self.emulator_path.suffix == ".lnk"
and self.emulator_path.exists()
):
try:
shell = win32com.client.Dispatch("WScript.Shell")
@@ -520,7 +521,7 @@ class MaaManager:
f"更新静默进程标记: {self.emulator_path}, 标记有效时间: {datetime.now() + timedelta(seconds=self.wait_time + 10)}"
)
Config.silence_dict[self.emulator_path] = (
datetime.now() + timedelta(seconds=self.wait_time + 10)
datetime.now() + timedelta(seconds=self.wait_time + 10)
)
await self.search_ADB_address()
@@ -641,11 +642,11 @@ class MaaManager:
# 记录更新包路径
if (
data["Global"]["VersionUpdate.package"]
and (
data["Global"]["VersionUpdate.package"]
and (
self.maa_root_path
/ data["Global"]["VersionUpdate.package"]
).exists()
).exists()
):
self.maa_update_package = data["Global"][
"VersionUpdate.package"
@@ -653,8 +654,8 @@ class MaaManager:
# 记录剿灭情况
if (
mode == "Annihilation"
and self.weekly_annihilation_limit_reached
mode == "Annihilation"
and self.weekly_annihilation_limit_reached
):
await self.cur_user_data.set(
"Data", "LastAnnihilationDate", self.curdate
@@ -887,8 +888,8 @@ class MaaManager:
if self.run_book["Annihilation"] and self.run_book["Routine"]:
# 成功完成代理的用户修改相关参数
if (
self.cur_user_data.get("Data", "ProxyTimes") == 0
and self.cur_user_data.get("Info", "RemainedDay") != -1
self.cur_user_data.get("Data", "ProxyTimes") == 0
and self.cur_user_data.get("Info", "RemainedDay") != -1
):
await self.cur_user_data.set(
"Info",
@@ -967,9 +968,9 @@ class MaaManager:
Config.if_ignore_silence.remove(self.script_id)
if (
self.mode == "自动代理"
and hasattr(self, "index")
and self.user_list[self.index]["status"] == "运行"
self.mode == "自动代理"
and hasattr(self, "index")
and self.user_list[self.index]["status"] == "运行"
):
if not self.maa_update_package:
@@ -999,9 +1000,9 @@ class MaaManager:
await self.result_record()
elif (
self.mode == "人工排查"
and hasattr(self, "index")
and self.user_list[self.index]["status"] == "运行"
self.mode == "人工排查"
and hasattr(self, "index")
and self.user_list[self.index]["status"] == "运行"
):
await self.result_record()
@@ -1063,14 +1064,14 @@ class MaaManager:
elif self.mode == "设置脚本":
(
Path.cwd()
/ f"data/{self.script_id}/{self.user_id if self.user_id else 'Default'}/ConfigFile"
Path.cwd()
/ f"data/{self.script_id}/{self.user_id if self.user_id else 'Default'}/ConfigFile"
).mkdir(parents=True, exist_ok=True)
shutil.copy(
self.maa_set_path,
(
Path.cwd()
/ f"data/{self.script_id}/{self.user_id if self.user_id else 'Default'}/ConfigFile/gui.json"
Path.cwd()
/ f"data/{self.script_id}/{self.user_id if self.user_id else 'Default'}/ConfigFile/gui.json"
),
)
@@ -1232,12 +1233,12 @@ class MaaManager:
if "完成任务: Infrast" in log or "完成任务: 基建换班" in log:
self.task_dict["Base"] = "False"
if (
"完成任务: Fight" in log
or "完成任务: 刷理智" in log
or (
"完成任务: Fight" in log
or "完成任务: 刷理智" in log
or (
self.log_check_mode == "Annihilation"
and "任务出错: 刷理智" in log
)
)
):
self.task_dict["Combat"] = "False"
if "完成任务: Mall" in log or "完成任务: 获取信用及购物" in log:
@@ -1264,13 +1265,13 @@ class MaaManager:
self.maa_result = "MAA在完成任务前中止"
elif (
"MaaAssistantArknights GUI exited" in log
or not await self.maa_process_manager.is_running()
"MaaAssistantArknights GUI exited" in log
or not await self.maa_process_manager.is_running()
):
self.maa_result = "MAA在完成任务前退出"
elif datetime.now() - latest_time > timedelta(
minutes=self.script_config.get("Run", f"{self.log_check_mode}TimeLimit")
minutes=self.script_config.get("Run", f"{self.log_check_mode}TimeLimit")
):
self.maa_result = "MAA进程超时"
@@ -1287,8 +1288,8 @@ class MaaManager:
elif "已停止" in log:
self.maa_result = "MAA在完成任务前中止"
elif (
"MaaAssistantArknights GUI exited" in log
or not await self.maa_process_manager.is_running()
"MaaAssistantArknights GUI exited" in log
or not await self.maa_process_manager.is_running()
):
self.maa_result = "MAA在完成任务前退出"
else:
@@ -1325,17 +1326,17 @@ class MaaManager:
elif self.cur_user_data.get("Info", "Mode") == "详细":
shutil.copy(
(
Path.cwd()
/ f"data/{self.script_id}/{self.user_list[self.index]['user_id']}/ConfigFile/gui.json"
Path.cwd()
/ f"data/{self.script_id}/{self.user_list[self.index]['user_id']}/ConfigFile/gui.json"
),
self.maa_set_path,
)
elif self.mode == "设置脚本":
if (
self.user_id is None
and (
self.user_id is None
and (
Path.cwd() / f"data/{self.script_id}/Default/ConfigFile/gui.json"
).exists()
).exists()
):
shutil.copy(
(Path.cwd() / f"data/{self.script_id}/Default/ConfigFile/gui.json"),
@@ -1343,21 +1344,21 @@ class MaaManager:
)
elif self.user_id is not None:
if (
Path.cwd()
/ f"data/{self.script_id}/{self.user_id}/ConfigFile/gui.json"
Path.cwd()
/ f"data/{self.script_id}/{self.user_id}/ConfigFile/gui.json"
).exists():
shutil.copy(
(
Path.cwd()
/ f"data/{self.script_id}/{self.user_id}/ConfigFile/gui.json"
Path.cwd()
/ f"data/{self.script_id}/{self.user_id}/ConfigFile/gui.json"
),
self.maa_set_path,
)
else:
shutil.copy(
(
Path.cwd()
/ f"data/{self.script_id}/Default/ConfigFile/gui.json"
Path.cwd()
/ f"data/{self.script_id}/Default/ConfigFile/gui.json"
),
self.maa_set_path,
)
@@ -1378,10 +1379,10 @@ class MaaManager:
if self.mode == "自动代理" and mode in ["Annihilation", "Routine"]:
if (self.index == len(self.user_list) - 1) or (
self.user_config[
uuid.UUID(self.user_list[self.index + 1]["user_id"])
].get("Info", "Mode")
== "详细"
self.user_config[
uuid.UUID(self.user_list[self.index + 1]["user_id"])
].get("Info", "Mode")
== "详细"
):
data["Configurations"]["Default"][
"MainFunction.PostActions"
@@ -1459,8 +1460,8 @@ class MaaManager:
# 整理任务顺序
if (
mode == "Annihilation"
or self.cur_user_data.get("Info", "Mode") == "简洁"
mode == "Annihilation"
or self.cur_user_data.get("Info", "Mode") == "简洁"
):
data["Configurations"]["Default"]["TaskQueue.Order.WakeUp"] = "0"
data["Configurations"]["Default"]["TaskQueue.Order.Recruiting"] = "1"
@@ -1581,8 +1582,8 @@ class MaaManager:
if self.cur_user_data.get("Info", "InfrastMode") == "Custom":
if (
Path.cwd()
/ f"data/{self.script_id}/{self.user_list[self.index]['user_id']}/Infrastructure/infrastructure.json"
Path.cwd()
/ f"data/{self.script_id}/{self.user_list[self.index]['user_id']}/Infrastructure/infrastructure.json"
).exists():
data["Configurations"]["Default"][
@@ -1630,8 +1631,8 @@ class MaaManager:
# 基建模式
if (
data["Configurations"]["Default"]["Infrast.InfrastMode"]
== "Custom"
data["Configurations"]["Default"]["Infrast.InfrastMode"]
== "Custom"
):
data["Configurations"]["Default"][
"Infrast.CustomInfrastPlanIndex"
@@ -1856,11 +1857,11 @@ class MaaManager:
env = Environment(loader=FileSystemLoader(str(Path.cwd() / "res/html")))
if mode == "代理结果" and (
Config.get("Notify", "SendTaskResultTime") == "任何时刻"
or (
Config.get("Notify", "SendTaskResultTime") == "仅失败时"
and message["uncompleted_count"] != 0
)
Config.get("Notify", "SendTaskResultTime") == "任何时刻"
or (
Config.get("Notify", "SendTaskResultTime") == "仅失败时"
and message["uncompleted_count"] != 0
)
):
# 生成文本通知内容
message_text = (
@@ -1907,12 +1908,12 @@ class MaaManager:
if webhook.get("enabled", True):
try:
await Notify.CustomWebhookPush(
title,
f"{message_text}\n\nAUTO-MAS 敬上",
webhook
title, f"{message_text}\n\nAUTO-MAS 敬上", webhook
)
except Exception as e:
logger.error(f"自定义Webhook推送失败 ({webhook.get('name', 'Unknown')}): {e}")
logger.error(
f"自定义Webhook推送失败 ({webhook.get('name', 'Unknown')}): {e}"
)
elif mode == "统计信息":
@@ -1973,16 +1974,16 @@ class MaaManager:
if webhook.get("enabled", True):
try:
await Notify.CustomWebhookPush(
title,
f"{message_text}\n\nAUTO-MAS 敬上",
webhook
title, f"{message_text}\n\nAUTO-MAS 敬上", webhook
)
except Exception as e:
logger.error(f"自定义Webhook推送失败 ({webhook.get('name', 'Unknown')}): {e}")
logger.error(
f"自定义Webhook推送失败 ({webhook.get('name', 'Unknown')}): {e}"
)
# 发送用户单独通知
if self.cur_user_data.get("Notify", "Enabled") and self.cur_user_data.get(
"Notify", "IfSendStatistic"
"Notify", "IfSendStatistic"
):
# 发送邮件通知
@@ -2023,12 +2024,12 @@ class MaaManager:
if webhook.get("enabled", True):
try:
await Notify.CustomWebhookPush(
title,
f"{message_text}\n\nAUTO-MAS 敬上",
webhook
title, f"{message_text}\n\nAUTO-MAS 敬上", webhook
)
except Exception as e:
logger.error(f"用户自定义Webhook推送失败 ({webhook.get('name', 'Unknown')}): {e}")
logger.error(
f"用户自定义Webhook推送失败 ({webhook.get('name', 'Unknown')}): {e}"
)
else:
logger.error(
"用户CompanyWebHookBot密钥为空, 无法发送用户单独的CompanyWebHookBot通知"
@@ -2066,16 +2067,16 @@ class MaaManager:
if webhook.get("enabled", True):
try:
await Notify.CustomWebhookPush(
title,
"好羡慕~\n\nAUTO-MAS 敬上",
webhook
title, "好羡慕~\n\nAUTO-MAS 敬上", webhook
)
except Exception as e:
logger.error(f"自定义Webhook推送失败 ({webhook.get('name', 'Unknown')}): {e}")
logger.error(
f"自定义Webhook推送失败 ({webhook.get('name', 'Unknown')}): {e}"
)
# 发送用户单独通知
if self.cur_user_data.get("Notify", "Enabled") and self.cur_user_data.get(
"Notify", "IfSendSixStar"
"Notify", "IfSendSixStar"
):
# 发送邮件通知
@@ -2117,12 +2118,12 @@ class MaaManager:
if webhook.get("enabled", True):
try:
await Notify.CustomWebhookPush(
title,
"好羡慕~\n\nAUTO-MAS 敬上",
webhook
title, "好羡慕~\n\nAUTO-MAS 敬上", webhook
)
except Exception as e:
logger.error(f"用户自定义Webhook推送失败 ({webhook.get('name', 'Unknown')}): {e}")
logger.error(
f"用户自定义Webhook推送失败 ({webhook.get('name', 'Unknown')}): {e}"
)
else:
logger.error(
"用户CompanyWebHookBot密钥为空, 无法发送用户单独的CompanyWebHookBot通知"

View File

@@ -1,6 +1,7 @@
# AUTO-MAS: A Multi-Script, Multi-Config Management and Automation Software
# Copyright © 2024-2025 DLmaster361
# Copyright © 2025 MoeSnowyFox
# Copyright © 2025 AUTO-MAS Team
# This file is part of AUTO-MAS.

View File

@@ -1,5 +1,6 @@
# AUTO-MAS: A Multi-Script, Multi-Config Management and Automation Software
# Copyright © 2024-2025 DLmaster361
# Copyright © 2025 AUTO-MAS Team
# This file is part of AUTO-MAS.
@@ -992,12 +993,12 @@ class GeneralManager:
if webhook.get("enabled", True):
try:
await Notify.CustomWebhookPush(
title,
f"{message_text}\n\nAUTO-MAS 敬上",
webhook
title, f"{message_text}\n\nAUTO-MAS 敬上", webhook
)
except Exception as e:
logger.error(f"自定义Webhook推送失败 ({webhook.get('name', 'Unknown')}): {e}")
logger.error(
f"自定义Webhook推送失败 ({webhook.get('name', 'Unknown')}): {e}"
)
elif mode == "统计信息":
@@ -1039,12 +1040,12 @@ class GeneralManager:
if webhook.get("enabled", True):
try:
await Notify.CustomWebhookPush(
title,
f"{message_text}\n\nAUTO-MAS 敬上",
webhook
title, f"{message_text}\n\nAUTO-MAS 敬上", webhook
)
except Exception as e:
logger.error(f"自定义Webhook推送失败 ({webhook.get('name', 'Unknown')}): {e}")
logger.error(
f"自定义Webhook推送失败 ({webhook.get('name', 'Unknown')}): {e}"
)
# 发送用户单独通知
if self.cur_user_data.get("Notify", "Enabled") and self.cur_user_data.get(
@@ -1078,18 +1079,18 @@ class GeneralManager:
# 推送CompanyWebHookBot通知
# 发送用户自定义Webhook通知
user_webhooks = self.cur_user_data.get("Notify", {}).get("CustomWebhooks", [])
user_webhooks = self.cur_user_data.get("Notify", "CustomWebhooks")
if user_webhooks:
for webhook in user_webhooks:
if webhook.get("enabled", True):
try:
await Notify.CustomWebhookPush(
title,
f"{message_text}\n\nAUTO-MAS 敬上",
webhook
title, f"{message_text}\n\nAUTO-MAS 敬上", webhook
)
except Exception as e:
logger.error(f"用户自定义Webhook推送失败 ({webhook.get('name', 'Unknown')}): {e}")
logger.error(
f"用户自定义Webhook推送失败 ({webhook.get('name', 'Unknown')}): {e}"
)
else:
logger.error(
"用户CompanyWebHookBot密钥为空, 无法发送用户单独的CompanyWebHookBot通知"

View File

@@ -7,6 +7,7 @@
#
# skland-checkin-ghaction Copyright © 2023 Yanstory
# https://github.com/Yanstory/skland-checkin-ghaction
# Copyright © 2025 AUTO-MAS Team
# This file is part of AUTO-MAS.