feat(notification): 添加测试通知功能
This commit is contained in:
@@ -243,5 +243,39 @@ class Notification(QWidget):
|
|||||||
f'使用企业微信群机器人推送通知时出错:\n{response.json()["errmsg"]}'
|
f'使用企业微信群机器人推送通知时出错:\n{response.json()["errmsg"]}'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def send_test_notification(self):
|
||||||
|
"""发送测试通知到所有已启用的通知渠道"""
|
||||||
|
# 发送系统通知
|
||||||
|
self.push_plyer(
|
||||||
|
"测试通知",
|
||||||
|
"这是 AUTO_MAA 外部通知测试信息。如果你看到了这段内容,说明 AUTO_MAA 的通知功能已经正确配置且可以正常工作!",
|
||||||
|
"测试通知",
|
||||||
|
3,
|
||||||
|
)
|
||||||
|
|
||||||
|
# 发送邮件通知
|
||||||
|
if Config.global_config.get(Config.global_config.notify_IfSendMail):
|
||||||
|
self.send_mail(
|
||||||
|
"文本",
|
||||||
|
"AUTO_MAA测试通知",
|
||||||
|
"这是 AUTO_MAA 外部通知测试信息。如果你看到了这段内容,说明 AUTO_MAA 的通知功能已经正确配置且可以正常工作!"
|
||||||
|
)
|
||||||
|
|
||||||
|
# 发送Server酱通知
|
||||||
|
if Config.global_config.get(Config.global_config.notify_IfServerChan):
|
||||||
|
self.ServerChanPush(
|
||||||
|
"AUTO_MAA测试通知",
|
||||||
|
"这是 AUTO_MAA 外部通知测试信息。如果你看到了这段内容,说明 AUTO_MAA 的通知功能已经正确配置且可以正常工作!"
|
||||||
|
)
|
||||||
|
|
||||||
|
# 发送企业微信机器人通知
|
||||||
|
if Config.global_config.get(Config.global_config.notify_IfCompanyWebHookBot):
|
||||||
|
self.CompanyWebHookBotPush(
|
||||||
|
"AUTO_MAA测试通知",
|
||||||
|
"这是 AUTO_MAA 外部通知测试信息。如果你看到了这段内容,说明 AUTO_MAA 的通知功能已经正确配置且可以正常工作!"
|
||||||
|
)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
Notify = Notification()
|
Notify = Notification()
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ from PySide6.QtWidgets import (
|
|||||||
QWidget,
|
QWidget,
|
||||||
QApplication,
|
QApplication,
|
||||||
QVBoxLayout,
|
QVBoxLayout,
|
||||||
QVBoxLayout,
|
|
||||||
)
|
)
|
||||||
from qfluentwidgets import (
|
from qfluentwidgets import (
|
||||||
ScrollArea,
|
ScrollArea,
|
||||||
@@ -56,7 +55,7 @@ from pathlib import Path
|
|||||||
from typing import Dict, List, Union
|
from typing import Dict, List, Union
|
||||||
|
|
||||||
from app.core import Config, MainInfoBar
|
from app.core import Config, MainInfoBar
|
||||||
from app.services import Crypto, System
|
from app.services import Crypto, System, Notify
|
||||||
from app.utils import DownloadManager
|
from app.utils import DownloadManager
|
||||||
from .Widget import (
|
from .Widget import (
|
||||||
LineEditMessageBox,
|
LineEditMessageBox,
|
||||||
@@ -630,6 +629,13 @@ class NotifySettingCard(HeaderCardWidget):
|
|||||||
self.card_EMail = self.EMailSettingCard(self)
|
self.card_EMail = self.EMailSettingCard(self)
|
||||||
self.card_ServerChan = self.ServerChanSettingCard(self)
|
self.card_ServerChan = self.ServerChanSettingCard(self)
|
||||||
self.card_CompanyWebhookBot = self.CompanyWechatPushSettingCard(self)
|
self.card_CompanyWebhookBot = self.CompanyWechatPushSettingCard(self)
|
||||||
|
self.card_TestNotification = PushSettingCard(
|
||||||
|
text="发送测试通知",
|
||||||
|
icon=FluentIcon.SEND,
|
||||||
|
title="测试通知",
|
||||||
|
content="发送测试通知到所有已启用的通知渠道",
|
||||||
|
)
|
||||||
|
self.card_TestNotification.clicked.connect(self.send_test_notification)
|
||||||
|
|
||||||
Layout = QVBoxLayout()
|
Layout = QVBoxLayout()
|
||||||
Layout.addWidget(self.card_NotifyContent)
|
Layout.addWidget(self.card_NotifyContent)
|
||||||
@@ -637,8 +643,19 @@ class NotifySettingCard(HeaderCardWidget):
|
|||||||
Layout.addWidget(self.card_EMail)
|
Layout.addWidget(self.card_EMail)
|
||||||
Layout.addWidget(self.card_ServerChan)
|
Layout.addWidget(self.card_ServerChan)
|
||||||
Layout.addWidget(self.card_CompanyWebhookBot)
|
Layout.addWidget(self.card_CompanyWebhookBot)
|
||||||
|
Layout.addWidget(self.card_TestNotification)
|
||||||
self.viewLayout.addLayout(Layout)
|
self.viewLayout.addLayout(Layout)
|
||||||
|
|
||||||
|
def send_test_notification(self):
|
||||||
|
"""发送测试通知到所有已启用的通知渠道"""
|
||||||
|
if Notify.send_test_notification():
|
||||||
|
MainInfoBar.push_info_bar(
|
||||||
|
"success",
|
||||||
|
"测试通知已发送",
|
||||||
|
"请检查已配置的通知渠道是否可以收到消息",
|
||||||
|
3000
|
||||||
|
)
|
||||||
|
|
||||||
class NotifyContentSettingCard(ExpandGroupSettingCard):
|
class NotifyContentSettingCard(ExpandGroupSettingCard):
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
|
|||||||
Reference in New Issue
Block a user