@@ -556,14 +556,6 @@ class GlobalConfig(QConfig):
|
|||||||
"Notify", "IfSendErrorOnly", False, BoolValidator()
|
"Notify", "IfSendErrorOnly", False, BoolValidator()
|
||||||
)
|
)
|
||||||
notify_MailAddress = ConfigItem("Notify", "MailAddress", "")
|
notify_MailAddress = ConfigItem("Notify", "MailAddress", "")
|
||||||
notify_IfServerChan = ConfigItem("Notify", "IfServerChan", False, BoolValidator())
|
|
||||||
notify_ServerChanKey = ConfigItem("Notify", "ServerChanKey", "")
|
|
||||||
notify_ServerChanChannel = ConfigItem("Notify", "ServerChanChannel", "")
|
|
||||||
notify_ServerChanTag = ConfigItem("Notify", "ServerChanTag", "")
|
|
||||||
notify_IfCompanyWebHookBot = ConfigItem("Notify", "IfCompanyWebHookBot", False, BoolValidator())
|
|
||||||
notify_CompanyWebHookBotUrl = ConfigItem("Notify", "CompanyWebHookBotUrl", "")
|
|
||||||
notify_IfPushDeer = ConfigItem("Notify", "IfPushDeer", False, BoolValidator())
|
|
||||||
notify_IfPushDeerKey = ConfigItem("Notify", "PushDeerKey", "")
|
|
||||||
|
|
||||||
update_IfAutoUpdate = ConfigItem("Update", "IfAutoUpdate", False, BoolValidator())
|
update_IfAutoUpdate = ConfigItem("Update", "IfAutoUpdate", False, BoolValidator())
|
||||||
|
|
||||||
|
|||||||
@@ -528,14 +528,6 @@ class MaaManager(QObject):
|
|||||||
f"{self.mode[:4]}任务报告",
|
f"{self.mode[:4]}任务报告",
|
||||||
f"{end_log}\n\nAUTO_MAA 敬上\n\n我们根据您在 AUTO_MAA 中的设置发送了这封电子邮件,本邮件无需回复\n",
|
f"{end_log}\n\nAUTO_MAA 敬上\n\n我们根据您在 AUTO_MAA 中的设置发送了这封电子邮件,本邮件无需回复\n",
|
||||||
)
|
)
|
||||||
Notify.ServerChanPush(
|
|
||||||
f"{self.mode[:4]}任务报告",
|
|
||||||
f"{end_log}\n\nAUTO_MAA 敬上",
|
|
||||||
)
|
|
||||||
Notify.CompanyWebHookBotPush(
|
|
||||||
f"{self.mode[:4]}任务报告",
|
|
||||||
f"{end_log}\nAUTO_MAA 敬上",
|
|
||||||
)
|
|
||||||
|
|
||||||
self.accomplish.emit({"Time": begin_time, "History": end_log})
|
self.accomplish.emit({"Time": begin_time, "History": end_log})
|
||||||
|
|
||||||
|
|||||||
@@ -24,14 +24,13 @@ AUTO_MAA通知服务
|
|||||||
v4.2
|
v4.2
|
||||||
作者:DLmaster_361
|
作者:DLmaster_361
|
||||||
"""
|
"""
|
||||||
import requests
|
|
||||||
from plyer import notification
|
from plyer import notification
|
||||||
import smtplib
|
import smtplib
|
||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
from email.header import Header
|
from email.header import Header
|
||||||
from email.utils import formataddr
|
from email.utils import formataddr
|
||||||
from serverchan_sdk import sc_send
|
|
||||||
from loguru import logger
|
|
||||||
from app.core import Config
|
from app.core import Config
|
||||||
|
|
||||||
|
|
||||||
@@ -41,6 +40,7 @@ class Notification:
|
|||||||
"""推送系统通知"""
|
"""推送系统通知"""
|
||||||
|
|
||||||
if Config.global_config.get(Config.global_config.notify_IfPushPlyer):
|
if Config.global_config.get(Config.global_config.notify_IfPushPlyer):
|
||||||
|
|
||||||
notification.notify(
|
notification.notify(
|
||||||
title=title,
|
title=title,
|
||||||
message=message,
|
message=message,
|
||||||
@@ -90,70 +90,11 @@ class Notification:
|
|||||||
Config.global_config.get(Config.global_config.notify_MailAddress),
|
Config.global_config.get(Config.global_config.notify_MailAddress),
|
||||||
message.as_string(),
|
message.as_string(),
|
||||||
)
|
)
|
||||||
logger.info("邮件发送成功")
|
|
||||||
return True
|
return True
|
||||||
except smtplib.SMTPException as e:
|
except smtplib.SMTPException as e:
|
||||||
return f"发送邮件时出错:\n{e}"
|
return f"发送邮件时出错:\n{e}"
|
||||||
finally:
|
finally:
|
||||||
smtpObj.quit()
|
smtpObj.quit()
|
||||||
|
|
||||||
def ServerChanPush(self, title, content):
|
|
||||||
"""使用Server酱推送通知"""
|
|
||||||
|
|
||||||
if Config.global_config.get(Config.global_config.notify_IfServerChan):
|
|
||||||
send_key = Config.global_config.get(Config.global_config.notify_ServerChanKey)
|
|
||||||
option = {}
|
|
||||||
is_valid = lambda s: s == "" or (s == '|'.join(s.split('|')) and (s.count('|') == 0 or all(s.split('|'))))
|
|
||||||
"""
|
|
||||||
is_valid => True, 如果启用的话需要正确设置Tag和Channel。
|
|
||||||
允许空的Tag和Channel即不启用,但不允许例如a||b,|a|b,a|b|,||||
|
|
||||||
"""
|
|
||||||
send_tag = Config.global_config.get(Config.global_config.notify_ServerChanTag)
|
|
||||||
send_channel = Config.global_config.get(Config.global_config.notify_ServerChanChannel)
|
|
||||||
|
|
||||||
if is_valid(send_tag):
|
|
||||||
option['tags'] = send_tag
|
|
||||||
else:
|
|
||||||
option['tags'] = ''
|
|
||||||
logger.warning('请正确设置Auto_MAA中ServerChan的Tag。')
|
|
||||||
|
|
||||||
if is_valid(send_channel):
|
|
||||||
option['channel'] = send_channel
|
|
||||||
else:
|
|
||||||
option['channel'] = ''
|
|
||||||
logger.warning('请正确设置Auto_MAA中ServerChan的Channel。')
|
|
||||||
|
|
||||||
response = sc_send(send_key, title, content, option)
|
|
||||||
if response["code"] == 0:
|
|
||||||
logger.info("Server酱推送通知成功")
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
logger.info("Server酱推送通知失败")
|
|
||||||
logger.error(response)
|
|
||||||
return f'使用Server酱推送通知时出错:\n{response["data"]['error']}'
|
|
||||||
|
|
||||||
def CompanyWebHookBotPush(self, title, content):
|
|
||||||
"""使用企业微信群机器人推送通知"""
|
|
||||||
if Config.global_config.get(Config.global_config.notify_IfCompanyWebHookBot):
|
|
||||||
content = f'{title}\n{content}'
|
|
||||||
data = {
|
|
||||||
"msgtype": "text",
|
|
||||||
"text": {
|
|
||||||
"content": content
|
|
||||||
}
|
|
||||||
}
|
|
||||||
response = requests.post(
|
|
||||||
url=Config.global_config.get(Config.global_config.notify_CompanyWebHookBotUrl),
|
|
||||||
json=data
|
|
||||||
)
|
|
||||||
if response.json()["errcode"] == 0:
|
|
||||||
logger.info("企业微信群机器人推送通知成功")
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
logger.info("企业微信群机器人推送通知失败")
|
|
||||||
logger.error(response.json())
|
|
||||||
return f'使用企业微信群机器人推送通知时出错:\n{response.json()["errmsg"]}'
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Notify = Notification()
|
Notify = Notification()
|
||||||
|
|||||||
@@ -519,13 +519,6 @@ class NotifySettingCard(HeaderCardWidget):
|
|||||||
|
|
||||||
Layout = QVBoxLayout()
|
Layout = QVBoxLayout()
|
||||||
|
|
||||||
self.card_IfSendErrorOnly = SwitchSettingCard(
|
|
||||||
icon=FluentIcon.PAGE_RIGHT,
|
|
||||||
title="仅推送异常信息",
|
|
||||||
content="仅在任务出现异常时推送通知",
|
|
||||||
configItem=Config.global_config.notify_IfSendErrorOnly,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.card_IfPushPlyer = SwitchSettingCard(
|
self.card_IfPushPlyer = SwitchSettingCard(
|
||||||
icon=FluentIcon.PAGE_RIGHT,
|
icon=FluentIcon.PAGE_RIGHT,
|
||||||
title="推送系统通知",
|
title="推送系统通知",
|
||||||
@@ -534,13 +527,9 @@ class NotifySettingCard(HeaderCardWidget):
|
|||||||
)
|
)
|
||||||
|
|
||||||
self.card_SendMail = self.SendMailSettingCard(self)
|
self.card_SendMail = self.SendMailSettingCard(self)
|
||||||
self.card_ServerChan = self.ServerChanSettingCard(self)
|
|
||||||
self.card_CompanyWebhookBot = self.CompanyWechatPushSettingCard(self)
|
|
||||||
Layout.addWidget(self.card_IfSendErrorOnly)
|
|
||||||
Layout.addWidget(self.card_IfPushPlyer)
|
Layout.addWidget(self.card_IfPushPlyer)
|
||||||
Layout.addWidget(self.card_SendMail)
|
Layout.addWidget(self.card_SendMail)
|
||||||
Layout.addWidget(self.card_ServerChan)
|
|
||||||
Layout.addWidget(self.card_CompanyWebhookBot)
|
|
||||||
|
|
||||||
self.viewLayout.addLayout(Layout)
|
self.viewLayout.addLayout(Layout)
|
||||||
|
|
||||||
@@ -572,8 +561,16 @@ class NotifySettingCard(HeaderCardWidget):
|
|||||||
configItem=Config.global_config.notify_MailAddress,
|
configItem=Config.global_config.notify_MailAddress,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.card_IfSendErrorOnly = SwitchSettingCard(
|
||||||
|
icon=FluentIcon.PAGE_RIGHT,
|
||||||
|
title="仅推送异常信息",
|
||||||
|
content="仅在任务出现异常时推送通知",
|
||||||
|
configItem=Config.global_config.notify_IfSendErrorOnly,
|
||||||
|
)
|
||||||
|
|
||||||
Layout.addWidget(self.card_IfSendMail)
|
Layout.addWidget(self.card_IfSendMail)
|
||||||
Layout.addWidget(self.MailAddress)
|
Layout.addWidget(self.MailAddress)
|
||||||
|
Layout.addWidget(self.card_IfSendErrorOnly)
|
||||||
|
|
||||||
# 调整内部布局
|
# 调整内部布局
|
||||||
self.viewLayout.setContentsMargins(0, 0, 0, 0)
|
self.viewLayout.setContentsMargins(0, 0, 0, 0)
|
||||||
@@ -581,94 +578,6 @@ class NotifySettingCard(HeaderCardWidget):
|
|||||||
|
|
||||||
self.addGroupWidget(widget)
|
self.addGroupWidget(widget)
|
||||||
|
|
||||||
class ServerChanSettingCard(ExpandGroupSettingCard):
|
|
||||||
def __init__(self, parent=None):
|
|
||||||
super().__init__(
|
|
||||||
FluentIcon.SETTING,
|
|
||||||
"ServerChan推送",
|
|
||||||
"通过ServerChan推送推送任务结果",
|
|
||||||
parent,
|
|
||||||
)
|
|
||||||
|
|
||||||
widget = QWidget()
|
|
||||||
Layout = QVBoxLayout(widget)
|
|
||||||
|
|
||||||
self.card_IfServerChan = SwitchSettingCard(
|
|
||||||
icon=FluentIcon.PAGE_RIGHT,
|
|
||||||
title="SeverChan推送",
|
|
||||||
content="是否SeverChan推送",
|
|
||||||
configItem=Config.global_config.notify_IfServerChan,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.ServerChanKey = LineEditSettingCard(
|
|
||||||
text="请输入SendKey",
|
|
||||||
icon=FluentIcon.PAGE_RIGHT,
|
|
||||||
title="SendKey",
|
|
||||||
content="Server酱的SendKey(SC3与SCT都可以)",
|
|
||||||
configItem=Config.global_config.notify_ServerChanKey,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.ServerChanChannel = LineEditSettingCard(
|
|
||||||
text="请输入需要推送的Channel代码(SCT生效)",
|
|
||||||
icon=FluentIcon.PAGE_RIGHT,
|
|
||||||
title="ServerChanChannel代码",
|
|
||||||
content="可以留空,留空则默认。可以多个,请使用|隔开",
|
|
||||||
configItem=Config.global_config.notify_ServerChanChannel,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.ServerChanTag = LineEditSettingCard(
|
|
||||||
text="请输入加入推送的Tag(SC3生效)",
|
|
||||||
icon=FluentIcon.PAGE_RIGHT,
|
|
||||||
title="Tag内容",
|
|
||||||
content="可以留空,留空则默认。可以多个,请使用|隔开",
|
|
||||||
configItem=Config.global_config.notify_ServerChanTag,
|
|
||||||
)
|
|
||||||
Layout.addWidget(self.card_IfServerChan)
|
|
||||||
Layout.addWidget(self.ServerChanKey)
|
|
||||||
Layout.addWidget(self.ServerChanChannel)
|
|
||||||
Layout.addWidget(self.ServerChanTag)
|
|
||||||
self.viewLayout.setContentsMargins(0, 0, 0, 0)
|
|
||||||
self.viewLayout.setSpacing(0)
|
|
||||||
self.addGroupWidget(widget)
|
|
||||||
|
|
||||||
widget = QWidget()
|
|
||||||
Layout = QVBoxLayout(widget)
|
|
||||||
|
|
||||||
class CompanyWechatPushSettingCard(ExpandGroupSettingCard):
|
|
||||||
def __init__(self, parent=None):
|
|
||||||
super().__init__(
|
|
||||||
FluentIcon.SETTING,
|
|
||||||
"企业微信机器人推送",
|
|
||||||
"通过企业微信机器人Webhook推送推送任务结果",
|
|
||||||
parent,
|
|
||||||
)
|
|
||||||
|
|
||||||
widget = QWidget()
|
|
||||||
Layout = QVBoxLayout(widget)
|
|
||||||
|
|
||||||
self.card_IfCompanyWechat = SwitchSettingCard(
|
|
||||||
icon=FluentIcon.PAGE_RIGHT,
|
|
||||||
title="企业微信机器人推送",
|
|
||||||
content="是否启用企业微信机器人推送",
|
|
||||||
configItem=Config.global_config.notify_IfCompanyWebHookBot,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.CompanyWebHookBotUrl = LineEditSettingCard(
|
|
||||||
text="请输入Webhook的Url",
|
|
||||||
icon=FluentIcon.PAGE_RIGHT,
|
|
||||||
title="WebhookUrl",
|
|
||||||
content="企业微信群机器人的Webhook地址",
|
|
||||||
configItem=Config.global_config.notify_CompanyWebHookBotUrl,
|
|
||||||
)
|
|
||||||
|
|
||||||
Layout.addWidget(self.card_IfCompanyWechat)
|
|
||||||
Layout.addWidget(self.CompanyWebHookBotUrl)
|
|
||||||
self.viewLayout.setContentsMargins(0, 0, 0, 0)
|
|
||||||
self.viewLayout.setSpacing(0)
|
|
||||||
self.addGroupWidget(widget)
|
|
||||||
widget = QWidget()
|
|
||||||
Layout = QVBoxLayout(widget)
|
|
||||||
|
|
||||||
|
|
||||||
class SecuritySettingCard(HeaderCardWidget):
|
class SecuritySettingCard(HeaderCardWidget):
|
||||||
|
|
||||||
@@ -733,20 +642,10 @@ class OtherSettingCard(HeaderCardWidget):
|
|||||||
title="公告",
|
title="公告",
|
||||||
content="查看AUTO_MAA的最新公告",
|
content="查看AUTO_MAA的最新公告",
|
||||||
)
|
)
|
||||||
|
|
||||||
self.card_UserDocs = HyperlinkCard(
|
|
||||||
url="https://docs.qq.com/aio/DQ2NwUHRiWGtMWHBy",
|
|
||||||
text="访问用户文档",
|
|
||||||
icon=FluentIcon.PAGE_RIGHT,
|
|
||||||
title="用户文档",
|
|
||||||
content="查看AUTO_MAA的使用教程和文档",
|
|
||||||
)
|
|
||||||
|
|
||||||
self.card_Association = self.AssociationSettingCard()
|
self.card_Association = self.AssociationSettingCard()
|
||||||
|
|
||||||
Layout = QVBoxLayout()
|
Layout = QVBoxLayout()
|
||||||
Layout.addWidget(self.card_Notice)
|
Layout.addWidget(self.card_Notice)
|
||||||
Layout.addWidget(self.card_UserDocs)
|
|
||||||
Layout.addWidget(self.card_Association)
|
Layout.addWidget(self.card_Association)
|
||||||
self.viewLayout.addLayout(Layout)
|
self.viewLayout.addLayout(Layout)
|
||||||
|
|
||||||
|
|||||||
@@ -8,5 +8,4 @@ pywin32
|
|||||||
pyautogui
|
pyautogui
|
||||||
pycryptodome
|
pycryptodome
|
||||||
requests
|
requests
|
||||||
nuitka==2.6
|
nuitka==2.6
|
||||||
serverchan_sdk
|
|
||||||
Reference in New Issue
Block a user