diff --git a/app/chain/site.py b/app/chain/site.py index c5eb4541..5ec58e2f 100644 --- a/app/chain/site.py +++ b/app/chain/site.py @@ -188,7 +188,7 @@ class SiteChain(ChainBase): if not cookies: logger.error(f"CookieCloud同步失败:{msg}") if manual: - self.message.put(f"CookieCloud同步失败: {msg}") + self.message.put(msg, title="CookieCloud同步失败", role="system") return False, msg # 保存Cookie或新增站点 _update_count = 0 @@ -276,8 +276,8 @@ class SiteChain(ChainBase): if _fail_count > 0: ret_msg += f",{_fail_count}个站点添加失败,下次同步时将重试,也可以手动添加" if manual: - self.message.put(f"CookieCloud同步成功, {ret_msg}") - logger.info(f"CookieCloud同步成功:{ret_msg}") + self.message.put(ret_msg, title="CookieCloud同步成功", role="system") + logger.info(f"CookieCloud同步成功:{ret_msg}", role="system") return True, ret_msg @eventmanager.register(EventType.SiteUpdated) diff --git a/app/chain/subscribe.py b/app/chain/subscribe.py index f0693da9..222cb816 100644 --- a/app/chain/subscribe.py +++ b/app/chain/subscribe.py @@ -378,9 +378,9 @@ class SubscribeChain(ChainBase): # 手动触发时发送系统消息 if manual: if sid: - self.message.put(f'订阅 {subscribes[0].name} 搜索完成!') + self.message.put(f'{subscribes[0].name} 搜索完成!', title="订阅搜索", role="system") else: - self.message.put('所有订阅搜索完成!') + self.message.put('所有订阅搜索完成!', title="订阅搜索", role="system") def update_subscribe_priority(self, subscribe: Subscribe, meta: MetaInfo, mediainfo: MediaInfo, downloads: List[Context]): diff --git a/app/helper/message.py b/app/helper/message.py index c0a32031..d08caf2e 100644 --- a/app/helper/message.py +++ b/app/helper/message.py @@ -10,36 +10,44 @@ class MessageHelper(metaclass=Singleton): """ 消息队列管理器,包括系统消息和用户消息 """ + def __init__(self): self.sys_queue = queue.Queue() self.user_queue = queue.Queue() - def put(self, message: Any, role: str = "system", note: Union[list, dict] = None): + def put(self, message: Any, role: str = "plugin", title: str = None, note: Union[list, dict] = None): """ 存消息 :param message: 消息 :param role: 消息通道 systm:系统消息,plugin:插件消息,user:用户消息 + :param title: 标题 :param note: 附件json """ if role in ["system", "plugin"]: + # 没有标题时获取插件名称 + if role == "plugin" and not title: + title = "插件通知" # 系统通知,默认 self.sys_queue.put(json.dumps({ "type": role, - "title": message, + "title": title, + "text": message, "date": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), - "text": note + "note": note })) else: if isinstance(message, str): # 非系统的文本通知 self.user_queue.put(json.dumps({ - "title": message, + "title": title, + "text": message, "date": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), "note": note })) elif hasattr(message, "to_dict"): # 非系统的复杂结构通知,如媒体信息/种子列表等。 content = message.to_dict() + content['title'] = title content['date'] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) content['note'] = note self.user_queue.put(json.dumps(content)) diff --git a/app/main.py b/app/main.py index 4a50110f..fd33d9f1 100644 --- a/app/main.py +++ b/app/main.py @@ -149,7 +149,7 @@ def check_auth(): """ if SitesHelper().auth_level < 2: err_msg = "用户认证失败,站点相关功能将无法使用!" - MessageHelper().put(f"注意:{err_msg}") + MessageHelper().put(f"注意:{err_msg}", title="用户认证", role="system") CommandChian().post_message( Notification( mtype=NotificationType.Manual,