mirror of
https://github.com/yulinfeng000/blive.git
synced 2024-12-25 20:30:12 +08:00
将心跳包人气值数据模拟成一个事件进行处理
This commit is contained in:
parent
3cab5a65c4
commit
0fdb1d47ff
@ -144,8 +144,10 @@ class BLiveMsgPackage:
|
||||
|
||||
# 心跳包处理
|
||||
if header.operation == Operation.HEARTBEAT_REPLY:
|
||||
# 心跳不会粘包,前4位有不明含义的数据
|
||||
packages.append((header, data[4:].decode("utf-8")))
|
||||
popularity = struct.unpack("!I", data[:4])[0]
|
||||
payload = data[4:].decode("utf-8")
|
||||
plain_text = "{"+"\"cmd\":\"HEARTBEAT_REPLY\",\"popularity\":{},\"payload\":{}".format(popularity,payload)+"}"
|
||||
packages.append((header, plain_text))
|
||||
|
||||
# 通知包处理
|
||||
elif header.operation == Operation.NOTIFY:
|
||||
@ -178,6 +180,7 @@ packman = BLiveMsgPackage()
|
||||
|
||||
|
||||
class Events(str, enum.Enum):
|
||||
HEARTBEAT_REPLY="HEARTBEAT_REPLY" # 心跳包回复,带有当前主播的人气值
|
||||
LIVE = "LIVE" # 主播开播
|
||||
PREPARING = "PREPARING" # 下播【结束语】
|
||||
ROOM_CHANGE = "ROOM_CHANGE" # 房间信息改变
|
||||
|
@ -20,6 +20,9 @@ async def listen(ctx: BLiverCtx):
|
||||
f'[弹幕] {danmu.sender.name} ({danmu.sender.medal.medal_name}:{danmu.sender.medal.medal_level}): "{danmu.content}"\n'
|
||||
)
|
||||
|
||||
@app.on(Events.HEARTBEAT_REPLY)
|
||||
async def liver_popularity(ctx: BLiverCtx):
|
||||
print(ctx.body['popularity'])
|
||||
|
||||
@app.on(Events.INTERACT_WORD)
|
||||
async def listen_join(ctx: BLiverCtx):
|
||||
|
Loading…
Reference in New Issue
Block a user