feat 多通知渠道支持
This commit is contained in:
@ -1,6 +1,10 @@
|
||||
from abc import abstractmethod, ABCMeta
|
||||
from typing import Tuple, Union
|
||||
|
||||
from app.db.systemconfig_oper import SystemConfigOper
|
||||
from app.schemas import Notification
|
||||
from app.schemas.types import SystemConfigKey, MessageChannel
|
||||
|
||||
|
||||
class _ModuleBase(metaclass=ABCMeta):
|
||||
"""
|
||||
@ -30,3 +34,32 @@ class _ModuleBase(metaclass=ABCMeta):
|
||||
:return: None,该方法可被多个模块同时处理
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def checkMessage(channel_type: MessageChannel):
|
||||
"""
|
||||
检查消息渠道及消息类型,如不符合则不处理
|
||||
"""
|
||||
|
||||
def decorator(func):
|
||||
def wrapper(self, message: Notification, *args, **kwargs):
|
||||
# 检查消息渠道
|
||||
if message.channel and message.channel != channel_type:
|
||||
return None
|
||||
else:
|
||||
# 检查消息类型开关
|
||||
if message.mtype:
|
||||
switchs = SystemConfigOper().get(SystemConfigKey.NotificationChannels)
|
||||
for switch in switchs:
|
||||
if switch.get("mtype") == message.mtype.value:
|
||||
if channel_type == MessageChannel.Wechat and not switch.get("wechat"):
|
||||
return None
|
||||
if channel_type == MessageChannel.Telegram and not switch.get("telegram"):
|
||||
return None
|
||||
if channel_type == MessageChannel.Slack and not switch.get("slack"):
|
||||
return None
|
||||
return func(self, message, *args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
|
Reference in New Issue
Block a user