Files
MoviePilot/app/application/notification.py

35 lines
1.2 KiB
Python

from typing import Optional
from app.runtime.extensions.service_registry import ServiceBaseHelper
from app.schemas import NotificationConf, ServiceInfo
from app.schemas.types import ModuleType, SystemConfigKey
class NotificationHelper(ServiceBaseHelper[NotificationConf]):
"""提供按持久化配置发现通知服务的能力。"""
def __init__(self):
"""绑定通知配置和通知模块类型。"""
super().__init__(
config_key=SystemConfigKey.Notifications,
conf_type=NotificationConf,
module_type=ModuleType.Notification,
)
def is_notification(
self,
service_type: Optional[str] = None,
service: Optional[ServiceInfo] = None,
name: Optional[str] = None,
) -> bool:
"""
判断通知服务是否属于指定类型。
:param service_type: 消息通知服务的类型名称
:param service: 要判断的服务信息
:param name: 未传入服务信息时用于查询的服务名称
:return: 服务存在且类型匹配时返回 True
"""
service = service or self.get_service(name=name)
return bool(service and service.type == service_type)