fix: Fixed dynamic push lost when live room is not exists
This commit is contained in:
@@ -61,4 +61,4 @@ async def dynamic_spider(datasource: DataSource):
|
|||||||
except DataSourceException:
|
except DataSourceException:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
up.dispatch("DYNAMIC_UPDATE", detail)
|
asyncio.create_task(up.dynamic_update(detail))
|
||||||
|
|||||||
+24
-28
@@ -70,9 +70,6 @@ class Up(BaseModel):
|
|||||||
def inject_bot(self, bot):
|
def inject_bot(self, bot):
|
||||||
self.__bot = bot
|
self.__bot = bot
|
||||||
|
|
||||||
def dispatch(self, name, data):
|
|
||||||
self.__room.dispatch(name, data)
|
|
||||||
|
|
||||||
async def accumulate_and_reset_data(self):
|
async def accumulate_and_reset_data(self):
|
||||||
await redis.accumulate_data(self.room_id)
|
await redis.accumulate_data(self.room_id)
|
||||||
await redis.reset_data(self.room_id)
|
await redis.reset_data(self.room_id)
|
||||||
@@ -340,8 +337,30 @@ class Up(BaseModel):
|
|||||||
|
|
||||||
await redis.incr_room_guard_time(self.room_id, int(time.time()), month)
|
await redis.incr_room_guard_time(self.room_id, int(time.time()), month)
|
||||||
|
|
||||||
@self.__room.on("DYNAMIC_UPDATE")
|
async def disconnect(self):
|
||||||
async def dynamic_update(event):
|
"""
|
||||||
|
断开连接直播间
|
||||||
|
"""
|
||||||
|
if self.__room is not None and self.__room.get_status() == 2:
|
||||||
|
await self.__room.disconnect()
|
||||||
|
self.__is_reconnect = False
|
||||||
|
logger.success(f"已断开连接 {self.uname} 的直播间 {self.room_id}")
|
||||||
|
|
||||||
|
await self.accumulate_and_reset_data()
|
||||||
|
|
||||||
|
async def auto_reload_connect(self):
|
||||||
|
"""
|
||||||
|
自动判断仅连接必要的直播间开启时,重载配置时自动处理直播间连接状态
|
||||||
|
"""
|
||||||
|
if config.get("ONLY_CONNECT_NECESSARY_ROOM"):
|
||||||
|
if any([self.__any_live_on_enabled(), self.__any_live_off_enabled(), self.__any_live_report_enabled()]):
|
||||||
|
if self.__room is None or self.__room.get_status() != 2:
|
||||||
|
await self.connect()
|
||||||
|
else:
|
||||||
|
if self.__room is not None and self.__room.get_status() == 2:
|
||||||
|
await self.disconnect()
|
||||||
|
|
||||||
|
async def dynamic_update(self, event):
|
||||||
"""
|
"""
|
||||||
动态更新事件
|
动态更新事件
|
||||||
"""
|
"""
|
||||||
@@ -382,29 +401,6 @@ class Up(BaseModel):
|
|||||||
await self.__bot.send_dynamic_at(self)
|
await self.__bot.send_dynamic_at(self)
|
||||||
await self.__bot.send_dynamic_update(self, dynamic_update_args)
|
await self.__bot.send_dynamic_update(self, dynamic_update_args)
|
||||||
|
|
||||||
async def disconnect(self):
|
|
||||||
"""
|
|
||||||
断开连接直播间
|
|
||||||
"""
|
|
||||||
if self.__room is not None and self.__room.get_status() == 2:
|
|
||||||
await self.__room.disconnect()
|
|
||||||
self.__is_reconnect = False
|
|
||||||
logger.success(f"已断开连接 {self.uname} 的直播间 {self.room_id}")
|
|
||||||
|
|
||||||
await self.accumulate_and_reset_data()
|
|
||||||
|
|
||||||
async def auto_reload_connect(self):
|
|
||||||
"""
|
|
||||||
自动判断仅连接必要的直播间开启时,重载配置时自动处理直播间连接状态
|
|
||||||
"""
|
|
||||||
if config.get("ONLY_CONNECT_NECESSARY_ROOM"):
|
|
||||||
if any([self.__any_live_on_enabled(), self.__any_live_off_enabled(), self.__any_live_report_enabled()]):
|
|
||||||
if self.__room is None or self.__room.get_status() != 2:
|
|
||||||
await self.connect()
|
|
||||||
else:
|
|
||||||
if self.__room is not None and self.__room.get_status() == 2:
|
|
||||||
await self.disconnect()
|
|
||||||
|
|
||||||
async def __generate_live_report_param(self):
|
async def __generate_live_report_param(self):
|
||||||
"""
|
"""
|
||||||
计算直播报告所需数据
|
计算直播报告所需数据
|
||||||
|
|||||||
Reference in New Issue
Block a user