From 536bd9268a4118c1e5e3cc53ffe1a34243cd75d1 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sat, 30 Mar 2024 08:04:52 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E6=96=B0=E5=A2=9E=E8=AE=A2?= =?UTF-8?q?=E9=98=85=E7=9B=B8=E5=85=B3=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chain/subscribe.py | 18 +++++++++++++++++- app/schemas/types.py | 22 +++++++++++++--------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/app/chain/subscribe.py b/app/chain/subscribe.py index 76f3fb034..63c942bfb 100644 --- a/app/chain/subscribe.py +++ b/app/chain/subscribe.py @@ -12,7 +12,7 @@ from app.chain.torrents import TorrentsChain from app.core.config import settings from app.core.context import TorrentInfo, Context, MediaInfo -from app.core.event import eventmanager, Event +from app.core.event import eventmanager, Event, EventManager from app.core.meta import MetaBase from app.core.metainfo import MetaInfo from app.db.models.subscribe import Subscribe @@ -153,6 +153,12 @@ def add(self, title: str, year: str, title=f"{mediainfo.title_year} {metainfo.season} 已添加订阅", text=text, image=mediainfo.get_message_image())) + # 发送事件 + EventManager().send_event(EventType.SubscribeAdded, { + "subscribe_id": sid, + "username": username, + "mediainfo": mediainfo.to_dict(), + }) # 返回结果 return sid, "" @@ -361,6 +367,11 @@ def update_subscribe_priority(self, subscribe: Subscribe, meta: MetaInfo, self.post_message(Notification(mtype=NotificationType.Subscribe, title=f'{mediainfo.title_year} {meta.season} 已洗版完成', image=mediainfo.get_message_image())) + # 发送事件 + EventManager().send_event(EventType.SubscribeComplete, { + "subscribe_id": subscribe.id, + "mediainfo": mediainfo.to_dict(), + }) else: # 正在洗版,更新资源优先级 logger.info(f'{mediainfo.title_year} 正在洗版,更新资源优先级为 {priority}') @@ -391,6 +402,11 @@ def finish_subscribe_or_not(self, subscribe: Subscribe, meta: MetaInfo, mediainf self.post_message(Notification(mtype=NotificationType.Subscribe, title=f'{mediainfo.title_year} {meta.season} 已完成订阅', image=mediainfo.get_message_image())) + # 发送事件 + EventManager().send_event(EventType.SubscribeComplete, { + "subscribe_id": subscribe.id, + "mediainfo": mediainfo.to_dict(), + }) elif downloads and meta.type == MediaType.TV: # 电视剧更新已下载集数 self.__update_subscribe_note(subscribe=subscribe, downloads=downloads) diff --git a/app/schemas/types.py b/app/schemas/types.py index 5044acb2b..cc28bf67e 100644 --- a/app/schemas/types.py +++ b/app/schemas/types.py @@ -14,34 +14,38 @@ class TorrentStatus(Enum): # 可监听事件 class EventType(Enum): - # 插件重载 + # 插件需要重载 PluginReload = "plugin.reload" # 插件动作 PluginAction = "plugin.action" # 执行命令 CommandExcute = "command.excute" - # 站点删除 + # 站点已删除 SiteDeleted = "site.deleted" - # Webhook消息 - WebhookMessage = "webhook.message" + # 站点已更新 + SiteUpdated = "site.updated" # 转移完成 TransferComplete = "transfer.complete" - # 添加下载 + # 下载已添加 DownloadAdded = "download.added" # 删除历史记录 HistoryDeleted = "history.deleted" # 删除下载源文件 DownloadFileDeleted = "downloadfile.deleted" - # 用户外来消息 + # 收到用户外来消息 UserMessage = "user.message" - # 通知消息 + # 收到Webhook消息 + WebhookMessage = "webhook.message" + # 发送消息通知 NoticeMessage = "notice.message" # 名称识别请求 NameRecognize = "name.recognize" # 名称识别结果 NameRecognizeResult = "name.recognize.result" - # 站点发生更新 - SiteUpdated = "site.updated" + # 订阅已添加 + SubscribeAdded = "subscribe.added" + # 订阅已完成 + SubscribeComplete = "subscribe.complete" # 系统配置Key字典