diff --git a/app/chain/__init__.py b/app/chain/__init__.py index 7209651e..0c2f2a9c 100644 --- a/app/chain/__init__.py +++ b/app/chain/__init__.py @@ -16,7 +16,7 @@ from app.core.module import ModuleManager from app.log import logger from app.schemas import TransferInfo, TransferTorrent, ExistMediaInfo, DownloadingTorrent, CommingMessage, Notification, \ WebhookEventInfo -from app.schemas.types import TorrentStatus, MediaType, MediaImageType +from app.schemas.types import TorrentStatus, MediaType, MediaImageType, EventType from app.utils.object import ObjectUtils @@ -330,6 +330,15 @@ class ChainBase(metaclass=ABCMeta): :param message: 消息体 :return: 成功或失败 """ + # 发送事件 + self.eventmanager.send_event(etype=EventType.NoticeMessage, + data={ + "channel": message.channel, + "title": message.title, + "text": message.text, + "image": message.image, + "userid": message.userid, + }) return self.run_module("post_message", message=message) def post_medias_message(self, message: Notification, medias: List[MediaInfo]) -> Optional[bool]: diff --git a/app/modules/wechat/__init__.py b/app/modules/wechat/__init__.py index 51adbbec..dfaa14df 100644 --- a/app/modules/wechat/__init__.py +++ b/app/modules/wechat/__init__.py @@ -3,13 +3,11 @@ from typing import Optional, Union, List, Tuple, Any from app.core.config import settings from app.core.context import Context, MediaInfo -from app.core.event import EventManager from app.log import logger from app.modules import _ModuleBase, checkMessage from app.modules.wechat.WXBizMsgCrypt3 import WXBizMsgCrypt from app.modules.wechat.wechat import WeChat from app.schemas import MessageChannel, CommingMessage, Notification -from app.schemas.types import EventType from app.utils.dom import DomUtils @@ -123,14 +121,6 @@ class WechatModule(_ModuleBase): :param message: 消息内容 :return: 成功或失败 """ - # 发送事件 - EventManager().send_event(etype=EventType.WechatMessage, - data={ - "title": message.title, - "text": message.text, - "image": message.image, - "userid": message.userid, - }) return self.wechat.send_msg(title=message.title, text=message.text, image=message.image, userid=message.userid) diff --git a/app/plugins/messageforward/__init__.py b/app/plugins/messageforward/__init__.py index 28250ae4..52855564 100644 --- a/app/plugins/messageforward/__init__.py +++ b/app/plugins/messageforward/__init__.py @@ -5,7 +5,7 @@ from datetime import datetime from app.core.config import settings from app.plugins import _PluginBase from app.core.event import eventmanager -from app.schemas.types import EventType +from app.schemas.types import EventType, MessageChannel from app.utils.http import RequestUtils from typing import Any, List, Dict, Tuple, Optional from app.log import logger @@ -13,7 +13,7 @@ from app.log import logger class MessageForward(_PluginBase): # 插件名称 - plugin_name = "WeChat消息转发" + plugin_name = "消息转发" # 插件描述 plugin_desc = "根据正则转发通知到其他WeChat应用。" # 插件图标 @@ -107,7 +107,7 @@ class MessageForward(_PluginBase): 'props': { 'model': 'wechat', 'rows': '3', - 'label': 'wechat应用配置', + 'label': '应用配置', 'placeholder': 'appid:corpid:appsecret(一行一个配置)' } } @@ -130,7 +130,7 @@ class MessageForward(_PluginBase): 'model': 'pattern', 'rows': '3', 'label': '正则配置', - 'placeholder': '对应上方wechat配置,一行一个,一一对应' + 'placeholder': '对应上方应用配置,一行一个,一一对应' } } ] @@ -148,7 +148,7 @@ class MessageForward(_PluginBase): def get_page(self) -> List[dict]: pass - @eventmanager.register(EventType.WechatMessage) + @eventmanager.register(EventType.NoticeMessage) def send(self, event): """ 消息转发 @@ -158,6 +158,10 @@ class MessageForward(_PluginBase): # 消息体 data = event.event_data + channel = data['channel'] + if channel and channel != MessageChannel.Wechat: + return + title = data['title'] text = data['text'] image = data['image'] diff --git a/app/plugins/nastoolssync/__init__.py b/app/plugins/nastoolsync/__init__.py similarity index 94% rename from app/plugins/nastoolssync/__init__.py rename to app/plugins/nastoolsync/__init__.py index 8db541ff..1072bec2 100644 --- a/app/plugins/nastoolssync/__init__.py +++ b/app/plugins/nastoolsync/__init__.py @@ -7,11 +7,11 @@ from typing import Any, List, Dict, Tuple from app.log import logger -class NastoolsSync(_PluginBase): +class NAStoolSync(_PluginBase): # 插件名称 plugin_name = "历史记录同步" # 插件描述 - plugin_desc = "同步NasTools历史记录到MoviePilot。" + plugin_desc = "同步NAStool历史记录到MoviePilot。" # 插件图标 plugin_icon = "sync.png" # 主题色 @@ -163,12 +163,13 @@ class NastoolsSync(_PluginBase): AND t.TYPE = d.TYPE;''' cursor.execute(sql) nt_historys = cursor.fetchall() + cursor.close() if not nt_historys: - logger.error("未获取到NasTools数据库文件中的转移历史,请检查数据库路径是正确") + logger.error("未获取到NAStool数据库文件中的转移历史,请检查数据库路径是正确") return - logger.info(f"获取到NasTools转移记录 {len(nt_historys)} 条") + logger.info(f"获取到NAStool转移记录 {len(nt_historys)} 条") return nt_historys def get_state(self) -> bool: @@ -224,7 +225,7 @@ class NastoolsSync(_PluginBase): 'component': 'VTextField', 'props': { 'model': 'nt_db_path', - 'label': 'NasTools数据库user.db路径', + 'label': 'NAStool数据库user.db路径', } } ] @@ -245,7 +246,7 @@ class NastoolsSync(_PluginBase): 'props': { 'model': 'path', 'label': '路径映射', - 'placeholder': 'NasTools路径:MoviePilot路径(一行一个)' + 'placeholder': 'NAStool路径:MoviePilot路径(一行一个)' } } ] diff --git a/app/schemas/types.py b/app/schemas/types.py index 33da1142..5eea698d 100644 --- a/app/schemas/types.py +++ b/app/schemas/types.py @@ -36,8 +36,8 @@ class EventType(Enum): MediaDeleted = "media.deleted" # 用户外来消息 UserMessage = "user.message" - # wechat消息 - WechatMessage = "wechat.message" + # 通知消息 + NoticeMessage = "notice.message" # 系统配置Key字典