fix: Fixed dynamic push lost when live room is not exists
This commit is contained in:
parent
a37c737310
commit
7ce1514a5a
@ -61,4 +61,4 @@ async def dynamic_spider(datasource: DataSource):
|
||||
except DataSourceException:
|
||||
continue
|
||||
|
||||
up.dispatch("DYNAMIC_UPDATE", detail)
|
||||
asyncio.create_task(up.dynamic_update(detail))
|
||||
|
@ -70,9 +70,6 @@ class Up(BaseModel):
|
||||
def inject_bot(self, bot):
|
||||
self.__bot = bot
|
||||
|
||||
def dispatch(self, name, data):
|
||||
self.__room.dispatch(name, data)
|
||||
|
||||
async def accumulate_and_reset_data(self):
|
||||
await redis.accumulate_data(self.room_id)
|
||||
await redis.reset_data(self.room_id)
|
||||
@ -340,48 +337,6 @@ class Up(BaseModel):
|
||||
|
||||
await redis.incr_room_guard_time(self.room_id, int(time.time()), month)
|
||||
|
||||
@self.__room.on("DYNAMIC_UPDATE")
|
||||
async def dynamic_update(event):
|
||||
"""
|
||||
动态更新事件
|
||||
"""
|
||||
logger.debug(f"{self.uname} (DYNAMIC_UPDATE): {event}")
|
||||
|
||||
dynamic_id = event["desc"]["dynamic_id"]
|
||||
dynamic_type = event["desc"]["type"]
|
||||
bvid = event['desc']['bvid'] if dynamic_type == 8 else ""
|
||||
rid = event['desc']['rid'] if dynamic_type in (64, 256) else ""
|
||||
|
||||
action_map = {
|
||||
1: "转发了动态",
|
||||
2: "发表了新动态",
|
||||
4: "发表了新动态",
|
||||
8: "投稿了新视频",
|
||||
64: "投稿了新专栏",
|
||||
256: "投稿了新音频",
|
||||
2048: "发表了新动态"
|
||||
}
|
||||
url_map = {
|
||||
1: f"https://t.bilibili.com/{dynamic_id}",
|
||||
2: f"https://t.bilibili.com/{dynamic_id}",
|
||||
4: f"https://t.bilibili.com/{dynamic_id}",
|
||||
8: f"https://www.bilibili.com/video/{bvid}",
|
||||
64: f"https://www.bilibili.com/read/cv{rid}",
|
||||
256: f"https://www.bilibili.com/audio/au{rid}",
|
||||
2048: f"https://t.bilibili.com/{dynamic_id}"
|
||||
}
|
||||
base64str = await DynamicPicGenerator.generate(event)
|
||||
|
||||
# 推送动态消息
|
||||
dynamic_update_args = {
|
||||
"{uname}": self.uname,
|
||||
"{action}": action_map.get(dynamic_type, "发表了新动态"),
|
||||
"{url}": url_map.get(dynamic_type, f"https://t.bilibili.com/{dynamic_id}"),
|
||||
"{picture}": "".join(["{base64pic=", base64str, "}"])
|
||||
}
|
||||
await self.__bot.send_dynamic_at(self)
|
||||
await self.__bot.send_dynamic_update(self, dynamic_update_args)
|
||||
|
||||
async def disconnect(self):
|
||||
"""
|
||||
断开连接直播间
|
||||
@ -405,6 +360,47 @@ class Up(BaseModel):
|
||||
if self.__room is not None and self.__room.get_status() == 2:
|
||||
await self.disconnect()
|
||||
|
||||
async def dynamic_update(self, event):
|
||||
"""
|
||||
动态更新事件
|
||||
"""
|
||||
logger.debug(f"{self.uname} (DYNAMIC_UPDATE): {event}")
|
||||
|
||||
dynamic_id = event["desc"]["dynamic_id"]
|
||||
dynamic_type = event["desc"]["type"]
|
||||
bvid = event['desc']['bvid'] if dynamic_type == 8 else ""
|
||||
rid = event['desc']['rid'] if dynamic_type in (64, 256) else ""
|
||||
|
||||
action_map = {
|
||||
1: "转发了动态",
|
||||
2: "发表了新动态",
|
||||
4: "发表了新动态",
|
||||
8: "投稿了新视频",
|
||||
64: "投稿了新专栏",
|
||||
256: "投稿了新音频",
|
||||
2048: "发表了新动态"
|
||||
}
|
||||
url_map = {
|
||||
1: f"https://t.bilibili.com/{dynamic_id}",
|
||||
2: f"https://t.bilibili.com/{dynamic_id}",
|
||||
4: f"https://t.bilibili.com/{dynamic_id}",
|
||||
8: f"https://www.bilibili.com/video/{bvid}",
|
||||
64: f"https://www.bilibili.com/read/cv{rid}",
|
||||
256: f"https://www.bilibili.com/audio/au{rid}",
|
||||
2048: f"https://t.bilibili.com/{dynamic_id}"
|
||||
}
|
||||
base64str = await DynamicPicGenerator.generate(event)
|
||||
|
||||
# 推送动态消息
|
||||
dynamic_update_args = {
|
||||
"{uname}": self.uname,
|
||||
"{action}": action_map.get(dynamic_type, "发表了新动态"),
|
||||
"{url}": url_map.get(dynamic_type, f"https://t.bilibili.com/{dynamic_id}"),
|
||||
"{picture}": "".join(["{base64pic=", base64str, "}"])
|
||||
}
|
||||
await self.__bot.send_dynamic_at(self)
|
||||
await self.__bot.send_dynamic_update(self, dynamic_update_args)
|
||||
|
||||
async def __generate_live_report_param(self):
|
||||
"""
|
||||
计算直播报告所需数据
|
||||
|
Loading…
x
Reference in New Issue
Block a user