mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
b站订阅直播订阅支持短号
This commit is contained in:
parent
9e962bd0d1
commit
c0ec2e7856
@ -226,18 +226,18 @@ async def _():
|
|||||||
bot = get_bot()
|
bot = get_bot()
|
||||||
sub = None
|
sub = None
|
||||||
if bot:
|
if bot:
|
||||||
try:
|
# try:
|
||||||
await sub_manager.reload_sub_data()
|
await sub_manager.reload_sub_data()
|
||||||
sub = await sub_manager.random_sub_data()
|
sub = await sub_manager.random_sub_data()
|
||||||
if sub:
|
if sub:
|
||||||
logger.debug(f"Bilibili订阅开始检测:{sub.sub_id}")
|
logger.debug(f"Bilibili订阅开始检测:{sub.sub_id}")
|
||||||
rst = await get_sub_status(sub.sub_id, sub.sub_type)
|
rst = await get_sub_status(sub.sub_id, sub.sub_type)
|
||||||
|
await send_sub_msg(rst, sub, bot)
|
||||||
|
if sub.sub_type == "live":
|
||||||
|
rst = await get_sub_status(sub.sub_id, "up")
|
||||||
await send_sub_msg(rst, sub, bot)
|
await send_sub_msg(rst, sub, bot)
|
||||||
if sub.sub_type == "live":
|
# except Exception as e:
|
||||||
rst = await get_sub_status(sub.uid, "up")
|
# logger.error(f"B站订阅推送发生错误 sub_id:{sub.sub_id if sub else 0} {type(e)}:{e}")
|
||||||
await send_sub_msg(rst, sub, bot)
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"B站订阅推送发生错误 sub_id:{sub.sub_id if sub else 0} {type(e)}:{e}")
|
|
||||||
|
|
||||||
|
|
||||||
async def send_sub_msg(rst: str, sub: BilibiliSub, bot: Bot):
|
async def send_sub_msg(rst: str, sub: BilibiliSub, bot: Bot):
|
||||||
|
|||||||
@ -38,39 +38,38 @@ async def add_live_sub(live_id: int, sub_user: str) -> str:
|
|||||||
:param sub_user: 订阅用户 id # 7384933:private or 7384933:2342344(group)
|
:param sub_user: 订阅用户 id # 7384933:private or 7384933:2342344(group)
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
# try:
|
|
||||||
try:
|
try:
|
||||||
"""bilibili_api.live库的LiveRoom类中get_room_info改为bilireq.live库的get_room_info_by_id方法"""
|
try:
|
||||||
live_info = await get_room_info_by_id(live_id)
|
"""bilibili_api.live库的LiveRoom类中get_room_info改为bilireq.live库的get_room_info_by_id方法"""
|
||||||
except ResponseCodeError:
|
live_info = await get_room_info_by_id(live_id)
|
||||||
return f"未找到房间号Id:{live_id} 的信息,请检查Id是否正确"
|
except ResponseCodeError:
|
||||||
uid = live_info["uid"]
|
return f"未找到房间号Id:{live_id} 的信息,请检查Id是否正确"
|
||||||
room_id = live_info["room_id"]
|
uid = live_info["uid"]
|
||||||
short_id = live_info["short_id"]
|
room_id = live_info["room_id"]
|
||||||
title = live_info["title"]
|
short_id = live_info["short_id"]
|
||||||
live_status = live_info["live_status"]
|
title = live_info["title"]
|
||||||
await BilibiliSub.add_bilibili_sub(
|
live_status = live_info["live_status"]
|
||||||
room_id,
|
if await BilibiliSub.add_bilibili_sub(
|
||||||
"live",
|
room_id,
|
||||||
sub_user,
|
"live",
|
||||||
uid=uid,
|
sub_user,
|
||||||
live_short_id=short_id,
|
uid=uid,
|
||||||
live_status=live_status,
|
live_short_id=short_id,
|
||||||
)
|
live_status=live_status,
|
||||||
# await _get_up_status(live_id)
|
):
|
||||||
uname = (await BilibiliSub.get_sub(live_id)).uname
|
await _get_up_status(room_id)
|
||||||
# uname = 1
|
uname = (await BilibiliSub.get_sub(room_id)).uname
|
||||||
return (
|
return (
|
||||||
"已成功订阅主播:\n"
|
"已成功订阅主播:\n"
|
||||||
f"\ttitle:{title}\n"
|
f"\ttitle:{title}\n"
|
||||||
f"\tname: {uname}\n"
|
f"\tname: {uname}\n"
|
||||||
f"\tlive_id:{live_id}\n"
|
f"\tlive_id:{room_id}\n"
|
||||||
f"\tuid:{uid}"
|
f"\tuid:{uid}"
|
||||||
)
|
)
|
||||||
# else:
|
else:
|
||||||
# return "添加订阅失败..."
|
return "添加订阅失败..."
|
||||||
# except Exception as e:
|
except Exception as e:
|
||||||
# logger.error(f"订阅主播live_id:{live_id} 发生了错误 {type(e)}:{e}")
|
logger.error(f"订阅主播live_id:{live_id} 发生了错误 {type(e)}:{e}")
|
||||||
return "添加订阅失败..."
|
return "添加订阅失败..."
|
||||||
|
|
||||||
|
|
||||||
@ -251,13 +250,13 @@ async def _get_up_status(id_: int) -> Optional[str]:
|
|||||||
user_info = await get_user_info(_user.uid)
|
user_info = await get_user_info(_user.uid)
|
||||||
uname = user_info["name"]
|
uname = user_info["name"]
|
||||||
"""bilibili_api.user库中User类的get_videos改为bilireq.user库的get_videos方法"""
|
"""bilibili_api.user库中User类的get_videos改为bilireq.user库的get_videos方法"""
|
||||||
video_info = await get_videos(id_)
|
video_info = await get_videos(_user.uid)
|
||||||
latest_video_created = 0
|
latest_video_created = 0
|
||||||
video = None
|
video = None
|
||||||
dividing_line = "\n-------------\n"
|
dividing_line = "\n-------------\n"
|
||||||
if _user.uname != uname:
|
if _user.uname != uname:
|
||||||
await BilibiliSub.update_sub_info(id_, uname=uname)
|
await BilibiliSub.update_sub_info(id_, uname=uname)
|
||||||
dynamic_img, dynamic_upload_time, link = await get_user_dynamic(id_, _user)
|
dynamic_img, dynamic_upload_time, link = await get_user_dynamic(_user.uid, _user)
|
||||||
if video_info["list"].get("vlist"):
|
if video_info["list"].get("vlist"):
|
||||||
video = video_info["list"]["vlist"][0]
|
video = video_info["list"]["vlist"][0]
|
||||||
latest_video_created = video["created"]
|
latest_video_created = video["created"]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user