blive/app.py

56 lines
1.3 KiB
Python
Raw Normal View History

from blive import BLiver, Events, BLiverCtx
2022-01-09 11:19:51 +08:00
from blive.msg import (
DanMuMsg,
HotRankChangeV2Msg,
InteractWordMsg,
SendGiftMsg,
SuperChatMsg,
)
2022-01-06 00:50:50 +08:00
2022-01-09 11:19:51 +08:00
app = BLiver(605)
2022-01-06 00:50:50 +08:00
@app.on(Events.DANMU_MSG)
2022-01-06 00:50:50 +08:00
async def listen(ctx: BLiverCtx):
danmu = DanMuMsg(ctx.body)
print(
2022-02-08 11:19:04 +08:00
f"\n{danmu.sender['name']}({danmu.sender['medal']['medal_name']}:{danmu.sender['medal']['medal_level']}): \"{danmu.content}\"\n"
)
@app.on(Events.INTERACT_WORD)
async def listen_join(ctx: BLiverCtx):
join = InteractWordMsg(ctx.body)
print(
"欢迎",
f"{join.user['name']} ({join.user['medal']['medal_name']}:{join.user['medal']['medal_level']})",
"进入直播间",
)
@app.on(Events.SUPER_CHAT_MESSAGE)
async def listen_sc(ctx: BLiverCtx):
2022-01-09 11:19:51 +08:00
msg = SuperChatMsg(ctx.body)
print(msg.sender)
print(msg.content)
print(msg.start_time)
print(msg.time)
print(msg.price)
@app.on(Events.SEND_GIFT)
async def listen_gift(ctx: BLiverCtx):
msg = SendGiftMsg(ctx.body)
print(f"{msg.sender['name']} 送出 {msg.gift['gift_name']}")
@app.on(Events.HOT_RANK_CHANGED_V2)
async def hot(ctx: BLiverCtx):
msg = HotRankChangeV2Msg(ctx.body)
print(
f"恭喜 {ctx.bliver.uname}{msg.area_name} 区 的 {msg.rank_desc} 榜单中获得第 {msg.rank}"
)
2022-01-06 00:50:50 +08:00
app.run()