新增代理成功消息推送渠道Server酱与企业微信群机器人推送

This commit is contained in:
heziziziscool
2025-02-04 14:07:45 +08:00
committed by DLmaster
parent a5b4f6f59f
commit 6f0aec329b
5 changed files with 190 additions and 11 deletions

View File

@@ -556,6 +556,14 @@ 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())

View File

@@ -528,6 +528,14 @@ 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}AUTO_MAA 敬上",
)
self.accomplish.emit({"Time": begin_time, "History": end_log}) self.accomplish.emit({"Time": begin_time, "History": end_log})

View File

@@ -24,13 +24,16 @@ AUTO_MAA通知服务
v4.2 v4.2
作者DLmaster_361 作者DLmaster_361
""" """
import requests
from loguru import logger
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 app.core import Config from app.core import Config
@@ -96,5 +99,62 @@ class Notification:
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|ba|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()

View File

@@ -519,6 +519,13 @@ 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="推送系统通知",
@@ -527,9 +534,13 @@ 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)
@@ -561,16 +572,8 @@ 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)
@@ -578,6 +581,94 @@ 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酱的SendKeySC3与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="请输入加入推送的TagSC3生效",
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):
@@ -642,10 +733,20 @@ 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)
@@ -659,6 +760,7 @@ class OtherSettingCard(HeaderCardWidget):
parent, parent,
) )
self.card_GitHubRepository = HyperlinkCard( self.card_GitHubRepository = HyperlinkCard(
url="https://github.com/DLmaster361/AUTO_MAA", url="https://github.com/DLmaster361/AUTO_MAA",
text="访问GitHub仓库", text="访问GitHub仓库",

View File

@@ -8,4 +8,5 @@ pywin32
pyautogui pyautogui
pycryptodome pycryptodome
requests requests
nuitka==2.6 nuitka==2.6
serverchan_sdk