fix(maa): 将通知判定过程全部移入push_notification

This commit is contained in:
DLmaster361
2025-05-23 22:59:09 +08:00
parent 974a4b634a
commit f5d898c89e
4 changed files with 192 additions and 189 deletions

View File

@@ -584,7 +584,7 @@ class MaaPlanConfig(LQConfig):
class AppConfig(GlobalConfig): class AppConfig(GlobalConfig):
VERSION = "4.3.8.3" VERSION = "4.3.8.4"
gameid_refreshed = Signal() gameid_refreshed = Signal()
PASSWORD_refreshed = Signal() PASSWORD_refreshed = Signal()

View File

@@ -614,8 +614,8 @@ class MaaManager(QObject):
f"喜报:用户 {user[0]} 公招出六星啦!", f"喜报:用户 {user[0]} 公招出六星啦!",
{ {
"user_name": user_data["Info"]["Name"], "user_name": user_data["Info"]["Name"],
"user_index": user[2],
}, },
user_data,
) )
# 执行MAA解压更新动作 # 执行MAA解压更新动作
@@ -641,17 +641,12 @@ class MaaManager(QObject):
logger.info(f"{self.name} | 更新动作结束") logger.info(f"{self.name} | 更新动作结束")
if Config.get(Config.notify_IfSendStatistic): # 发送统计信息
statistics = Config.merge_maa_logs("指定项", user_logs_list) statistics = Config.merge_maa_logs("指定项", user_logs_list)
statistics["user_index"] = user[2] statistics["user_index"] = user[2]
statistics["user_info"] = user[0] statistics["user_info"] = user[0]
statistics["start_time"] = user_start_time.strftime( statistics["start_time"] = user_start_time.strftime("%Y-%m-%d %H:%M:%S")
"%Y-%m-%d %H:%M:%S" statistics["end_time"] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
)
statistics["end_time"] = datetime.now().strftime(
"%Y-%m-%d %H:%M:%S"
)
statistics["maa_result"] = ( statistics["maa_result"] = (
"代理任务全部完成" "代理任务全部完成"
if (run_book["Annihilation"] and run_book["Routine"]) if (run_book["Annihilation"] and run_book["Routine"])
@@ -661,6 +656,7 @@ class MaaManager(QObject):
"统计信息", "统计信息",
f"{current_date} | 用户 {user[0]} 的自动代理统计报告", f"{current_date} | 用户 {user[0]} 的自动代理统计报告",
statistics, statistics,
user_data,
) )
if run_book["Annihilation"] and run_book["Routine"]: if run_book["Annihilation"] and run_book["Routine"]:
@@ -854,6 +850,17 @@ class MaaManager(QObject):
self.data[_]["Config"]["Info"]["Name"] for _ in wait_index self.data[_]["Config"]["Info"]["Name"] for _ in wait_index
], ],
} }
# 生成结果文本
result_text = (
f"任务开始时间:{result["start_time"]},结束时间:{result["end_time"]}\n"
f"已完成数:{result["completed_count"]},未完成数:{result["uncompleted_count"]}\n\n"
)
if len(result["failed_user"]) > 0:
result_text += f"{self.mode[2:4]}未成功的用户:\n{"\n".join(result["failed_user"])}\n"
if len(result["waiting_user"]) > 0:
result_text += f"\n未开始{self.mode[2:4]}的用户:\n{"\n".join(result["waiting_user"])}\n"
# 推送代理结果通知 # 推送代理结果通知
Notify.push_plyer( Notify.push_plyer(
title.replace("报告", "已完成!"), title.replace("报告", "已完成!"),
@@ -861,15 +868,7 @@ class MaaManager(QObject):
f"已完成用户数:{len(over_index)},未完成用户数:{len(error_index) + len(wait_index)}", f"已完成用户数:{len(over_index)},未完成用户数:{len(error_index) + len(wait_index)}",
10, 10,
) )
if Config.get(Config.notify_SendTaskResultTime) == "任何时刻" or ( self.push_notification("代理结果", title, result)
Config.get(Config.notify_SendTaskResultTime) == "仅失败时"
and len(error_index) + len(wait_index) != 0
):
result_text = self.push_notification("代理结果", title, result)
else:
result_text = self.push_notification(
"代理结果", title, result, if_get_text_only=True
)
self.agree_bilibili(False) self.agree_bilibili(False)
self.log_monitor.deleteLater() self.log_monitor.deleteLater()
@@ -1743,15 +1742,21 @@ class MaaManager(QObject):
mode: str, mode: str,
title: str, title: str,
message: Union[str, dict], message: Union[str, dict],
if_get_text_only: bool = False, user_data: Dict[str, Dict[str, Union[str, int, bool]]] = None,
) -> str: ) -> None:
"""通过所有渠道推送通知""" """通过所有渠道推送通知"""
env = Environment( env = Environment(
loader=FileSystemLoader(str(Config.app_path / "resources/html")) loader=FileSystemLoader(str(Config.app_path / "resources/html"))
) )
if mode == "代理结果": if mode == "代理结果" and (
Config.get(Config.notify_SendTaskResultTime) == "任何时刻"
or (
Config.get(Config.notify_SendTaskResultTime) == "仅失败时"
and message["uncompleted_count"] != 0
)
):
# 生成文本通知内容 # 生成文本通知内容
message_text = ( message_text = (
f"任务开始时间:{message["start_time"]},结束时间:{message["end_time"]}\n" f"任务开始时间:{message["start_time"]},结束时间:{message["end_time"]}\n"
@@ -1763,9 +1768,6 @@ class MaaManager(QObject):
if len(message["waiting_user"]) > 0: if len(message["waiting_user"]) > 0:
message_text += f"\n未开始{self.mode[2:4]}的用户:\n{"\n".join(message["waiting_user"])}\n" message_text += f"\n未开始{self.mode[2:4]}的用户:\n{"\n".join(message["waiting_user"])}\n"
if if_get_text_only:
return message_text
# 生成HTML通知内容 # 生成HTML通知内容
message["failed_user"] = "".join(message["failed_user"]) message["failed_user"] = "".join(message["failed_user"])
message["waiting_user"] = "".join(message["waiting_user"]) message["waiting_user"] = "".join(message["waiting_user"])
@@ -1773,12 +1775,16 @@ class MaaManager(QObject):
template = env.get_template("MAA_result.html") template = env.get_template("MAA_result.html")
message_html = template.render(message) message_html = template.render(message)
# ServerChan的换行是两个换行符。故而将\n替换为\n\n
serverchan_message = message_text.replace("\n", "\n\n")
# 发送全局通知 # 发送全局通知
if Config.get(Config.notify_IfSendMail): if Config.get(Config.notify_IfSendMail):
Notify.send_mail( Notify.send_mail(
"网页", title, message_html, Config.get(Config.notify_ToAddress) "网页", title, message_html, Config.get(Config.notify_ToAddress)
) )
serverchan_message = message_text.replace("\n", "\n\n")
if Config.get(Config.notify_IfServerChan): if Config.get(Config.notify_IfServerChan):
Notify.ServerChanPush( Notify.ServerChanPush(
title, title,
@@ -1787,6 +1793,7 @@ class MaaManager(QObject):
Config.get(Config.notify_ServerChanTag), Config.get(Config.notify_ServerChanTag),
Config.get(Config.notify_ServerChanChannel), Config.get(Config.notify_ServerChanChannel),
) )
if Config.get(Config.notify_IfCompanyWebHookBot): if Config.get(Config.notify_IfCompanyWebHookBot):
Notify.CompanyWebHookBotPush( Notify.CompanyWebHookBotPush(
title, title,
@@ -1794,10 +1801,8 @@ class MaaManager(QObject):
Config.get(Config.notify_CompanyWebHookBotUrl), Config.get(Config.notify_CompanyWebHookBotUrl),
) )
return message_text
elif mode == "统计信息": elif mode == "统计信息":
user_index = message.get("user_index")
# 生成文本通知内容 # 生成文本通知内容
formatted = [] formatted = []
for stage, items in message["drop_statistics"].items(): for stage, items in message["drop_statistics"].items():
@@ -1823,13 +1828,17 @@ class MaaManager(QObject):
template = env.get_template("MAA_statistics.html") template = env.get_template("MAA_statistics.html")
message_html = template.render(message) message_html = template.render(message)
# ServerChan的换行是两个换行符。故而将\n替换为\n\n
serverchan_message = message_text.replace("\n", "\n\n")
# 发送全局通知 # 发送全局通知
if Config.get(Config.notify_IfSendStatistic):
if Config.get(Config.notify_IfSendMail): if Config.get(Config.notify_IfSendMail):
Notify.send_mail( Notify.send_mail(
"网页", title, message_html, Config.get(Config.notify_ToAddress) "网页", title, message_html, Config.get(Config.notify_ToAddress)
) )
# ServerChan的换行是两个换行符。故而将\n替换为\n\n
serverchan_message = message_text.replace("\n", "\n\n")
if Config.get(Config.notify_IfServerChan): if Config.get(Config.notify_IfServerChan):
Notify.ServerChanPush( Notify.ServerChanPush(
title, title,
@@ -1838,6 +1847,7 @@ class MaaManager(QObject):
Config.get(Config.notify_ServerChanTag), Config.get(Config.notify_ServerChanTag),
Config.get(Config.notify_ServerChanChannel), Config.get(Config.notify_ServerChanChannel),
) )
if Config.get(Config.notify_IfCompanyWebHookBot): if Config.get(Config.notify_IfCompanyWebHookBot):
Notify.CompanyWebHookBotPush( Notify.CompanyWebHookBotPush(
title, title,
@@ -1846,39 +1856,34 @@ class MaaManager(QObject):
) )
# 发送用户单独通知 # 发送用户单独通知
user_data = self.data.get(user_index, {}).get("Config", {}) if (
if user_data["Notify"].get("IfSendStatistic", False): user_data["Notify"]["Enabled"]
if user_data.get("Notify") and user_data["Notify"].get( and user_data["Notify"]["IfSendStatistic"]
"Enabled", False
): ):
# 发送邮件通知 # 发送邮件通知
if user_data.get("Notify", {}).get("IfSendMail", False): if user_data["Notify"]["IfSendMail"]:
userToAddress = user_data.get("Notify", {}).get("ToAddress") if user_data["Notify"]["ToAddress"]:
if userToAddress: Notify.send_mail(
Notify.send_mail("网页", title, message_text, userToAddress) "网页",
title,
message_html,
user_data["Notify"]["ToAddress"],
)
else: else:
logger.error( logger.error(
f"{self.name} | 用户邮箱地址为空,无法发送用户单独的邮件通知" f"{self.name} | 用户邮箱地址为空,无法发送用户单独的邮件通知"
) )
# 发送ServerChan通知 # 发送ServerChan通知
if user_data.get("Notify", {}).get("IfServerChan", False): if user_data["Notify"]["IfServerChan"]:
userServerChanKey = user_data.get("Notify", {}).get( if user_data["Notify"]["ServerChanKey"]:
"ServerChanKey"
)
userServerChanTag = user_data.get("Notify", {}).get(
"ServerChanTag"
)
userServerChanChannel = user_data.get("Notify", {}).get(
"ServerChanChannel"
)
if userServerChanKey:
Notify.ServerChanPush( Notify.ServerChanPush(
title, title,
f"{serverchan_message}\n\nAUTO_MAA 敬上", f"{serverchan_message}\n\nAUTO_MAA 敬上",
userServerChanKey, user_data["Notify"]["ServerChanKey"],
userServerChanTag, user_data["Notify"]["ServerChanTag"],
userServerChanChannel, user_data["Notify"]["ServerChanChannel"],
) )
else: else:
logger.error( logger.error(
@@ -1886,15 +1891,12 @@ class MaaManager(QObject):
) )
# 推送CompanyWebHookBot通知 # 推送CompanyWebHookBot通知
if user_data.get("Notify", {}).get("IfCompanyWebHookBot", False): if user_data["Notify"]["IfCompanyWebHookBot"]:
userCompanyWebHookBotUrl = user_data.get("Notify", {}).get( if user_data["Notify"]["CompanyWebHookBotUrl"]:
"CompanyWebHookBotUrl"
)
if userCompanyWebHookBotUrl:
Notify.CompanyWebHookBotPush( Notify.CompanyWebHookBotPush(
title, title,
f"{message_text}\n\nAUTO_MAA 敬上", f"{message_text}\n\nAUTO_MAA 敬上",
userCompanyWebHookBotUrl, user_data["Notify"]["CompanyWebHookBotUrl"],
) )
else: else:
logger.error( logger.error(
@@ -1902,19 +1904,20 @@ class MaaManager(QObject):
) )
elif mode == "公招六星": elif mode == "公招六星":
user_index = message.get("user_index")
# 生成HTML通知内容 # 生成HTML通知内容
template = env.get_template("MAA_six_star.html") template = env.get_template("MAA_six_star.html")
# 这里需要看一下我给message加了个user_index
message_html = template.render(message) message_html = template.render(message)
if Config.get(Config.notify_IfSendSixStar):
# 发送全局通知 # 发送全局通知
if Config.get(Config.notify_IfSendSixStar):
if Config.get(Config.notify_IfSendMail): if Config.get(Config.notify_IfSendMail):
Notify.send_mail( Notify.send_mail(
"网页", title, message_html, Config.get(Config.notify_ToAddress) "网页", title, message_html, Config.get(Config.notify_ToAddress)
) )
if Config.get(Config.notify_IfServerChan): if Config.get(Config.notify_IfServerChan):
Notify.ServerChanPush( Notify.ServerChanPush(
title, title,
@@ -1923,48 +1926,41 @@ class MaaManager(QObject):
Config.get(Config.notify_ServerChanTag), Config.get(Config.notify_ServerChanTag),
Config.get(Config.notify_ServerChanChannel), Config.get(Config.notify_ServerChanChannel),
) )
if Config.get(Config.notify_IfCompanyWebHookBot): if Config.get(Config.notify_IfCompanyWebHookBot):
Notify.CompanyWebHookBotPush( Notify.CompanyWebHookBotPush(
title, title,
"好羡慕~\n\nAUTO_MAA 敬上", "好羡慕~\n\nAUTO_MAA 敬上",
Config.get(Config.notify_CompanyWebHookBotUrl), Config.get(Config.notify_CompanyWebHookBotUrl),
) )
# 发送用户单独通知
user_data = self.data.get(user_index, {}).get("Config", {})
# 判断是否单独发送六星 # 发送用户单独通知
if user_data["Notify"].get("IfSendSixStar", False): if user_data["Notify"]["Enabled"] and user_data["Notify"]["IfSendSixStar"]:
if user_data.get("Notify") and user_data["Notify"].get(
"Enabled", False
):
# 发送邮件通知 # 发送邮件通知
if user_data.get("Notify", {}).get("IfSendMail", False): if user_data["Notify"]["IfSendMail"]:
userToAddress = user_data.get("Notify", {}).get("ToAddress") if user_data["Notify"]["ToAddress"]:
if userToAddress: Notify.send_mail(
Notify.send_mail("网页", title, message_html, userToAddress) "网页",
title,
message_html,
user_data["Notify"]["ToAddress"],
)
else: else:
logger.error( logger.error(
f"{self.name} | 用户邮箱地址为空,无法发送用户单独的邮件通知" f"{self.name} | 用户邮箱地址为空,无法发送用户单独的邮件通知"
) )
# 发送ServerChan通知 # 发送ServerChan通知
if user_data.get("Notify", {}).get("IfServerChan", False): if user_data["Notify"]["IfServerChan"]:
userServerChanKey = user_data.get("Notify", {}).get(
"ServerChanKey" if user_data["Notify"]["ServerChanKey"]:
)
userServerChanTag = user_data.get("Notify", {}).get(
"ServerChanTag"
)
userServerChanChannel = user_data.get("Notify", {}).get(
"ServerChanChannel"
)
if userServerChanKey:
Notify.ServerChanPush( Notify.ServerChanPush(
title, title,
"好羡慕~\n\nAUTO_MAA 敬上", "好羡慕~\n\nAUTO_MAA 敬上",
userServerChanKey, user_data["Notify"]["ServerChanKey"],
userServerChanTag, user_data["Notify"]["ServerChanTag"],
userServerChanChannel, user_data["Notify"]["ServerChanChannel"],
) )
else: else:
logger.error( logger.error(
@@ -1972,15 +1968,12 @@ class MaaManager(QObject):
) )
# 推送CompanyWebHookBot通知 # 推送CompanyWebHookBot通知
if user_data.get("Notify", {}).get("IfCompanyWebHookBot", False): if user_data["Notify"]["IfCompanyWebHookBot"]:
userCompanyWebHookBotUrl = user_data.get("Notify", {}).get( if user_data["Notify"]["CompanyWebHookBotUrl"]:
"CompanyWebHookBotUrl"
)
if userCompanyWebHookBotUrl:
Notify.CompanyWebHookBotPush( Notify.CompanyWebHookBotPush(
title, title,
"好羡慕~\n\nAUTO_MAA 敬上", "好羡慕~\n\nAUTO_MAA 敬上",
userCompanyWebHookBotUrl, user_data["Notify"]["CompanyWebHookBotUrl"],
) )
else: else:
logger.error( logger.error(

View File

@@ -1003,22 +1003,27 @@ class UserNoticeSettingCard(PushAndSwitchButtonSettingCard):
return f"{s[:4]}***{s[-4:]}" if len(s) > 8 else s return f"{s[:4]}***{s[-4:]}" if len(s) > 8 else s
elif s.startswith(("http://", "https://")): elif s.startswith(("http://", "https://")):
# Webhook URL域名 + 路径尾4 # Webhook URL域名前5 + 路径尾5
parsed_url = urlparse(s) parsed_url = urlparse(s)
domain = parsed_url.netloc domain = (
parsed_url.netloc[:5]
if len(parsed_url.netloc) > 5
else parsed_url.netloc
)
path_tail = ( path_tail = (
parsed_url.path[-4:] parsed_url.path[-5:]
if len(parsed_url.path) > 4 if len(parsed_url.path) > 5
else parsed_url.path else parsed_url.path
) )
return f"{domain}" return f"{domain}......{path_tail}"
elif "@" in s: elif "@" in s:
# # 邮箱:显示@前最多3字符 + 域名 # 邮箱:@前4/7 + 域名
# username, domain = s.split("@", 1) username, domain = s.split("@", 1)
# displayed_name = username[-3:] if len(username) > 3 else username displayed_name = (
# 邮箱展示全部 f"{username[:4]}......" if len(username) > 7 else username
return f"{s}" )
return f"{displayed_name}@{domain}"
else: else:
# 普通字符串末尾3字符 # 普通字符串末尾3字符

View File

@@ -1,6 +1,11 @@
{ {
"main_version": "4.3.8.3", "main_version": "4.3.8.4",
"version_info": { "version_info": {
"4.3.8.4": {
"新增功能": [
"支持为每一个用户执行独立通知"
]
},
"4.3.8.3": { "4.3.8.3": {
"新增功能": [ "新增功能": [
"用户仪表盘支持直接控制用户状态" "用户仪表盘支持直接控制用户状态"