fix: Fixed the issue where the obtained danmu data was incorrect due to bilibili new anti-spam policy
This commit is contained in:
@@ -205,10 +205,26 @@ class StarBot:
|
|||||||
if len(need_follow_uids) > 0:
|
if len(need_follow_uids) > 0:
|
||||||
asyncio.create_task(follow_task(need_follow_uids))
|
asyncio.create_task(follow_task(need_follow_uids))
|
||||||
|
|
||||||
|
# 检测 UID 配置完整性
|
||||||
|
if config.get("ACCOUNT_UID") is None:
|
||||||
|
logger.warning("未填写 ACCOUNT_UID 配置项, 受 B 站风控影响, 将无法获取弹幕相关数据, 请使用 config.set('ACCOUNT_UID', 您的UID) 设置")
|
||||||
|
|
||||||
# 检测消息补发配置完整性
|
# 检测消息补发配置完整性
|
||||||
if config.get("BAN_RESEND") and config.get("MASTER_QQ") is None:
|
if config.get("BAN_RESEND") and config.get("MASTER_QQ") is None:
|
||||||
logger.warning("检测到风控消息补发功能已开启, 但未配置机器人主人 QQ, 将会导致 \"补发\" 命令无法使用, 请使用 config.set(\"MASTER_QQ\", QQ号) 进行配置")
|
logger.warning("检测到风控消息补发功能已开启, 但未配置机器人主人 QQ, 将会导致 \"补发\" 命令无法使用, 请使用 config.set(\"MASTER_QQ\", QQ号) 进行配置")
|
||||||
|
|
||||||
|
# 受 B 站新风控机制影响,取到了 UID 为 0 的弹幕数据,自动删除掉这一批污染数据
|
||||||
|
for key in await redis.keys("UserDanmuCount:*"):
|
||||||
|
room_id = key.split(":")[1]
|
||||||
|
count = int(await redis.zscore(key, 0))
|
||||||
|
await redis.zrem(key, 0)
|
||||||
|
await redis.hincrby("RoomDanmuCount", room_id, -count)
|
||||||
|
for key in await redis.keys("UserDanmuTotal:*"):
|
||||||
|
room_id = key.split(":")[1]
|
||||||
|
count = int(await redis.zscore(key, 0))
|
||||||
|
await redis.zrem(key, 0)
|
||||||
|
await redis.hincrby("RoomDanmuTotal", room_id, -count)
|
||||||
|
|
||||||
# 启动消息推送模块
|
# 启动消息推送模块
|
||||||
Ariadne.options["default_account"] = self.__datasource.bots[0].qq
|
Ariadne.options["default_account"] = self.__datasource.bots[0].qq
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ from aiohttp.client_ws import ClientWebSocketResponse
|
|||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
from ..exception.LiveException import LiveException
|
from ..exception.LiveException import LiveException
|
||||||
|
from ..utils import config
|
||||||
from ..utils.AsyncEvent import AsyncEvent
|
from ..utils.AsyncEvent import AsyncEvent
|
||||||
from ..utils.Credential import Credential
|
from ..utils.Credential import Credential
|
||||||
from ..utils.Danmaku import Danmaku
|
from ..utils.Danmaku import Danmaku
|
||||||
@@ -810,7 +811,10 @@ class LiveDanmaku(AsyncEvent):
|
|||||||
logger.warning(f"直播间 {self.room_display_id} 检测到未知的数据包类型, 无法处理")
|
logger.warning(f"直播间 {self.room_display_id} 检测到未知的数据包类型, 无法处理")
|
||||||
|
|
||||||
async def __send_verify_data(self, ws: ClientWebSocketResponse, token: str):
|
async def __send_verify_data(self, ws: ClientWebSocketResponse, token: str):
|
||||||
verify_data = {"uid": 0, "roomid": self.__room_real_id,
|
uid = config.get("ACCOUNT_UID")
|
||||||
|
if uid is None:
|
||||||
|
uid = 0
|
||||||
|
verify_data = {"uid": uid, "roomid": self.__room_real_id,
|
||||||
"protover": 3, "platform": "web", "type": 2, "key": token}
|
"protover": 3, "platform": "web", "type": 2, "key": token}
|
||||||
data = json.dumps(verify_data).encode()
|
data = json.dumps(verify_data).encode()
|
||||||
await self.__send(data, self.PROTOCOL_VERSION_HEARTBEAT, self.DATAPACK_TYPE_VERIFY, ws)
|
await self.__send(data, self.PROTOCOL_VERSION_HEARTBEAT, self.DATAPACK_TYPE_VERIFY, ws)
|
||||||
|
|||||||
@@ -279,7 +279,8 @@ class Up(BaseModel):
|
|||||||
|
|
||||||
# 弹幕统计
|
# 弹幕统计
|
||||||
await redis.incr_room_danmu_count(self.room_id)
|
await redis.incr_room_danmu_count(self.room_id)
|
||||||
await redis.incr_user_danmu_count(self.room_id, uid)
|
if uid != 0:
|
||||||
|
await redis.incr_user_danmu_count(self.room_id, uid)
|
||||||
|
|
||||||
# 弹幕词云所需弹幕记录
|
# 弹幕词云所需弹幕记录
|
||||||
if isinstance(base[0][13], str):
|
if isinstance(base[0][13], str):
|
||||||
|
|||||||
+11
-1
@@ -25,7 +25,7 @@ async def init():
|
|||||||
logger.success("成功连接 Redis 数据库")
|
logger.success("成功连接 Redis 数据库")
|
||||||
|
|
||||||
|
|
||||||
# String
|
# Key
|
||||||
|
|
||||||
async def expire(key: str, seconds: int):
|
async def expire(key: str, seconds: int):
|
||||||
await __redis.expire(key, seconds)
|
await __redis.expire(key, seconds)
|
||||||
@@ -35,6 +35,12 @@ async def exists(key: str) -> bool:
|
|||||||
return bool(await __redis.exists(key))
|
return bool(await __redis.exists(key))
|
||||||
|
|
||||||
|
|
||||||
|
async def keys(pattern: str) -> List[str]:
|
||||||
|
return [x.decode() for x in await __redis.keys(pattern)]
|
||||||
|
|
||||||
|
|
||||||
|
# String
|
||||||
|
|
||||||
async def get(key: str) -> str:
|
async def get(key: str) -> str:
|
||||||
result = await __redis.get(key)
|
result = await __redis.get(key)
|
||||||
if result is None:
|
if result is None:
|
||||||
@@ -214,6 +220,10 @@ async def zunionstore(dest: str, source: Union[str, List[str]]):
|
|||||||
await __redis.zunionstore(dest, source)
|
await __redis.zunionstore(dest, source)
|
||||||
|
|
||||||
|
|
||||||
|
async def zrem(key: str, member: Union[str, int]):
|
||||||
|
await __redis.zrem(key, member)
|
||||||
|
|
||||||
|
|
||||||
# StarBot
|
# StarBot
|
||||||
|
|
||||||
# 直播间状态,0:未开播,1:正在直播,2:轮播
|
# 直播间状态,0:未开播,1:正在直播,2:轮播
|
||||||
|
|||||||
Reference in New Issue
Block a user