1- from __future__ import annotations
2-
1+ import importlib
32import logging
4- from enum import Enum
53
64from module .conf import settings
75from module .database import Database
8- from module .models import Notification
6+ from module .models import Message
7+ from module .models .config import Notification
98from module .network import load_image
10- import importlib
11-
129from module .notification .plugin .log import Notifier
1310
1411logger = logging .getLogger (__name__ )
@@ -36,12 +33,12 @@ def get_poster_from_db(title: str) -> str:
3633 logger .error (f"获取海报失败: { title } - { e } " )
3734 return ""
3835
39- async def process_notification (self , notify : Notification ) -> Notification :
36+ async def process_notification (self , notify : Message ) -> Message :
4037 """
4138 处理通知对象,进行必要的数据解析和补充
4239 """
4340 # 创建副本,避免修改原对象
44- processed = Notification (
41+ processed = Message (
4542 title = notify .title ,
4643 season = notify .season ,
4744 episode = notify .episode ,
@@ -70,17 +67,25 @@ class PostNotification:
7067 """
7168
7269 def __init__ (self ) -> None :
73- self .processor = NotificationProcessor ()
70+ self .processor : NotificationProcessor = NotificationProcessor ()
7471 self .logger = logging .getLogger (self .__class__ .__name__ )
75- self .notifier = None
72+ self .config : Notification = settings .notification
73+ self .notifier = Notifier (** self .config .model_dump ())
7674
77- def initialize (self ) -> None :
75+ def initialize (self , config : Notification | None = None ) -> None :
7876 """根据设置创建通知管理器"""
79- self .notifier = self ._get_notifier ()
80- self .notifier .initialize ()
81-
82- def _get_notifier (self ):
83- notification_type = settings .notification .type
77+ self .config = settings .notification
78+ if not self .config .enable :
79+ logger .info ("通知功能已禁用" )
80+ return
81+ self .notifier = self ._get_notifier (config )
82+ # self.notifier.initialize()
83+
84+ def _get_notifier (self , config : Notification | None = None ) -> Notifier :
85+ print (f"获取通知器: { config } " )
86+ if config is None :
87+ config = self .config
88+ notification_type = config .type
8489 package_path = f"module.notification.plugin.{ notification_type } "
8590 try :
8691 notification_module = importlib .import_module (package_path )
@@ -93,10 +98,10 @@ def _get_notifier(self):
9398 f"使用默认日志通知器: { notification_module .Notifier .__name__ } "
9499 )
95100 Notifier = notification_module .Notifier
96- logger .debug (f"加载通知器: { Notifier . __name__ } " )
97- return Notifier ()
101+ logger .debug (f"加载通知器: { config . type } " )
102+ return Notifier (** config . model_dump () )
98103
99- async def send (self , notify : Notification ) -> bool :
104+ async def send (self , notify : Message ) -> bool :
100105 """
101106 发送通知
102107
@@ -125,7 +130,10 @@ async def send(self, notify: Notification) -> bool:
125130 # 测试用例
126131 title = "败犬"
127132 link = "posters/aHR0cHM6Ly9pbWFnZS50bWRiLm9yZy90L3Avdzc4MC9wYWRSbWJrMkxkTGd1ZGg1Y0xZMG85VEZ6aEkuanBn"
128- nt = Notification (title = title , season = 1 , episode = "1" , poster_path = link )
133+
134+ title = "AB通知测试"
135+ link = "https://mikanani.me/images/Bangumi/202507/8a6beaff.jpg"
136+ nt = Message (title = title , season = "1" , episode = "1" , poster_path = link )
129137 sender = PostNotification ()
130138 sender .initialize ()
131139
0 commit comments