|
| 1 | +from src.Utils.PluginBase import command |
| 2 | +from src.Utils.EventClass import GroupMessageEvent |
| 3 | + |
| 4 | +from uapis_extension import post_for_api, get_from_api |
| 5 | + |
| 6 | + |
| 7 | +__metadata__ = { |
| 8 | + "name": "[社区插件]B站直播查询", |
| 9 | + "version": "1.0.0", |
| 10 | + "author": "AxT-Team", |
| 11 | + "description": "从接口请求得到B站直播间开播状态等信息", |
| 12 | + "official": False, |
| 13 | +} |
| 14 | + |
| 15 | +@command(["bili", "/bili"]) |
| 16 | +async def bili_handler(event: GroupMessageEvent): |
| 17 | + msg = event.content.split(" ")[1] if len(event.content.split(" ")) > 1 else "" |
| 18 | + try: |
| 19 | + response = await get_from_api("/api/v1/social/bilibili/liveroom?mid=" + str(msg)) |
| 20 | + except Exception as e: |
| 21 | + try: |
| 22 | + response = await get_from_api("/api/v1/social/bilibili/liveroom?room_id=" + str(msg)) |
| 23 | + except Exception as e: |
| 24 | + await event.reply("房间信息获取失败,请确保您输入了正确的房间号/主播UID") |
| 25 | + raise |
| 26 | + uid = response["uid"] |
| 27 | + roomid = response["roomid"] if response["short_id"] == 0 else response["short_id"] |
| 28 | + attention = response["attention"] |
| 29 | + online = response["online"] |
| 30 | + if response["live_status"] == 1: |
| 31 | + online = f"开播中" |
| 32 | + elif response["live_status"] == 0: |
| 33 | + online = f"未开播" |
| 34 | + elif response["live_status"] == 2: |
| 35 | + online = f"轮播中" |
| 36 | + else: |
| 37 | + online = f"未知状态" |
| 38 | + area = response["parent_area_name"] + " > " + response["area_name"] |
| 39 | + title = response["title"] |
| 40 | + pic = response["background"] |
| 41 | + desc = response["description"] |
| 42 | + live_time = response["live_time"] if response["live_status"] == 1 else "N/A" |
| 43 | + tags = ", ".join(response["tags"]) |
| 44 | + returns = f"""主播UID: {uid} |
| 45 | +房间号: {roomid} |
| 46 | +开播状态: {online} |
| 47 | +直播标题: {title} |
| 48 | +直播分区: {area} |
| 49 | +直播时间: {live_time} |
| 50 | +粉丝数: {attention} |
| 51 | +当前人气: {online} |
| 52 | +标签: {tags} |
| 53 | +直播简介: {desc} |
| 54 | +直播封面: {pic}""" |
| 55 | + await event.reply(returns) |
0 commit comments