From 254fb6916f8afd9954795e2fa330def00b4c37e3 Mon Sep 17 00:00:00 2001 From: DLmaster Date: Mon, 3 Mar 2025 21:59:37 +0800 Subject: [PATCH 1/8] =?UTF-8?q?feat(core):=20=E5=88=9D=E6=AD=A5=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E5=85=AD=E6=98=9F=E5=85=AC=E6=8B=9B=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/core/config.py | 8 +++++++- app/models/MAA.py | 20 +++++++++++++++++++- resources/version.json | 2 +- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/app/core/config.py b/app/core/config.py index ed5bce7..a29fa03 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -466,7 +466,7 @@ class AppConfig: cur.close() db.close() - def save_maa_log(self, log_path: Path, logs: list, maa_result: str) -> None: + def save_maa_log(self, log_path: Path, logs: list, maa_result: str) -> bool: """保存MAA日志""" data: Dict[str, Union[str, Dict[str, Union[int, dict]]]] = { @@ -475,6 +475,8 @@ class AppConfig: "maa_result": maa_result, } + if_six_star = False + # 公招统计(仅统计招募到的) confirmed_recruit = False current_star_level = None @@ -490,6 +492,8 @@ class AppConfig: star_match = re.search(r"(\d+)\s*★ Tags", logs[i]) if star_match: current_star_level = f"{star_match.group(1)}★" + if current_star_level == "6★": + if_six_star = True if "已确认招募" in logs[i]: # 只有确认招募后才统计 confirmed_recruit = True @@ -553,6 +557,8 @@ class AppConfig: self.merge_maa_logs("所有项", log_path.parent) + return if_six_star + def merge_maa_logs(self, mode: str, logs_path: Union[Path, List[Path]]) -> dict: """合并指定数据统计信息文件""" diff --git a/app/models/MAA.py b/app/models/MAA.py index 8ff7b90..e9c94e7 100644 --- a/app/models/MAA.py +++ b/app/models/MAA.py @@ -291,7 +291,7 @@ class MaaManager(QObject): Config.silence_list.remove(self.emulator_path) # 保存运行日志以及统计信息 - Config.save_maa_log( + if_six_star = Config.save_maa_log( Config.app_path / f"history/{curdate}/{self.data[user[2]][0]}/{start_time.strftime("%H-%M-%S")}.log", self.check_maa_log(start_time, mode_book[j]), @@ -302,6 +302,14 @@ class MaaManager(QObject): / f"history/{curdate}/{self.data[user[2]][0]}/{start_time.strftime("%H-%M-%S")}.json", ) + if if_six_star: + + self.push_notification( + "公招六星", + f"喜报:用户 {user[0]} 公招出六星啦!", + "好羡慕~", + ) + # 成功完成代理的用户修改相关参数 if run_book[0] and run_book[1]: if self.data[user[2]][14] == 0 and self.data[user[2]][3] != -1: @@ -1314,3 +1322,13 @@ class MaaManager(QObject): Notify.send_mail("网页", title, html_content) Notify.ServerChanPush(title, f"{message_text}\n\nAUTO_MAA 敬上") Notify.CompanyWebHookBotPush(title, f"{message_text}AUTO_MAA 敬上") + + elif mode == "公招六星": + + Notify.send_mail( + "文本", + title, + f"{message}\n\nAUTO_MAA 敬上\n\n我们根据您在 AUTO_MAA 中的设置发送了这封电子邮件,本邮件无需回复\n", + ) + Notify.ServerChanPush(title, f"{message}\n\nAUTO_MAA 敬上") + Notify.CompanyWebHookBotPush(title, f"{message}AUTO_MAA 敬上") diff --git a/resources/version.json b/resources/version.json index 364384f..951fec4 100644 --- a/resources/version.json +++ b/resources/version.json @@ -1,7 +1,7 @@ { "main_version": "4.2.4.7", "updater_version": "1.1.2.1", - "announcement": "\n## 新增功能\n- 历史记录统计功能上线\n- 添加软件主页\n- 添加启动时直接最小化功能\n- 更新器拥有多网址测速功能\n- 添加统计信息通知功能\n## 修复BUG\n- RMA70-12不能正确统计的问题\n- 更新器修正`channel`\n## 程序优化\n- 添加MAA监测字段:`未检测到任何模拟器`\n- 取消MAA运行中自动更新", + "announcement": "\n## 新增功能\n- 历史记录统计功能上线\n- 添加软件主页\n- 添加启动时直接最小化功能\n- 更新器拥有多网址测速功能\n- 添加统计信息通知功能(含六星监测)\n## 修复BUG\n- RMA70-12不能正确统计的问题\n- 更新器修正`channel`\n## 程序优化\n- 添加MAA监测字段:`未检测到任何模拟器`\n- 取消MAA运行中自动更新", "proxy_list": [ "", "https://gitproxy.click/", From 4271a07f0312fed799d28b8b0d394242079d0533 Mon Sep 17 00:00:00 2001 From: aoxuan Date: Wed, 5 Mar 2025 14:07:03 +0800 Subject: [PATCH 2/8] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BC=81=E4=B8=9A?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E7=BE=A4=E6=9C=BA=E5=99=A8=E4=BA=BA=E6=8E=A8?= =?UTF-8?q?=E9=80=81=E9=80=9A=E7=9F=A5=E6=B6=88=E6=81=AF=E6=9C=AA=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=E6=8D=A2=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/MAA.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/MAA.py b/app/models/MAA.py index e9c94e7..fdb3192 100644 --- a/app/models/MAA.py +++ b/app/models/MAA.py @@ -1321,7 +1321,7 @@ class MaaManager(QObject): Notify.send_mail("网页", title, html_content) Notify.ServerChanPush(title, f"{message_text}\n\nAUTO_MAA 敬上") - Notify.CompanyWebHookBotPush(title, f"{message_text}AUTO_MAA 敬上") + Notify.CompanyWebHookBotPush(title, f"{message_text}\n\nAUTO_MAA 敬上") elif mode == "公招六星": From 6292624d41c62516cb44d30e6b7dcbec00728ebe Mon Sep 17 00:00:00 2001 From: DLmaster Date: Wed, 5 Mar 2025 14:34:15 +0800 Subject: [PATCH 3/8] =?UTF-8?q?fix(services):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=82=AE=E7=AE=B1=E9=80=9A=E7=9F=A5=E6=A0=A1=E9=AA=8C=E8=BF=87?= =?UTF-8?q?=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/notification.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/app/services/notification.py b/app/services/notification.py index b5b0566..8d2fcca 100644 --- a/app/services/notification.py +++ b/app/services/notification.py @@ -27,6 +27,7 @@ v4.2 import requests from loguru import logger from plyer import notification +import re import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart @@ -58,11 +59,38 @@ class Notification: return True - def send_mail(self, mode, title, content): + def send_mail(self, mode, title, content) -> None: """推送邮件通知""" if Config.global_config.get(Config.global_config.notify_IfSendMail): + if ( + Config.global_config.get(Config.global_config.notify_SMTPServerAddress) + == "" + or Config.global_config.get( + Config.global_config.notify_AuthorizationCode + ) + == "" + or not bool( + re.match( + r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$", + Config.global_config.get( + Config.global_config.notify_FromAddress + ), + ) + ) + or not bool( + re.match( + r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$", + Config.global_config.get(Config.global_config.notify_ToAddress), + ) + ) + ): + logger.error( + "请正确设置邮件通知的SMTP服务器地址、授权码、发件人地址和收件人地址" + ) + return None + try: # 定义邮件正文 if mode == "文本": From 1feb0cf83f8e4a8581bb5aa8860f389794b3cfc7 Mon Sep 17 00:00:00 2001 From: DLmaster Date: Wed, 5 Mar 2025 15:11:57 +0800 Subject: [PATCH 4/8] =?UTF-8?q?fix(serices):=20=E4=BF=AE=E5=A4=8D=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E6=9C=8D=E5=8A=A1=E4=BD=BF=E7=94=A8InfoBar=E6=8A=A5?= =?UTF-8?q?=E9=94=99=E6=97=B6=E7=A8=8B=E5=BA=8F=E5=B4=A9=E6=BA=83=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/core/timer.py | 5 +---- app/services/notification.py | 28 +++++++++++++++++++++------- app/ui/main_window.py | 1 + 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/app/core/timer.py b/app/core/timer.py index 97357b2..449ceba 100644 --- a/app/core/timer.py +++ b/app/core/timer.py @@ -39,10 +39,7 @@ from app.services import System class _MainTimer(QWidget): - def __init__( - self, - parent=None, - ): + def __init__(self, parent=None): super().__init__(parent) self.if_FailSafeException = False diff --git a/app/services/notification.py b/app/services/notification.py index 8d2fcca..a8eeda1 100644 --- a/app/services/notification.py +++ b/app/services/notification.py @@ -24,6 +24,9 @@ AUTO_MAA通知服务 v4.2 作者:DLmaster_361 """ + +from PySide6.QtWidgets import QWidget +from PySide6.QtCore import Signal import requests from loguru import logger from plyer import notification @@ -36,11 +39,16 @@ from email.utils import formataddr from serverchan_sdk import sc_send -from app.core import Config, MainInfoBar +from app.core import Config from app.services.security import Crypto -class Notification: +class Notification(QWidget): + + push_info_bar = Signal(str, str, str, int) + + def __init__(self, parent=None): + super().__init__(parent) def push_plyer(self, title, message, ticker, t): """推送系统通知""" @@ -89,6 +97,12 @@ class Notification: logger.error( "请正确设置邮件通知的SMTP服务器地址、授权码、发件人地址和收件人地址" ) + self.push_info_bar.emit( + "error", + "邮件通知推送异常", + "请正确设置邮件通知的SMTP服务器地址、授权码、发件人地址和收件人地址", + -1, + ) return None try: @@ -139,7 +153,7 @@ class Notification: logger.success("邮件发送成功") except Exception as e: logger.error(f"发送邮件时出错:\n{e}") - MainInfoBar.push_info_bar("error", "发送邮件时出错", f"{e}", -1) + self.push_info_bar.emit("error", "发送邮件时出错", f"{e}", -1) def ServerChanPush(self, title, content): """使用Server酱推送通知""" @@ -168,7 +182,7 @@ class Notification: else: option["tags"] = "" logger.warning("请正确设置Auto_MAA中ServerChan的Tag。") - MainInfoBar.push_info_bar( + self.push_info_bar.emit( "warning", "Server酱通知推送异常", "请正确设置Auto_MAA中ServerChan的Tag。", @@ -180,7 +194,7 @@ class Notification: else: option["channel"] = "" logger.warning("请正确设置Auto_MAA中ServerChan的Channel。") - MainInfoBar.push_info_bar( + self.push_info_bar.emit( "warning", "Server酱通知推送异常", "请正确设置Auto_MAA中ServerChan的Channel。", @@ -194,7 +208,7 @@ class Notification: else: logger.info("Server酱推送通知失败") logger.error(response) - MainInfoBar.push_info_bar( + self.push_info_bar.emit( "error", "Server酱通知推送失败", f'使用Server酱推送通知时出错:\n{response["data"]['error']}', @@ -219,7 +233,7 @@ class Notification: else: logger.info("企业微信群机器人推送通知失败") logger.error(response.json()) - MainInfoBar.push_info_bar( + self.push_info_bar.emit( "error", "企业微信群机器人通知推送失败", f'使用企业微信群机器人推送通知时出错:\n{response.json()["errmsg"]}', diff --git a/app/ui/main_window.py b/app/ui/main_window.py index fc2b2ae..fb097fa 100644 --- a/app/ui/main_window.py +++ b/app/ui/main_window.py @@ -189,6 +189,7 @@ class AUTO_MAA(MSFluentWindow): TaskManager.create_gui.connect(self.dispatch_center.add_board) TaskManager.connect_gui.connect(self.dispatch_center.connect_main_board) + Notify.push_info_bar.connect(MainInfoBar.push_info_bar) self.setting.ui.card_IfShowTray.checkedChanged.connect( lambda: self.show_ui("配置托盘") ) From ce264de96308ef1d819343a064c4d9857008b5be Mon Sep 17 00:00:00 2001 From: DLmaster Date: Wed, 5 Mar 2025 16:00:48 +0800 Subject: [PATCH 5/8] =?UTF-8?q?feat(ui):=206=E6=98=9F=E5=85=AC=E6=8B=9B?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E6=B7=BB=E5=8A=A0=E7=8B=AC=E7=AB=8B=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/core/config.py | 1 + app/models/MAA.py | 7 ++++- app/ui/history.py | 5 +--- app/ui/main_window.py | 3 +-- app/ui/member_manager.py | 7 +---- app/ui/setting.py | 56 +++++++++++++++++++++++++++------------- 6 files changed, 48 insertions(+), 31 deletions(-) diff --git a/app/core/config.py b/app/core/config.py index a29fa03..0427f39 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -799,6 +799,7 @@ class GlobalConfig(QConfig): notify_IfSendStatistic = ConfigItem( "Notify", "IfSendStatistic", False, BoolValidator() ) + notify_IfSendSixStar = ConfigItem("Notify", "IfSendSixStar", False, BoolValidator()) notify_IfPushPlyer = ConfigItem("Notify", "IfPushPlyer", False, BoolValidator()) notify_IfSendMail = ConfigItem("Notify", "IfSendMail", False, BoolValidator()) notify_SMTPServerAddress = ConfigItem("Notify", "SMTPServerAddress", "") diff --git a/app/models/MAA.py b/app/models/MAA.py index fdb3192..31159d1 100644 --- a/app/models/MAA.py +++ b/app/models/MAA.py @@ -302,7 +302,12 @@ class MaaManager(QObject): / f"history/{curdate}/{self.data[user[2]][0]}/{start_time.strftime("%H-%M-%S")}.json", ) - if if_six_star: + if ( + Config.global_config.get( + Config.global_config.notify_IfSendSixStar + ) + and if_six_star + ): self.push_notification( "公招六星", diff --git a/app/ui/history.py b/app/ui/history.py index 6ed57b3..49d4d16 100644 --- a/app/ui/history.py +++ b/app/ui/history.py @@ -96,10 +96,7 @@ class HistoryCard(ExpandGroupSettingCard): def __init__(self, date: str, user_list: List[Path], parent=None): super().__init__( - FluentIcon.HISTORY, - date, - f"{date}的历史运行记录与统计信息", - parent, + FluentIcon.HISTORY, date, f"{date}的历史运行记录与统计信息", parent ) widget = QWidget() diff --git a/app/ui/main_window.py b/app/ui/main_window.py index fb097fa..8da86c0 100644 --- a/app/ui/main_window.py +++ b/app/ui/main_window.py @@ -149,8 +149,7 @@ class AUTO_MAA(MSFluentWindow): # 创建系统托盘及其菜单 self.tray = QSystemTrayIcon( - QIcon(str(Config.app_path / "resources/icons/AUTO_MAA.ico")), - self, + QIcon(str(Config.app_path / "resources/icons/AUTO_MAA.ico")), self ) self.tray.setToolTip("AUTO_MAA") self.tray_menu = SystemTrayMenu("AUTO_MAA", self) diff --git a/app/ui/member_manager.py b/app/ui/member_manager.py index eecc343..940b7c7 100644 --- a/app/ui/member_manager.py +++ b/app/ui/member_manager.py @@ -638,12 +638,7 @@ class MaaSettingBox(QWidget): class RunSetSettingCard(ExpandGroupSettingCard): def __init__(self, parent=None): - super().__init__( - FluentIcon.SETTING, - "运行", - "MAA运行调控选项", - parent, - ) + super().__init__(FluentIcon.SETTING, "运行", "MAA运行调控选项", parent) self.card_TaskTransitionMethod = ComboBoxSettingCard( configItem=Config.maa_config.RunSet_TaskTransitionMethod, diff --git a/app/ui/setting.py b/app/ui/setting.py index bb47843..ee68a06 100644 --- a/app/ui/setting.py +++ b/app/ui/setting.py @@ -542,18 +542,7 @@ class NotifySettingCard(HeaderCardWidget): self.setTitle("通知") - self.card_IfSendErrorOnly = SwitchSettingCard( - icon=FluentIcon.PAGE_RIGHT, - title="仅推送异常信息", - content="仅在任务出现异常时推送通知", - configItem=Config.global_config.notify_IfSendErrorOnly, - ) - self.caer_IfSendStatistic = SwitchSettingCard( - icon=FluentIcon.PAGE_RIGHT, - title="推送统计信息", - content="推送自动代理统计信息的通知", - configItem=Config.global_config.notify_IfSendStatistic, - ) + self.card_NotifyContent = self.NotifyContentSettingCard(self) self.card_IfPushPlyer = SwitchSettingCard( icon=FluentIcon.PAGE_RIGHT, title="推送系统通知", @@ -565,22 +554,53 @@ class NotifySettingCard(HeaderCardWidget): self.card_CompanyWebhookBot = self.CompanyWechatPushSettingCard(self) Layout = QVBoxLayout() - Layout.addWidget(self.card_IfSendErrorOnly) - Layout.addWidget(self.caer_IfSendStatistic) + Layout.addWidget(self.card_NotifyContent) Layout.addWidget(self.card_IfPushPlyer) Layout.addWidget(self.card_SendMail) Layout.addWidget(self.card_ServerChan) Layout.addWidget(self.card_CompanyWebhookBot) self.viewLayout.addLayout(Layout) + class NotifyContentSettingCard(ExpandGroupSettingCard): + + def __init__(self, parent=None): + super().__init__( + FluentIcon.SETTING, "通知内容选项", "选择需要推送的通知内容", parent + ) + + self.card_IfSendErrorOnly = SwitchSettingCard( + icon=FluentIcon.PAGE_RIGHT, + title="仅推送异常信息", + content="仅在任务出现异常时推送通知", + configItem=Config.global_config.notify_IfSendErrorOnly, + ) + self.card_IfSendStatistic = SwitchSettingCard( + icon=FluentIcon.PAGE_RIGHT, + title="推送统计信息", + content="推送自动代理统计信息的通知", + configItem=Config.global_config.notify_IfSendStatistic, + ) + self.card_IfSendSixStar = SwitchSettingCard( + icon=FluentIcon.PAGE_RIGHT, + title="推送公招高资喜报", + content="公招出现六星词条时推送喜报", + configItem=Config.global_config.notify_IfSendSixStar, + ) + + widget = QWidget() + Layout = QVBoxLayout(widget) + Layout.addWidget(self.card_IfSendErrorOnly) + Layout.addWidget(self.card_IfSendStatistic) + Layout.addWidget(self.card_IfSendSixStar) + self.viewLayout.setContentsMargins(0, 0, 0, 0) + self.viewLayout.setSpacing(0) + self.addGroupWidget(widget) + class SendMailSettingCard(ExpandGroupSettingCard): def __init__(self, parent=None): super().__init__( - FluentIcon.SETTING, - "推送邮件通知", - "通过电子邮箱推送任务结果", - parent, + FluentIcon.SETTING, "推送邮件通知", "通过电子邮箱推送任务结果", parent ) self.card_IfSendMail = SwitchSettingCard( From c73aca71f73e68d2635c072f0702482ce4645db6 Mon Sep 17 00:00:00 2001 From: DLmaster Date: Thu, 6 Mar 2025 23:02:23 +0800 Subject: [PATCH 6/8] =?UTF-8?q?feat(core):=20=E4=BC=98=E5=8C=96=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 优化相关设置项排布 - 邮件添加HTML模板 --- app/core/config.py | 7 +- app/models/MAA.py | 239 ++++++++++------------------- app/ui/setting.py | 53 ++++--- requirements.txt | 1 + resources/html/MAA_result.html | 160 +++++++++++++++++++ resources/html/MAA_six_star.html | 129 ++++++++++++++++ resources/html/MAA_statistics.html | 233 ++++++++++++++++++++++++++++ resources/version.json | 2 +- 8 files changed, 641 insertions(+), 183 deletions(-) create mode 100644 resources/html/MAA_result.html create mode 100644 resources/html/MAA_six_star.html create mode 100644 resources/html/MAA_statistics.html diff --git a/app/core/config.py b/app/core/config.py index 0427f39..dd18d58 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -793,8 +793,11 @@ class GlobalConfig(QConfig): ui_location = ConfigItem("UI", "location", "100x100") ui_maximized = ConfigItem("UI", "maximized", False, BoolValidator()) - notify_IfSendErrorOnly = ConfigItem( - "Notify", "IfSendErrorOnly", False, BoolValidator() + notify_SendTaskResultTime = OptionsConfigItem( + "Notify", + "SendTaskResultTime", + "不推送", + OptionsValidator(["不推送", "任何时刻", "仅失败时"]), ) notify_IfSendStatistic = ConfigItem( "Notify", "IfSendStatistic", False, BoolValidator() diff --git a/app/models/MAA.py b/app/models/MAA.py index 31159d1..2f2f62a 100644 --- a/app/models/MAA.py +++ b/app/models/MAA.py @@ -34,6 +34,7 @@ import subprocess import shutil import time from pathlib import Path +from jinja2 import Environment, FileSystemLoader from typing import Union, List from app.core import Config @@ -312,7 +313,7 @@ class MaaManager(QObject): self.push_notification( "公招六星", f"喜报:用户 {user[0]} 公招出六星啦!", - "好羡慕~", + {"user_name": self.data[user[2]][0]}, ) # 成功完成代理的用户修改相关参数 @@ -334,6 +335,7 @@ class MaaManager(QObject): ): statistics = Config.merge_maa_logs("指定项", user_logs_list) + statistics["user_info"] = user[0] statistics["start_time"] = user_start_time.strftime( "%Y-%m-%d %H:%M:%S" ) @@ -481,7 +483,7 @@ class MaaManager(QObject): self.user_config_path.mkdir(parents=True, exist_ok=True) shutil.copy(self.maa_set_path, self.user_config_path) - end_log = "" + result_text = "" # 导出结果 if self.mode in ["自动代理", "人工排查"]: @@ -504,28 +506,25 @@ class MaaManager(QObject): wait_index = [_[2] for _ in self.user_list if _[1] == "等待"] # 保存运行日志 - end_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S") - end_log = ( - f"任务开始时间:{begin_time},结束时间:{end_time}\n" - f"已完成数:{len(over_index)},未完成数:{len(error_index) + len(wait_index)}\n\n" - ) - - if len(error_index) != 0: - end_log += ( - f"{self.mode[2:4]}未成功的用户:\n" - f"{"\n".join([self.data[_][0] for _ in error_index])}\n" - ) - if len(wait_index) != 0: - end_log += ( - f"\n未开始{self.mode[2:4]}的用户:\n" - f"{"\n".join([self.data[_][0] for _ in wait_index])}\n" - ) - title = ( f"{self.set["MaaSet"]["Name"]}的{self.mode[:4]}任务报告" if self.set["MaaSet"]["Name"] != "" else f"{self.mode[:4]}任务报告" ) + result = { + "title": f"{self.mode[:4]}任务报告", + "script_name": ( + self.set["MaaSet"]["Name"] + if self.set["MaaSet"]["Name"] != "" + else "空白" + ), + "start_time": begin_time, + "end_time": datetime.now().strftime("%Y-%m-%d %H:%M:%S"), + "completed_count": len(over_index), + "uncompleted_count": len(error_index) + len(wait_index), + "failed_user": [self.data[_][0] for _ in error_index], + "waiting_user": [self.data[_][0] for _ in wait_index], + } # 推送代理结果通知 Notify.push_plyer( title.replace("报告", "已完成!"), @@ -533,18 +532,23 @@ class MaaManager(QObject): f"已完成用户数:{len(over_index)},未完成用户数:{len(error_index) + len(wait_index)}", 10, ) - if not Config.global_config.get( - Config.global_config.notify_IfSendErrorOnly - ) or ( - Config.global_config.get(Config.global_config.notify_IfSendErrorOnly) + if Config.global_config.get( + Config.global_config.notify_SendTaskResultTime + ) == "任何时刻" or ( + Config.global_config.get(Config.global_config.notify_SendTaskResultTime) + == "仅失败时" and len(error_index) + len(wait_index) != 0 ): - self.push_notification("代理结果", title, end_log) + 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.log_monitor.deleteLater() self.log_monitor_timer.deleteLater() - self.accomplish.emit({"Time": begin_time, "History": end_log}) + self.accomplish.emit({"Time": begin_time, "History": result_text}) def requestInterruption(self) -> None: logger.info(f"{self.name} | 收到任务中止申请") @@ -1167,142 +1171,50 @@ class MaaManager(QObject): return dt.strftime("%Y-%m-%d") def push_notification( - self, mode: str, title: str, message: Union[str, dict] - ) -> None: + self, + mode: str, + title: str, + message: Union[str, dict], + if_get_text_only: bool = False, + ) -> str: """通过所有渠道推送通知""" + env = Environment( + loader=FileSystemLoader(str(Config.app_path / "resources/html")) + ) + if mode == "代理结果": - Notify.send_mail( - "文本", - title, - f"{message}\n\nAUTO_MAA 敬上\n\n我们根据您在 AUTO_MAA 中的设置发送了这封电子邮件,本邮件无需回复\n", + # 生成文本通知内容 + message_text = ( + f"任务开始时间:{message["start_time"]},结束时间:{message["end_time"]}\n" + f"已完成数:{message["completed_count"]},未完成数:{message["uncompleted_count"]}\n\n" ) - Notify.ServerChanPush(title, f"{message}\n\nAUTO_MAA 敬上") - Notify.CompanyWebHookBotPush(title, f"{message}AUTO_MAA 敬上") + + if len(message["failed_user"]) > 0: + message_text += f"{self.mode[2:4]}未成功的用户:\n{"\n".join(message["failed_user"])}\n" + if len(message["waiting_user"]) > 0: + message_text += f"\n未开始{self.mode[2:4]}的用户:\n{"\n".join(message["waiting_user"])}\n" + + if if_get_text_only: + return message_text + + # 生成HTML通知内容 + message["failed_user"] = "、".join(message["failed_user"]) + message["waiting_user"] = "、".join(message["waiting_user"]) + + template = env.get_template("MAA_result.html") + message_html = template.render(message) + + Notify.send_mail("网页", title, message_html) + Notify.ServerChanPush(title, f"{message_text}\n\nAUTO_MAA 敬上") + Notify.CompanyWebHookBotPush(title, f"{message_text}\n\nAUTO_MAA 敬上") + + return message_text elif mode == "统计信息": - # HTML模板 - html_template = """ - - - - - {title} - - - -
-

{title}

- -

开始时间: {start_time}

-

结束时间: {end_time}

-

MAA执行结果: {maa_result}

- -

招募统计

- - - - - - - - - {recruit_rows} - -
星级数量
- - {drop_tables} -
- - - """ - - # 构建招募统计表格行 - recruit_rows = "".join( - f"{star}{count}" - for star, count in message["recruit_statistics"].items() - ) - - # 构建掉落统计数据表格 - drop_tables_html = "" - for stage, items in message["drop_statistics"].items(): - drop_rows = "".join( - f"{item}{quantity}" - for item, quantity in items.items() - ) - drop_table = f""" -

掉落统计 ({stage})

- - - - - - - - - {drop_rows} - -
物品数量
- """ - drop_tables_html += drop_table - - # 填充HTML模板 - html_content = html_template.format( - title=title, - start_time=message["start_time"], - end_time=message["end_time"], - maa_result=message["maa_result"], - recruit_rows=recruit_rows, - drop_tables=drop_tables_html, - ) - + # 生成文本通知内容 formatted = [] for stage, items in message["drop_statistics"].items(): formatted.append(f"掉落统计({stage}):") @@ -1315,7 +1227,6 @@ class MaaManager(QObject): formatted.append(f" {star}: {count}") recruit_text = "\n".join(formatted) - # 构建通知消息 message_text = ( f"开始时间: {message['start_time']}\n" f"结束时间: {message['end_time']}\n" @@ -1324,16 +1235,20 @@ class MaaManager(QObject): f"{drop_text}" ) - Notify.send_mail("网页", title, html_content) + # 生成HTML通知内容 + template = env.get_template("MAA_statistics.html") + message_html = template.render(message) + + Notify.send_mail("网页", title, message_html) Notify.ServerChanPush(title, f"{message_text}\n\nAUTO_MAA 敬上") Notify.CompanyWebHookBotPush(title, f"{message_text}\n\nAUTO_MAA 敬上") elif mode == "公招六星": - Notify.send_mail( - "文本", - title, - f"{message}\n\nAUTO_MAA 敬上\n\n我们根据您在 AUTO_MAA 中的设置发送了这封电子邮件,本邮件无需回复\n", - ) - Notify.ServerChanPush(title, f"{message}\n\nAUTO_MAA 敬上") - Notify.CompanyWebHookBotPush(title, f"{message}AUTO_MAA 敬上") + # 生成HTML通知内容 + template = env.get_template("MAA_six_star.html") + message_html = template.render(message) + + Notify.send_mail("网页", title, message_html) + Notify.ServerChanPush(title, "好羡慕~\n\nAUTO_MAA 敬上") + Notify.CompanyWebHookBotPush(title, "好羡慕~\n\nAUTO_MAA 敬上") diff --git a/app/ui/setting.py b/app/ui/setting.py index ee68a06..5aa6e92 100644 --- a/app/ui/setting.py +++ b/app/ui/setting.py @@ -543,20 +543,15 @@ class NotifySettingCard(HeaderCardWidget): self.setTitle("通知") self.card_NotifyContent = self.NotifyContentSettingCard(self) - self.card_IfPushPlyer = SwitchSettingCard( - icon=FluentIcon.PAGE_RIGHT, - title="推送系统通知", - content="推送系统级通知,不会在通知中心停留", - configItem=Config.global_config.notify_IfPushPlyer, - ) - self.card_SendMail = self.SendMailSettingCard(self) + self.card_Plyer = self.PlyerSettingCard(self) + self.card_EMail = self.EMailSettingCard(self) self.card_ServerChan = self.ServerChanSettingCard(self) self.card_CompanyWebhookBot = self.CompanyWechatPushSettingCard(self) Layout = QVBoxLayout() Layout.addWidget(self.card_NotifyContent) - Layout.addWidget(self.card_IfPushPlyer) - Layout.addWidget(self.card_SendMail) + Layout.addWidget(self.card_Plyer) + Layout.addWidget(self.card_EMail) Layout.addWidget(self.card_ServerChan) Layout.addWidget(self.card_CompanyWebhookBot) self.viewLayout.addLayout(Layout) @@ -568,11 +563,12 @@ class NotifySettingCard(HeaderCardWidget): FluentIcon.SETTING, "通知内容选项", "选择需要推送的通知内容", parent ) - self.card_IfSendErrorOnly = SwitchSettingCard( + self.card_SendTaskResultTime = ComboBoxSettingCard( + configItem=Config.global_config.notify_SendTaskResultTime, icon=FluentIcon.PAGE_RIGHT, - title="仅推送异常信息", - content="仅在任务出现异常时推送通知", - configItem=Config.global_config.notify_IfSendErrorOnly, + title="推送任务结果选项", + content="选择推送自动代理与人工排查任务结果的时机", + texts=["不推送", "任何时刻", "仅失败时"], ) self.card_IfSendStatistic = SwitchSettingCard( icon=FluentIcon.PAGE_RIGHT, @@ -589,18 +585,39 @@ class NotifySettingCard(HeaderCardWidget): widget = QWidget() Layout = QVBoxLayout(widget) - Layout.addWidget(self.card_IfSendErrorOnly) + Layout.addWidget(self.card_SendTaskResultTime) Layout.addWidget(self.card_IfSendStatistic) Layout.addWidget(self.card_IfSendSixStar) self.viewLayout.setContentsMargins(0, 0, 0, 0) self.viewLayout.setSpacing(0) self.addGroupWidget(widget) - class SendMailSettingCard(ExpandGroupSettingCard): + class PlyerSettingCard(ExpandGroupSettingCard): def __init__(self, parent=None): super().__init__( - FluentIcon.SETTING, "推送邮件通知", "通过电子邮箱推送任务结果", parent + FluentIcon.SETTING, "推送系统通知", "Plyer系统通知推送渠道", parent + ) + + self.card_IfPushPlyer = SwitchSettingCard( + icon=FluentIcon.PAGE_RIGHT, + title="推送系统通知", + content="使用Plyer推送系统级通知,不会在通知中心停留", + configItem=Config.global_config.notify_IfPushPlyer, + ) + + widget = QWidget() + Layout = QVBoxLayout(widget) + Layout.addWidget(self.card_IfPushPlyer) + self.viewLayout.setContentsMargins(0, 0, 0, 0) + self.viewLayout.setSpacing(0) + self.addGroupWidget(widget) + + class EMailSettingCard(ExpandGroupSettingCard): + + def __init__(self, parent=None): + super().__init__( + FluentIcon.SETTING, "推送邮件通知", "电子邮箱通知推送渠道", parent ) self.card_IfSendMail = SwitchSettingCard( @@ -654,7 +671,7 @@ class NotifySettingCard(HeaderCardWidget): super().__init__( FluentIcon.SETTING, "推送ServerChan通知", - "通过ServerChan通知推送任务结果", + "ServerChan通知推送渠道", parent, ) @@ -701,7 +718,7 @@ class NotifySettingCard(HeaderCardWidget): super().__init__( FluentIcon.SETTING, "推送企业微信机器人通知", - "通过企业微信机器人Webhook通知推送任务结果", + "企业微信机器人Webhook通知推送渠道", parent, ) diff --git a/requirements.txt b/requirements.txt index 95ceb9a..a8597de 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,5 +8,6 @@ pywin32 pyautogui pycryptodome requests +Jinja2 serverchan_sdk nuitka==2.6 \ No newline at end of file diff --git a/resources/html/MAA_result.html b/resources/html/MAA_result.html new file mode 100644 index 0000000..78328d2 --- /dev/null +++ b/resources/html/MAA_result.html @@ -0,0 +1,160 @@ + + + + + + + + +
+
+

{{ title }}

+ + +
+ +
+

脚本实例名称:{{ script_name }}

+

任务开始时间:{{ start_time }}

+

任务结束时间:{{ end_time }}

+

已完成数:{{ completed_count }}

+ {% if uncompleted_count %} +

未完成数:{{ uncompleted_count }}

+ {% endif %} + {% if failed_user %} +

代理未成功的用户: {{ failed_user }}

+ {% endif %} + {% if waiting_user %} +

未开始代理的用户: {{ waiting_user }}

+ {% endif %} +
+ +

AUTO_MAA 敬上

+ + + +
+ + + \ No newline at end of file diff --git a/resources/html/MAA_six_star.html b/resources/html/MAA_six_star.html new file mode 100644 index 0000000..38b461a --- /dev/null +++ b/resources/html/MAA_six_star.html @@ -0,0 +1,129 @@ + + + + + + + + +
+
+

喜报!

+ + +
+ +
+

恭喜用户 {{ user_name }} 喜提公开招募六星高资!

+
+ +

AUTO_MAA 敬上

+ + + +
+ + + \ No newline at end of file diff --git a/resources/html/MAA_statistics.html b/resources/html/MAA_statistics.html new file mode 100644 index 0000000..b3c3e56 --- /dev/null +++ b/resources/html/MAA_statistics.html @@ -0,0 +1,233 @@ + + + + + + + + +
+
+

自动代理统计报告

+ + +
+ +
+

用户代理信息:{{ user_info }}

+

任务开始时间:{{ start_time }}

+

任务结束时间:{{ end_time }}

+

MAA执行结果: + {% if maa_result == '代理任务全部完成' %} + {{ maa_result }} + {% elif maa_result == '代理任务未全部完成' %} + {{ maa_result }} + {% else %} + {{ maa_result }} + {% endif %} +

+ + {% if recruit_statistics %} +

公招统计

+ + + + + + {% for star, count in recruit_statistics %} + + + + + {% endfor %} +
星级数量
{{ star }}{{ count }}
+ {% endif %} + + {% if drop_statistics %} + {% for stage, items in drop_statistics.items() %} +

掉落统计({{ stage }})

+ + + + + + {% for item, amount in items.items() %} + + + + + {% endfor %} +
物品数量
{{ item }}{{ amount }}
+ {% endfor %} + {% endif %} +
+ +

AUTO_MAA 敬上

+ + + +
+ + + \ No newline at end of file diff --git a/resources/version.json b/resources/version.json index 951fec4..cd9a3b2 100644 --- a/resources/version.json +++ b/resources/version.json @@ -1,5 +1,5 @@ { - "main_version": "4.2.4.7", + "main_version": "4.2.4.8", "updater_version": "1.1.2.1", "announcement": "\n## 新增功能\n- 历史记录统计功能上线\n- 添加软件主页\n- 添加启动时直接最小化功能\n- 更新器拥有多网址测速功能\n- 添加统计信息通知功能(含六星监测)\n## 修复BUG\n- RMA70-12不能正确统计的问题\n- 更新器修正`channel`\n## 程序优化\n- 添加MAA监测字段:`未检测到任何模拟器`\n- 取消MAA运行中自动更新", "proxy_list": [ From 576fe59bbc798f013e54d61c6871b6f7534b5a67 Mon Sep 17 00:00:00 2001 From: DLmaster Date: Thu, 6 Mar 2025 23:37:51 +0800 Subject: [PATCH 7/8] =?UTF-8?q?fix(models):=20=E4=BF=AE=E5=A4=8D=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E8=A2=AB=E6=89=8B=E5=8A=A8=E4=B8=AD=E6=AD=A2=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=97=A0=E6=B3=95=E8=A2=AB=E6=AD=A3=E5=B8=B8=E5=BD=95?= =?UTF-8?q?=E5=85=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/MAA.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/MAA.py b/app/models/MAA.py index 2f2f62a..28938d7 100644 --- a/app/models/MAA.py +++ b/app/models/MAA.py @@ -556,7 +556,7 @@ class MaaManager(QObject): if len(self.log_monitor.files()) != 0: self.interrupt.emit() - self.maa_result = "您中止了本次任务" + self.maa_result = "任务被手动中止" self.isInterruptionRequested = True def push_question(self, title: str, message: str) -> bool: @@ -636,6 +636,8 @@ class MaaManager(QObject): minutes=self.set["RunSet"][time_book[mode]] ): self.maa_result = "检测到MAA进程超时" + elif self.isInterruptionRequested: + self.maa_result = "任务被手动中止" else: self.maa_result = "Wait" @@ -649,6 +651,8 @@ class MaaManager(QObject): or ("MaaAssistantArknights GUI exited" in log) ): self.maa_result = "检测到MAA进程异常" + elif self.isInterruptionRequested: + self.maa_result = "任务被手动中止" else: self.maa_result = "Wait" From 181856173e97c181d82297b446c6f6de27e09968 Mon Sep 17 00:00:00 2001 From: DLmaster Date: Thu, 6 Mar 2025 23:42:59 +0800 Subject: [PATCH 8/8] =?UTF-8?q?feat(core):=20=E8=B0=83=E6=95=B4=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E4=B8=BB=E9=A2=98=E5=9B=BE=E5=83=8F=E7=9A=84=E6=97=B6?= =?UTF-8?q?=E6=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/ui/main_window.py | 7 ++++--- resources/version.json | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/ui/main_window.py b/app/ui/main_window.py index 8da86c0..d709762 100644 --- a/app/ui/main_window.py +++ b/app/ui/main_window.py @@ -231,15 +231,16 @@ class AUTO_MAA(MSFluentWindow): # 检查密码 self.setting.check_PASSWORD() - # 获取公告 - self.setting.show_notice(if_show=False) - + # 获取主题图像 if ( Config.global_config.get(Config.global_config.function_HomeImageMode) == "主题图像" ): self.home.get_home_image() + # 获取公告 + self.setting.show_notice(if_show=False) + # 检查更新 if Config.global_config.get(Config.global_config.update_IfAutoUpdate): result = self.setting.get_update_info() diff --git a/resources/version.json b/resources/version.json index cd9a3b2..3077e3b 100644 --- a/resources/version.json +++ b/resources/version.json @@ -1,5 +1,5 @@ { - "main_version": "4.2.4.8", + "main_version": "4.2.5.0", "updater_version": "1.1.2.1", "announcement": "\n## 新增功能\n- 历史记录统计功能上线\n- 添加软件主页\n- 添加启动时直接最小化功能\n- 更新器拥有多网址测速功能\n- 添加统计信息通知功能(含六星监测)\n## 修复BUG\n- RMA70-12不能正确统计的问题\n- 更新器修正`channel`\n## 程序优化\n- 添加MAA监测字段:`未检测到任何模拟器`\n- 取消MAA运行中自动更新", "proxy_list": [