From ef67b76453d3e326f0f421f83223224dc8260271 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Fri, 22 Mar 2024 13:26:07 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=B8=8B=E8=BD=BD=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E7=94=A8=E6=88=B7=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/endpoints/download.py | 4 ++-- app/chain/download.py | 20 ++++++++++++++------ app/chain/message.py | 10 +++++----- app/chain/subscribe.py | 4 ++-- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/app/api/endpoints/download.py b/app/api/endpoints/download.py index c27befce..b2545226 100644 --- a/app/api/endpoints/download.py +++ b/app/api/endpoints/download.py @@ -45,7 +45,7 @@ def download( media_info=mediainfo, torrent_info=torrentinfo ) - did = DownloadChain().download_single(context=context, userid=current_user.name, username=current_user.name) + did = DownloadChain().download_single(context=context, username=current_user.name) return schemas.Response(success=True if did else False, data={ "download_id": did }) @@ -73,7 +73,7 @@ def add( media_info=mediainfo, torrent_info=torrentinfo ) - did = DownloadChain().download_single(context=context, userid=current_user.name, username=current_user.name) + did = DownloadChain().download_single(context=context, username=current_user.name) return schemas.Response(success=True if did else False, data={ "download_id": did }) diff --git a/app/chain/download.py b/app/chain/download.py index 061b0b6b..1340ddaa 100644 --- a/app/chain/download.py +++ b/app/chain/download.py @@ -34,14 +34,19 @@ class DownloadChain(ChainBase): self.mediaserver = MediaServerOper() def post_download_message(self, meta: MetaBase, mediainfo: MediaInfo, torrent: TorrentInfo, - channel: MessageChannel = None, - userid: str = None): + channel: MessageChannel = None, userid: str = None, username: str = None): """ 发送添加下载的消息 + :param meta: 元数据 + :param mediainfo: 媒体信息 + :param torrent: 种子信息 + :param channel: 通知渠道 + :param userid: 用户ID,指定时精确发送对应用户 + :param username: 通知显示的下载用户信息 """ msg_text = "" - if userid: - msg_text = f"用户:{userid}" + if username: + msg_text = f"用户:{username}" if torrent.site_name: msg_text = f"{msg_text}\n站点:{torrent.site_name}" if meta.resource_term: @@ -73,6 +78,7 @@ class DownloadChain(ChainBase): self.post_message(Notification( channel=channel, mtype=NotificationType.Download, + userid=userid, title=f"{mediainfo.title_year} " f"{meta.season_episode} 开始下载", text=msg_text, @@ -302,18 +308,20 @@ class DownloadChain(ChainBase): self.downloadhis.add_files(files_to_add) # 发送消息(群发,不带channel和userid) - self.post_download_message(meta=_meta, mediainfo=_media, torrent=_torrent) + self.post_download_message(meta=_meta, mediainfo=_media, torrent=_torrent, username=username) # 下载成功后处理 self.download_added(context=context, download_dir=download_dir, torrent_path=torrent_file) # 广播事件 self.eventmanager.send_event(EventType.DownloadAdded, { "hash": _hash, - "context": context + "context": context, + "username": username }) else: # 下载失败 logger.error(f"{_media.title_year} 添加下载任务失败:" f"{_torrent.title} - {_torrent.enclosure},{error_msg}") + # 只发送给对应渠道和用户 self.post_message(Notification( channel=channel, mtype=NotificationType.Manual, diff --git a/app/chain/message.py b/app/chain/message.py index 85358249..24a2857f 100644 --- a/app/chain/message.py +++ b/app/chain/message.py @@ -115,7 +115,7 @@ class MessageChain(ChainBase): # 用户ID userid = info.userid # 用户名 - username = info.username + username = info.username or userid if not userid: logger.debug(f'未识别到用户ID:{body}{form}{args}') return @@ -192,8 +192,8 @@ class MessageChain(ChainBase): # 媒体库中已存在 self.post_message( Notification(channel=channel, - title=f"{_current_media.title_year}" - f"{_current_meta.sea} 媒体库中已存在,如需重新下载请发送:搜索 XXX 或 下载 XXX", + title=f"【{_current_media.title_year}" + f"{_current_meta.sea} 媒体库中已存在,如需重新下载请发送:搜索 名称 或 下载 名称】", userid=userid)) return elif exist_flag: @@ -274,8 +274,8 @@ class MessageChain(ChainBase): if exist_flag: self.post_message(Notification( channel=channel, - title=f"{mediainfo.title_year}" - f"{_current_meta.sea} 媒体库中已存在,如需洗版请发送:洗版 XXX", + title=f"【{mediainfo.title_year}" + f"{_current_meta.sea} 媒体库中已存在,如需洗版请发送:洗版 XXX】", userid=userid)) return else: diff --git a/app/chain/subscribe.py b/app/chain/subscribe.py index 575b8ef0..5aa86c08 100644 --- a/app/chain/subscribe.py +++ b/app/chain/subscribe.py @@ -143,8 +143,8 @@ class SubscribeChain(ChainBase): userid=userid)) elif message: logger.info(f'{mediainfo.title_year} {metainfo.season} 添加订阅成功') - if username or userid: - text = f"评分:{mediainfo.vote_average},来自用户:{username or userid}" + if username: + text = f"评分:{mediainfo.vote_average},来自用户:{username}" else: text = f"评分:{mediainfo.vote_average}" # 群发