Skip to content

Commit 5fd0ca8

Browse files
authored
feat(plugin): 添加B站直播查询功能(未测试)
1 parent fe27f93 commit 5fd0ca8

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

plugins/axt_plugin_bililive.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "AxTBot-Public"
3-
version = "2.1.0+13020"
3+
version = "2.1.0+13021"
44
description = "AxTBot 社区机器人是由 AxT社区 开发并维护的公共、公益性QQ官方机器人,基于QQ开放平台 ,使用 Python 和 FastAPI 构建"
55
authors = [
66
{name = "Shanshui2024", email = "[email protected]"},

0 commit comments

Comments
 (0)