nonebot-adapter-bilibili-live


Namenonebot-adapter-bilibili-live JSON
Version 0.2.3 PyPI version JSON
download
home_pageNone
Summarybilibili 直播间协议支持
upload_time2025-08-08 07:37:28
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseNone
keywords nonebot bilibili live adapter
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # NoneBot-Adapter-BiliBili-Live

B 站直播间协议支持

## 配置

修改 NoneBot 配置文件 `.env` 或者 `.env.*`。

### Driver

请参考 [driver](https://nonebot.dev/docs/appendices/config#driver) 配置项,添加 `HTTPClient` 和 `WebSocketClient` 支持。如:

```dotenv
DRIVER=~httpx+~websockets
DRIVER=~aiohttp
```

### BILIBILI_LIVE_BOTS

#### 用户 Bot (Web API)

- `cookie` 机器人账号的 Cookies,需要存在 `SESSDATA`(必须) 和 `bili_jct`(用于一些 API 调用)。
- `room_ids` 监听的直播间房间号列表,长短号均可。

类型为 `WebBot`。

#### 开放平台 Bot

- `access_key` 开放平台提供的 `access_key`
- `access_secret` 开放平台提供的 `access_secret`
- `app_id` 项目 ID,在[此处](https://open-live.bilibili.com/open-manage)查看
- `identify_codes` 主播身份码列表,主播身份码可以在[幻星-互动玩法](https://play-live.bilibili.com)页面右下角 身份码 查看

类型为 `OpenBot`。

__开放平台 Bot 无法调用任何 API。__

#### 示例

用户 Bot 配置示例:

```dotenv
BILIBILI_LIVE_BOTS='
[
  {
    "cookie": "SESSDATA=xxxxxxxxxxxxxxxx; bili_jct=xxxxxxxxxxxxx;",
    "room_ids": [544853]
  }
]
'
```

开放平台 Bot 配置示例:

```dotenv
BILIBILI_LIVE_BOTS='
[
  {
    "access_key": "xxxxxxxxxxxxxxxxxxxx",
    "access_secret": "xxxxxxxxxxxxxxxxxxxx",
    "app_id": 100000,
    "identify_codes": ["xxxxxxxxxxxxxxxxxxxx"]
  }
]
'
```

## 实现

标斜体的为用户 Bot 和开放平台 Bot 共有实现,粗体的为开放平台 Bot 独有实现(继承 `OpenplatformOnlyEvent`),其他为用户 Bot 独有实现(继承 `WebOnlyEvent`)。

来自开放平台的事件的 `uid` 均为 `0`,相应的存在 `open_id` 字段。

获取用户 ID 建议使用 `event.get_user_id()` 方法,而不是 `event.uid` 或 `event.open_id`。

<details>
<summary>消息类事件</summary>

- _`DanmakuEvent` 弹幕消息_
- _`SuperChatEvent` 醒目留言。来自开放平台的会被认为是 `to_me`;来自用户 Bot 的当 Bot 为主播账号时会被认为是 `to_me`。_

</details>

<details>
<summary>通知类事件</summary>

### 用户互动

- _`UserEnterEvent` 用户进入直播间_
- `UserFollowEvent` 用户关注主播
- `UserShareEvent` 用户分享直播间
- _`LikeEvent` 点赞_
- `InteractionVote` 投票互动事件
- `InteractionDanmaku` 弹幕互动事件
- `InteractionFollow` 关注互动事件
- `InteractionGift` 送礼互动事件
- `InteractionShare` 分享互动事件
- `InteractionLike` 点赞互动事件

### 礼物相关

- _`SendGiftEvent` 送礼_
- _`GuardBuyEvent` 上舰通知_
- `GuardBuyToastEvent` 用户庆祝消息
- `SpecialGiftEvent` 特殊礼物
- `GiftStarProcessEvent` 礼物星球点亮

### 直播状态

- __`OpenLiveStartEvent` 开播事件__
- __`OpenLiveEndEvent` 下播事件__
- `WebLiveStartEvent` 直播开始
- `OnlineRankEvent` 高能榜更新
- `OnlineRankCountEvent` 高能用户数量
- `OnlineRankTopEvent` 到达直播间高能榜前三名
- `LikeInfoUpdateEvent` 点赞数更新
- `WatchedChangeEvent` 看过人数
- `StopLiveRoomListEvent` 下播的直播间

### 直播间管理

- `RoomRealTimeMessageUpdateEvent` 主播信息更新
- `RoomChangeEvent` 直播间信息更改
- `ChangeRoomInfoEvent` 直播间背景图片修改
- `RoomSkinMsgEvent` 直播间皮肤变更
- `RoomSilentOnEvent` 开启等级禁言
- `RoomSilentOffEvent` 关闭等级禁言
- `RoomBlockMsgEvent` 指定观众禁言
- `RoomAdminsEvent` 房管列表
- `RoomAdminEntranceEvent` 设立房管
- `RoomAdminRevokeEvent` 撤销房管

### 排行榜

- `PopularRankChangedEvent` 直播间在人气榜的排名改变
- `HotRankChangedEvent` 直播间限时热门榜排名改变
- `HotRankSettlementEvent` 限时热门榜上榜信息
- `AreaRankChangedEvent` 直播间在所属分区的排名改变

</details>

<details>
<summary>元事件</summary>

- _`HeartbeatEvent` 心跳包,包含人气值_
- `LIVE_OPEN_PLATFORM_INTERACTION_END` 开放平台互动结束事件。此事件不会进入 NoneBot 事件处理流程,会由适配器自行捕获。

</details>

<details>
<summary>API 实现</summary>

__API 仅限用户 Bot。__

### 弹幕发送

- `send_danmaku()` 发送弹幕消息

### 直播间信息

- `get_room_info()` 获取直播间详细信息
- `get_user_room_status()` 获取用户对应的直播间状态
- `get_master_info()` 获取主播信息

### 用户管理

- `add_silent_user()` 禁言观众
- `get_silent_user_list()` 查询直播间禁言列表
- `del_silent_user()` 解除禁言

</details>

## 代码实现参考

- [BAC](https://github.com/SocialSisterYi/bilibili-API-collect)
- [直播开放平台文档](https://open-live.bilibili.com/document)
- [blivedm](https://github.com/xfgryujk/blivedm)
- [adapter-bilibili](https://github.com/wwweww/adapter-bilibili)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "nonebot-adapter-bilibili-live",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "nonebot, bilibili, live, adapter",
    "author": null,
    "author_email": "MingxuanGame <MingxuanGame@outlook.com>",
    "download_url": "https://files.pythonhosted.org/packages/d0/3e/fe1dc2d1624d70239ba05317281a88265737b5ead1237bba1f4e8bcdf7c1/nonebot_adapter_bilibili_live-0.2.3.tar.gz",
    "platform": null,
    "description": "# NoneBot-Adapter-BiliBili-Live\n\nB \u7ad9\u76f4\u64ad\u95f4\u534f\u8bae\u652f\u6301\n\n## \u914d\u7f6e\n\n\u4fee\u6539 NoneBot \u914d\u7f6e\u6587\u4ef6 `.env` \u6216\u8005 `.env.*`\u3002\n\n### Driver\n\n\u8bf7\u53c2\u8003 [driver](https://nonebot.dev/docs/appendices/config#driver) \u914d\u7f6e\u9879\uff0c\u6dfb\u52a0 `HTTPClient` \u548c `WebSocketClient` \u652f\u6301\u3002\u5982\uff1a\n\n```dotenv\nDRIVER=~httpx+~websockets\nDRIVER=~aiohttp\n```\n\n### BILIBILI_LIVE_BOTS\n\n#### \u7528\u6237 Bot (Web API)\n\n- `cookie` \u673a\u5668\u4eba\u8d26\u53f7\u7684 Cookies\uff0c\u9700\u8981\u5b58\u5728 `SESSDATA`\uff08\u5fc5\u987b\uff09 \u548c `bili_jct`\uff08\u7528\u4e8e\u4e00\u4e9b API \u8c03\u7528\uff09\u3002\n- `room_ids` \u76d1\u542c\u7684\u76f4\u64ad\u95f4\u623f\u95f4\u53f7\u5217\u8868\uff0c\u957f\u77ed\u53f7\u5747\u53ef\u3002\n\n\u7c7b\u578b\u4e3a `WebBot`\u3002\n\n#### \u5f00\u653e\u5e73\u53f0 Bot\n\n- `access_key` \u5f00\u653e\u5e73\u53f0\u63d0\u4f9b\u7684 `access_key`\n- `access_secret` \u5f00\u653e\u5e73\u53f0\u63d0\u4f9b\u7684 `access_secret`\n- `app_id` \u9879\u76ee ID\uff0c\u5728[\u6b64\u5904](https://open-live.bilibili.com/open-manage)\u67e5\u770b\n- `identify_codes` \u4e3b\u64ad\u8eab\u4efd\u7801\u5217\u8868\uff0c\u4e3b\u64ad\u8eab\u4efd\u7801\u53ef\u4ee5\u5728[\u5e7b\u661f-\u4e92\u52a8\u73a9\u6cd5](https://play-live.bilibili.com)\u9875\u9762\u53f3\u4e0b\u89d2 \u8eab\u4efd\u7801 \u67e5\u770b\n\n\u7c7b\u578b\u4e3a `OpenBot`\u3002\n\n__\u5f00\u653e\u5e73\u53f0 Bot \u65e0\u6cd5\u8c03\u7528\u4efb\u4f55 API\u3002__\n\n#### \u793a\u4f8b\n\n\u7528\u6237 Bot \u914d\u7f6e\u793a\u4f8b\uff1a\n\n```dotenv\nBILIBILI_LIVE_BOTS='\n[\n  {\n    \"cookie\": \"SESSDATA=xxxxxxxxxxxxxxxx; bili_jct=xxxxxxxxxxxxx;\",\n    \"room_ids\": [544853]\n  }\n]\n'\n```\n\n\u5f00\u653e\u5e73\u53f0 Bot \u914d\u7f6e\u793a\u4f8b\uff1a\n\n```dotenv\nBILIBILI_LIVE_BOTS='\n[\n  {\n    \"access_key\": \"xxxxxxxxxxxxxxxxxxxx\",\n    \"access_secret\": \"xxxxxxxxxxxxxxxxxxxx\",\n    \"app_id\": 100000,\n    \"identify_codes\": [\"xxxxxxxxxxxxxxxxxxxx\"]\n  }\n]\n'\n```\n\n## \u5b9e\u73b0\n\n\u6807\u659c\u4f53\u7684\u4e3a\u7528\u6237 Bot \u548c\u5f00\u653e\u5e73\u53f0 Bot \u5171\u6709\u5b9e\u73b0\uff0c\u7c97\u4f53\u7684\u4e3a\u5f00\u653e\u5e73\u53f0 Bot \u72ec\u6709\u5b9e\u73b0\uff08\u7ee7\u627f `OpenplatformOnlyEvent`\uff09\uff0c\u5176\u4ed6\u4e3a\u7528\u6237 Bot \u72ec\u6709\u5b9e\u73b0\uff08\u7ee7\u627f `WebOnlyEvent`\uff09\u3002\n\n\u6765\u81ea\u5f00\u653e\u5e73\u53f0\u7684\u4e8b\u4ef6\u7684 `uid` \u5747\u4e3a `0`\uff0c\u76f8\u5e94\u7684\u5b58\u5728 `open_id` \u5b57\u6bb5\u3002\n\n\u83b7\u53d6\u7528\u6237 ID \u5efa\u8bae\u4f7f\u7528 `event.get_user_id()` \u65b9\u6cd5\uff0c\u800c\u4e0d\u662f `event.uid` \u6216 `event.open_id`\u3002\n\n<details>\n<summary>\u6d88\u606f\u7c7b\u4e8b\u4ef6</summary>\n\n- _`DanmakuEvent` \u5f39\u5e55\u6d88\u606f_\n- _`SuperChatEvent` \u9192\u76ee\u7559\u8a00\u3002\u6765\u81ea\u5f00\u653e\u5e73\u53f0\u7684\u4f1a\u88ab\u8ba4\u4e3a\u662f `to_me`\uff1b\u6765\u81ea\u7528\u6237 Bot \u7684\u5f53 Bot \u4e3a\u4e3b\u64ad\u8d26\u53f7\u65f6\u4f1a\u88ab\u8ba4\u4e3a\u662f `to_me`\u3002_\n\n</details>\n\n<details>\n<summary>\u901a\u77e5\u7c7b\u4e8b\u4ef6</summary>\n\n### \u7528\u6237\u4e92\u52a8\n\n- _`UserEnterEvent` \u7528\u6237\u8fdb\u5165\u76f4\u64ad\u95f4_\n- `UserFollowEvent` \u7528\u6237\u5173\u6ce8\u4e3b\u64ad\n- `UserShareEvent` \u7528\u6237\u5206\u4eab\u76f4\u64ad\u95f4\n- _`LikeEvent` \u70b9\u8d5e_\n- `InteractionVote` \u6295\u7968\u4e92\u52a8\u4e8b\u4ef6\n- `InteractionDanmaku` \u5f39\u5e55\u4e92\u52a8\u4e8b\u4ef6\n- `InteractionFollow` \u5173\u6ce8\u4e92\u52a8\u4e8b\u4ef6\n- `InteractionGift` \u9001\u793c\u4e92\u52a8\u4e8b\u4ef6\n- `InteractionShare` \u5206\u4eab\u4e92\u52a8\u4e8b\u4ef6\n- `InteractionLike` \u70b9\u8d5e\u4e92\u52a8\u4e8b\u4ef6\n\n### \u793c\u7269\u76f8\u5173\n\n- _`SendGiftEvent` \u9001\u793c_\n- _`GuardBuyEvent` \u4e0a\u8230\u901a\u77e5_\n- `GuardBuyToastEvent` \u7528\u6237\u5e86\u795d\u6d88\u606f\n- `SpecialGiftEvent` \u7279\u6b8a\u793c\u7269\n- `GiftStarProcessEvent` \u793c\u7269\u661f\u7403\u70b9\u4eae\n\n### \u76f4\u64ad\u72b6\u6001\n\n- __`OpenLiveStartEvent` \u5f00\u64ad\u4e8b\u4ef6__\n- __`OpenLiveEndEvent` \u4e0b\u64ad\u4e8b\u4ef6__\n- `WebLiveStartEvent` \u76f4\u64ad\u5f00\u59cb\n- `OnlineRankEvent` \u9ad8\u80fd\u699c\u66f4\u65b0\n- `OnlineRankCountEvent` \u9ad8\u80fd\u7528\u6237\u6570\u91cf\n- `OnlineRankTopEvent` \u5230\u8fbe\u76f4\u64ad\u95f4\u9ad8\u80fd\u699c\u524d\u4e09\u540d\n- `LikeInfoUpdateEvent` \u70b9\u8d5e\u6570\u66f4\u65b0\n- `WatchedChangeEvent` \u770b\u8fc7\u4eba\u6570\n- `StopLiveRoomListEvent` \u4e0b\u64ad\u7684\u76f4\u64ad\u95f4\n\n### \u76f4\u64ad\u95f4\u7ba1\u7406\n\n- `RoomRealTimeMessageUpdateEvent` \u4e3b\u64ad\u4fe1\u606f\u66f4\u65b0\n- `RoomChangeEvent` \u76f4\u64ad\u95f4\u4fe1\u606f\u66f4\u6539\n- `ChangeRoomInfoEvent` \u76f4\u64ad\u95f4\u80cc\u666f\u56fe\u7247\u4fee\u6539\n- `RoomSkinMsgEvent` \u76f4\u64ad\u95f4\u76ae\u80a4\u53d8\u66f4\n- `RoomSilentOnEvent` \u5f00\u542f\u7b49\u7ea7\u7981\u8a00\n- `RoomSilentOffEvent` \u5173\u95ed\u7b49\u7ea7\u7981\u8a00\n- `RoomBlockMsgEvent` \u6307\u5b9a\u89c2\u4f17\u7981\u8a00\n- `RoomAdminsEvent` \u623f\u7ba1\u5217\u8868\n- `RoomAdminEntranceEvent` \u8bbe\u7acb\u623f\u7ba1\n- `RoomAdminRevokeEvent` \u64a4\u9500\u623f\u7ba1\n\n### \u6392\u884c\u699c\n\n- `PopularRankChangedEvent` \u76f4\u64ad\u95f4\u5728\u4eba\u6c14\u699c\u7684\u6392\u540d\u6539\u53d8\n- `HotRankChangedEvent` \u76f4\u64ad\u95f4\u9650\u65f6\u70ed\u95e8\u699c\u6392\u540d\u6539\u53d8\n- `HotRankSettlementEvent` \u9650\u65f6\u70ed\u95e8\u699c\u4e0a\u699c\u4fe1\u606f\n- `AreaRankChangedEvent` \u76f4\u64ad\u95f4\u5728\u6240\u5c5e\u5206\u533a\u7684\u6392\u540d\u6539\u53d8\n\n</details>\n\n<details>\n<summary>\u5143\u4e8b\u4ef6</summary>\n\n- _`HeartbeatEvent` \u5fc3\u8df3\u5305\uff0c\u5305\u542b\u4eba\u6c14\u503c_\n- `LIVE_OPEN_PLATFORM_INTERACTION_END` \u5f00\u653e\u5e73\u53f0\u4e92\u52a8\u7ed3\u675f\u4e8b\u4ef6\u3002\u6b64\u4e8b\u4ef6\u4e0d\u4f1a\u8fdb\u5165 NoneBot \u4e8b\u4ef6\u5904\u7406\u6d41\u7a0b\uff0c\u4f1a\u7531\u9002\u914d\u5668\u81ea\u884c\u6355\u83b7\u3002\n\n</details>\n\n<details>\n<summary>API \u5b9e\u73b0</summary>\n\n__API \u4ec5\u9650\u7528\u6237 Bot\u3002__\n\n### \u5f39\u5e55\u53d1\u9001\n\n- `send_danmaku()` \u53d1\u9001\u5f39\u5e55\u6d88\u606f\n\n### \u76f4\u64ad\u95f4\u4fe1\u606f\n\n- `get_room_info()` \u83b7\u53d6\u76f4\u64ad\u95f4\u8be6\u7ec6\u4fe1\u606f\n- `get_user_room_status()` \u83b7\u53d6\u7528\u6237\u5bf9\u5e94\u7684\u76f4\u64ad\u95f4\u72b6\u6001\n- `get_master_info()` \u83b7\u53d6\u4e3b\u64ad\u4fe1\u606f\n\n### \u7528\u6237\u7ba1\u7406\n\n- `add_silent_user()` \u7981\u8a00\u89c2\u4f17\n- `get_silent_user_list()` \u67e5\u8be2\u76f4\u64ad\u95f4\u7981\u8a00\u5217\u8868\n- `del_silent_user()` \u89e3\u9664\u7981\u8a00\n\n</details>\n\n## \u4ee3\u7801\u5b9e\u73b0\u53c2\u8003\n\n- [BAC](https://github.com/SocialSisterYi/bilibili-API-collect)\n- [\u76f4\u64ad\u5f00\u653e\u5e73\u53f0\u6587\u6863](https://open-live.bilibili.com/document)\n- [blivedm](https://github.com/xfgryujk/blivedm)\n- [adapter-bilibili](https://github.com/wwweww/adapter-bilibili)\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "bilibili \u76f4\u64ad\u95f4\u534f\u8bae\u652f\u6301",
    "version": "0.2.3",
    "project_urls": {
        "Changelog": "https://github.com/MingxuanGame/nonebot-adapter-bilibili-live/releases",
        "Documentation": "https://github.com/MingxuanGame/nonebot-adapter-bilibili-live",
        "Homepage": "https://github.com/MingxuanGame/nonebot-adapter-bilibili-live",
        "Issues": "https://github.com/MingxuanGame/nonebot-adapter-bilibili-live/issues",
        "Repository": "https://github.com/MingxuanGame/nonebot-adapter-bilibili-live"
    },
    "split_keywords": [
        "nonebot",
        " bilibili",
        " live",
        " adapter"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "f14db20a68133b23c9fe5f153d0bcd230b47089ff9e12a493fb9deb56829b581",
                "md5": "6c33ffbf3324ea1494fda5b6ade77be4",
                "sha256": "ee9bfcf77c69aa5bbc46d26c0e75718092368cb20ce032f3d47f9c66a92784e7"
            },
            "downloads": -1,
            "filename": "nonebot_adapter_bilibili_live-0.2.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6c33ffbf3324ea1494fda5b6ade77be4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 36368,
            "upload_time": "2025-08-08T07:37:27",
            "upload_time_iso_8601": "2025-08-08T07:37:27.689984Z",
            "url": "https://files.pythonhosted.org/packages/f1/4d/b20a68133b23c9fe5f153d0bcd230b47089ff9e12a493fb9deb56829b581/nonebot_adapter_bilibili_live-0.2.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "d03efe1dc2d1624d70239ba05317281a88265737b5ead1237bba1f4e8bcdf7c1",
                "md5": "88cc61278f4a7e397925e256a0bcf81f",
                "sha256": "e1db58ddb2bdd20485dcc47fb189ea52063b86341c55b69b29f52caabfe70044"
            },
            "downloads": -1,
            "filename": "nonebot_adapter_bilibili_live-0.2.3.tar.gz",
            "has_sig": false,
            "md5_digest": "88cc61278f4a7e397925e256a0bcf81f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 32574,
            "upload_time": "2025-08-08T07:37:28",
            "upload_time_iso_8601": "2025-08-08T07:37:28.873096Z",
            "url": "https://files.pythonhosted.org/packages/d0/3e/fe1dc2d1624d70239ba05317281a88265737b5ead1237bba1f4e8bcdf7c1/nonebot_adapter_bilibili_live-0.2.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-08 07:37:28",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "MingxuanGame",
    "github_project": "nonebot-adapter-bilibili-live",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "nonebot-adapter-bilibili-live"
}
        
Elapsed time: 1.67929s