fix: Fixed the error occurring in live on and live off event of the encryption live room

This commit is contained in:
LWR
2023-05-30 00:52:20 +08:00
parent fd577a9684
commit b32737584c
+33 -3
View File
@@ -10,7 +10,7 @@ from pydantic import BaseModel, PrivateAttr
from .live import LiveDanmaku, LiveRoom from .live import LiveDanmaku, LiveRoom
from .model import PushTarget from .model import PushTarget
from .user import User from .user import User
from ..exception import LiveException from ..exception import LiveException, ResponseCodeException
from ..painter.DynamicPicGenerator import DynamicPicGenerator from ..painter.DynamicPicGenerator import DynamicPicGenerator
from ..utils import config, redis from ..utils import config, redis
from ..utils.network import request from ..utils.network import request
@@ -166,9 +166,19 @@ class Up(BaseModel):
""" """
logger.debug(f"{self.uname} (LIVE): {event}") logger.debug(f"{self.uname} (LIVE): {event}")
locked = False
room_info = {}
# 是否为真正开播 # 是否为真正开播
if "live_time" in event["data"]: if "live_time" in event["data"]:
try:
room_info = await self.__live_room.get_room_info() room_info = await self.__live_room.get_room_info()
except ResponseCodeException as ex:
if ex.code == 19002005:
locked = True
logger.warning(f"{self.uname} ({self.room_id}) 的直播间已加密")
if not locked:
self.uname = room_info["anchor_info"]["base_info"]["uname"] self.uname = room_info["anchor_info"]["base_info"]["uname"]
await redis.set_live_status(self.room_id, 1) await redis.set_live_status(self.room_id, 1)
@@ -185,14 +195,16 @@ class Up(BaseModel):
else: else:
logger.opt(colors=True).info(f"<magenta>[开播] {self.uname} ({self.room_id})</>") logger.opt(colors=True).info(f"<magenta>[开播] {self.uname} ({self.room_id})</>")
live_start_time = room_info["room_info"]["live_start_time"] live_start_time = room_info["room_info"]["live_start_time"] if not locked else int(time.time())
await redis.set_live_start_time(self.room_id, live_start_time)
if not locked:
fans_count = room_info["anchor_info"]["relation_info"]["attention"] fans_count = room_info["anchor_info"]["relation_info"]["attention"]
if room_info["anchor_info"]["medal_info"] is None: if room_info["anchor_info"]["medal_info"] is None:
fans_medal_count = 0 fans_medal_count = 0
else: else:
fans_medal_count = room_info["anchor_info"]["medal_info"]["fansclub"] fans_medal_count = room_info["anchor_info"]["medal_info"]["fansclub"]
guard_count = room_info["guard_info"]["count"] guard_count = room_info["guard_info"]["count"]
await redis.set_live_start_time(self.room_id, live_start_time)
await redis.set_fans_count(self.room_id, live_start_time, fans_count) await redis.set_fans_count(self.room_id, live_start_time, fans_count)
await redis.set_fans_medal_count(self.room_id, live_start_time, fans_medal_count) await redis.set_fans_medal_count(self.room_id, live_start_time, fans_medal_count)
await redis.set_guard_count(self.room_id, live_start_time, guard_count) await redis.set_guard_count(self.room_id, live_start_time, guard_count)
@@ -200,6 +212,7 @@ class Up(BaseModel):
await self.accumulate_and_reset_data() await self.accumulate_and_reset_data()
# 推送开播消息 # 推送开播消息
if not locked:
arg_base = room_info["room_info"] arg_base = room_info["room_info"]
args = { args = {
"{uname}": self.uname, "{uname}": self.uname,
@@ -207,6 +220,14 @@ class Up(BaseModel):
"{url}": f"https://live.bilibili.com/{self.room_id}", "{url}": f"https://live.bilibili.com/{self.room_id}",
"{cover}": "".join(["{urlpic=", arg_base["cover"], "}"]) "{cover}": "".join(["{urlpic=", arg_base["cover"], "}"])
} }
else:
args = {
"{uname}": self.uname,
"{title}": "加密直播间",
"{url}": f"https://live.bilibili.com/{self.room_id}",
"{cover}": ""
}
await self.__bot.send_live_on(self, args) await self.__bot.send_live_on(self, args)
await self.__bot.send_live_on_at(self) await self.__bot.send_live_on_at(self)
@@ -431,10 +452,19 @@ class Up(BaseModel):
"second": second "second": second
}) })
locked = False
room_info = {}
# 基础数据变动 # 基础数据变动
if self.__any_live_report_item_enabled(["fans_change", "fans_medal_change", "guard_change"]): if self.__any_live_report_item_enabled(["fans_change", "fans_medal_change", "guard_change"]):
try:
room_info = await self.__live_room.get_room_info() room_info = await self.__live_room.get_room_info()
except ResponseCodeException as ex:
if ex.code == 19002005:
locked = True
logger.warning(f"{self.uname} ({self.room_id}) 的直播间已加密")
if not locked:
if await redis.exists_fans_count(self.room_id, start_time): if await redis.exists_fans_count(self.room_id, start_time):
fans_count = await redis.get_fans_count(self.room_id, start_time) fans_count = await redis.get_fans_count(self.room_id, start_time)
else: else: