fix 下载消息显示用户名

This commit is contained in:
jxxghp 2024-03-22 13:26:07 +08:00
parent c4e7870f7b
commit ef67b76453
4 changed files with 23 additions and 15 deletions

View File

@ -45,7 +45,7 @@ def download(
media_info=mediainfo, media_info=mediainfo,
torrent_info=torrentinfo 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={ return schemas.Response(success=True if did else False, data={
"download_id": did "download_id": did
}) })
@ -73,7 +73,7 @@ def add(
media_info=mediainfo, media_info=mediainfo,
torrent_info=torrentinfo 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={ return schemas.Response(success=True if did else False, data={
"download_id": did "download_id": did
}) })

View File

@ -34,14 +34,19 @@ class DownloadChain(ChainBase):
self.mediaserver = MediaServerOper() self.mediaserver = MediaServerOper()
def post_download_message(self, meta: MetaBase, mediainfo: MediaInfo, torrent: TorrentInfo, def post_download_message(self, meta: MetaBase, mediainfo: MediaInfo, torrent: TorrentInfo,
channel: MessageChannel = None, channel: MessageChannel = None, userid: str = None, username: str = None):
userid: str = None):
""" """
发送添加下载的消息 发送添加下载的消息
:param meta: 元数据
:param mediainfo: 媒体信息
:param torrent: 种子信息
:param channel: 通知渠道
:param userid: 用户ID指定时精确发送对应用户
:param username: 通知显示的下载用户信息
""" """
msg_text = "" msg_text = ""
if userid: if username:
msg_text = f"用户:{userid}" msg_text = f"用户:{username}"
if torrent.site_name: if torrent.site_name:
msg_text = f"{msg_text}\n站点:{torrent.site_name}" msg_text = f"{msg_text}\n站点:{torrent.site_name}"
if meta.resource_term: if meta.resource_term:
@ -73,6 +78,7 @@ class DownloadChain(ChainBase):
self.post_message(Notification( self.post_message(Notification(
channel=channel, channel=channel,
mtype=NotificationType.Download, mtype=NotificationType.Download,
userid=userid,
title=f"{mediainfo.title_year} " title=f"{mediainfo.title_year} "
f"{meta.season_episode} 开始下载", f"{meta.season_episode} 开始下载",
text=msg_text, text=msg_text,
@ -302,18 +308,20 @@ class DownloadChain(ChainBase):
self.downloadhis.add_files(files_to_add) self.downloadhis.add_files(files_to_add)
# 发送消息群发不带channel和userid # 发送消息群发不带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.download_added(context=context, download_dir=download_dir, torrent_path=torrent_file)
# 广播事件 # 广播事件
self.eventmanager.send_event(EventType.DownloadAdded, { self.eventmanager.send_event(EventType.DownloadAdded, {
"hash": _hash, "hash": _hash,
"context": context "context": context,
"username": username
}) })
else: else:
# 下载失败 # 下载失败
logger.error(f"{_media.title_year} 添加下载任务失败:" logger.error(f"{_media.title_year} 添加下载任务失败:"
f"{_torrent.title} - {_torrent.enclosure}{error_msg}") f"{_torrent.title} - {_torrent.enclosure}{error_msg}")
# 只发送给对应渠道和用户
self.post_message(Notification( self.post_message(Notification(
channel=channel, channel=channel,
mtype=NotificationType.Manual, mtype=NotificationType.Manual,

View File

@ -115,7 +115,7 @@ class MessageChain(ChainBase):
# 用户ID # 用户ID
userid = info.userid userid = info.userid
# 用户名 # 用户名
username = info.username username = info.username or userid
if not userid: if not userid:
logger.debug(f'未识别到用户ID{body}{form}{args}') logger.debug(f'未识别到用户ID{body}{form}{args}')
return return
@ -192,8 +192,8 @@ class MessageChain(ChainBase):
# 媒体库中已存在 # 媒体库中已存在
self.post_message( self.post_message(
Notification(channel=channel, Notification(channel=channel,
title=f"{_current_media.title_year}" title=f"{_current_media.title_year}"
f"{_current_meta.sea} 媒体库中已存在,如需重新下载请发送:搜索 XXX 或 下载 XXX", f"{_current_meta.sea} 媒体库中已存在,如需重新下载请发送:搜索 名称 或 下载 名称】",
userid=userid)) userid=userid))
return return
elif exist_flag: elif exist_flag:
@ -274,8 +274,8 @@ class MessageChain(ChainBase):
if exist_flag: if exist_flag:
self.post_message(Notification( self.post_message(Notification(
channel=channel, channel=channel,
title=f"{mediainfo.title_year}" title=f"{mediainfo.title_year}"
f"{_current_meta.sea} 媒体库中已存在,如需洗版请发送:洗版 XXX", f"{_current_meta.sea} 媒体库中已存在,如需洗版请发送:洗版 XXX",
userid=userid)) userid=userid))
return return
else: else:

View File

@ -143,8 +143,8 @@ class SubscribeChain(ChainBase):
userid=userid)) userid=userid))
elif message: elif message:
logger.info(f'{mediainfo.title_year} {metainfo.season} 添加订阅成功') logger.info(f'{mediainfo.title_year} {metainfo.season} 添加订阅成功')
if username or userid: if username:
text = f"评分:{mediainfo.vote_average},来自用户:{username or userid}" text = f"评分:{mediainfo.vote_average},来自用户:{username}"
else: else:
text = f"评分:{mediainfo.vote_average}" text = f"评分:{mediainfo.vote_average}"
# 群发 # 群发