Skip to content

Commit

Permalink
feat:新增订阅相关事件
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp committed Mar 30, 2024
1 parent 5ee41b8 commit 536bd92
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
18 changes: 17 additions & 1 deletion app/chain/subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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, ""

Expand Down Expand Up @@ -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}')
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 13 additions & 9 deletions app/schemas/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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字典
Expand Down

0 comments on commit 536bd92

Please sign in to comment.