yulinfeng000/blive

心跳包回复的数据前四位是人气值

Closed this issue · 3 comments

# 心跳不会粘包,前4位有不明含义的数据

这是说明

可以使用 struct.unpack("!I", data[:4]) 将其取出

好的,多谢

DEFAULT_POPULARITY = 1
popularity = struct.unpack("!I", data[:4])[0]
if popularity != DEFAULT_POPULARITY:
    packages.append(
        (header, f'{{"cmd": "HEARTBEAT", "popularity": {popularity}}}'))

我现在用这种方式把它模拟成一个cmd来把人气拿出来,有其他更优雅的实现方式吗?

已经改成通过cmd进行处理

@app.on(Events.HEARTBEAT_REPLY)
async def liver_popularity(ctx):
    print(ctx.body['popularity'])