2022-11-25 20:30:45 +08:00
|
|
|
from blive import BLiver, Events, BLiverCtx
|
2022-01-09 11:19:51 +08:00
|
|
|
from blive.msg import (
|
|
|
|
DanMuMsg,
|
2022-02-22 13:34:46 +08:00
|
|
|
EntryEffectMsg,
|
2022-01-09 11:19:51 +08:00
|
|
|
HotRankChangeV2Msg,
|
|
|
|
InteractWordMsg,
|
2022-02-22 13:34:46 +08:00
|
|
|
OnlineRankCountMsg,
|
2022-01-09 11:19:51 +08:00
|
|
|
SendGiftMsg,
|
2022-02-22 13:34:46 +08:00
|
|
|
StopLiveRoomListMsg,
|
2022-01-09 11:19:51 +08:00
|
|
|
SuperChatMsg,
|
|
|
|
)
|
2022-01-06 00:50:50 +08:00
|
|
|
|
2022-02-22 13:34:46 +08:00
|
|
|
app = BLiver(510)
|
2022-01-06 00:50:50 +08:00
|
|
|
|
|
|
|
|
2022-01-06 12:18:29 +08:00
|
|
|
@app.on(Events.DANMU_MSG)
|
2022-01-06 00:50:50 +08:00
|
|
|
async def listen(ctx: BLiverCtx):
|
|
|
|
danmu = DanMuMsg(ctx.body)
|
2022-01-06 12:18:29 +08:00
|
|
|
print(
|
2022-11-25 20:30:45 +08:00
|
|
|
f'[弹幕] {danmu.sender.name} ({danmu.sender.medal.medal_name}:{danmu.sender.medal.medal_level}): "{danmu.content}"\n'
|
2022-01-06 12:18:29 +08:00
|
|
|
)
|
|
|
|
|
2023-02-11 17:24:11 +08:00
|
|
|
@app.on(Events.HEARTBEAT_REPLY)
|
|
|
|
async def liver_popularity(ctx: BLiverCtx):
|
|
|
|
print(ctx.body['popularity'])
|
2022-01-06 12:18:29 +08:00
|
|
|
|
|
|
|
@app.on(Events.INTERACT_WORD)
|
|
|
|
async def listen_join(ctx: BLiverCtx):
|
|
|
|
join = InteractWordMsg(ctx.body)
|
|
|
|
print(
|
2022-11-25 20:30:45 +08:00
|
|
|
"[欢迎]",
|
2022-01-06 12:18:29 +08:00
|
|
|
f"{join.user['name']} ({join.user['medal']['medal_name']}:{join.user['medal']['medal_level']})",
|
2022-11-25 20:30:45 +08:00
|
|
|
"进入直播间\n",
|
2022-01-06 12:18:29 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@app.on(Events.SUPER_CHAT_MESSAGE)
|
|
|
|
async def listen_sc(ctx: BLiverCtx):
|
2022-01-09 11:19:51 +08:00
|
|
|
msg = SuperChatMsg(ctx.body)
|
2022-02-22 13:34:46 +08:00
|
|
|
print(
|
2022-11-25 20:30:45 +08:00
|
|
|
f"[sc] 感谢 {msg.sender['name']}({msg.sender['medal']['medal_name']}:{msg.sender['medal']['medal_level']})的价值 {msg.price} 的sc\n\n\t{msg.content}\n"
|
2022-02-22 13:34:46 +08:00
|
|
|
)
|
2022-01-06 12:18:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
@app.on(Events.SEND_GIFT)
|
|
|
|
async def listen_gift(ctx: BLiverCtx):
|
|
|
|
msg = SendGiftMsg(ctx.body)
|
2022-02-22 13:34:46 +08:00
|
|
|
print(
|
2022-11-25 20:30:45 +08:00
|
|
|
f"[礼物] {msg.sender['name']} ({msg.sender['medal']['medal_name']}:{msg.sender['medal']['medal_level']}) 送出 {msg.gift['gift_name']}\n"
|
2022-02-22 13:34:46 +08:00
|
|
|
)
|
2022-01-06 12:18:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
@app.on(Events.HOT_RANK_CHANGED_V2)
|
|
|
|
async def hot(ctx: BLiverCtx):
|
|
|
|
msg = HotRankChangeV2Msg(ctx.body)
|
|
|
|
print(
|
2022-11-25 20:30:45 +08:00
|
|
|
f"[通知] 恭喜 {ctx.bliver.uname} 在 {msg.area_name} 区 的 {msg.rank_desc} 榜单中获得第 {msg.rank} 名\n"
|
2022-01-06 12:18:29 +08:00
|
|
|
)
|
2022-01-06 00:50:50 +08:00
|
|
|
|
|
|
|
|
2022-02-22 13:34:46 +08:00
|
|
|
@app.on(Events.ENTRY_EFFECT)
|
|
|
|
async def welcome_captain(ctx: BLiverCtx):
|
|
|
|
msg = EntryEffectMsg(ctx.body)
|
2022-11-25 20:30:45 +08:00
|
|
|
print(f"[热烈欢迎] {msg.copy_writting}\n")
|
2022-02-22 13:34:46 +08:00
|
|
|
|
|
|
|
|
|
|
|
@app.on(Events.STOP_LIVE_ROOM_LIST)
|
|
|
|
async def stop_live_room_list(ctx: BLiverCtx):
|
|
|
|
# 监听停止直播的房间
|
|
|
|
msg = StopLiveRoomListMsg(ctx.body)
|
2022-11-25 20:30:45 +08:00
|
|
|
print(f"[通知] 停止直播的房间列表:{msg.room_id_list}\n")
|
2022-02-22 13:34:46 +08:00
|
|
|
|
|
|
|
|
|
|
|
@app.on(Events.ONLINE_RANK_COUNT)
|
|
|
|
async def online_rank(ctx):
|
|
|
|
msg = OnlineRankCountMsg(ctx.body)
|
2022-11-25 20:30:45 +08:00
|
|
|
print(f"[通知] 当前在线人气排名 {msg.count}\n")
|
2022-02-22 13:34:46 +08:00
|
|
|
|
|
|
|
|
2022-01-06 00:50:50 +08:00
|
|
|
app.run()
|