Skip to main content

bilibili 直播间协议支持

Project description

NoneBot-Adapter-BiliBili-Live

B 站直播间协议支持

配置

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

Driver

请参考 driver 配置项,添加 HTTPClientWebSocketClient 支持。如:

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,在此处查看
  • identify_codes 主播身份码列表,主播身份码可以在幻星-互动玩法页面右下角 身份码 查看

类型为 OpenBot

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

示例

用户 Bot 配置示例:

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

开放平台 Bot 配置示例:

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.uidevent.open_id

消息类事件
  • DanmakuEvent 弹幕消息
  • SuperChatEvent 醒目留言。来自开放平台的会被认为是 to_me;来自用户 Bot 的当 Bot 为主播账号时会被认为是 to_me
通知类事件

用户互动

  • 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 直播间在所属分区的排名改变
元事件
  • HeartbeatEvent 心跳包,包含人气值
  • LIVE_OPEN_PLATFORM_INTERACTION_END 开放平台互动结束事件。此事件不会进入 NoneBot 事件处理流程,会由适配器自行捕获。
API 实现

API 仅限用户 Bot。

弹幕发送

  • send_danmaku() 发送弹幕消息

直播间信息

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

用户管理

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

代码实现参考

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nonebot_adapter_bilibili_live-0.2.5.tar.gz (32.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nonebot_adapter_bilibili_live-0.2.5-py3-none-any.whl (36.4 kB view details)

Uploaded Python 3

File details

Details for the file nonebot_adapter_bilibili_live-0.2.5.tar.gz.

File metadata

  • Download URL: nonebot_adapter_bilibili_live-0.2.5.tar.gz
  • Upload date:
  • Size: 32.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for nonebot_adapter_bilibili_live-0.2.5.tar.gz
Algorithm Hash digest
SHA256 91c267951db69970ce8c0a101f7dd134733b006928ca5ec81269f999c93b9686
MD5 fec098a080d91a2c757f8caf8dee51df
BLAKE2b-256 80de95661e8587af64e6d49cc197ce4d1f189bf841b7a2292d2cc18bbf768aba

See more details on using hashes here.

File details

Details for the file nonebot_adapter_bilibili_live-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: nonebot_adapter_bilibili_live-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 36.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for nonebot_adapter_bilibili_live-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a47440ae6230b3343078053535445d5b5f6b3a8d6cdedd17dddb2bd983ebdb2c
MD5 43393156d770ac78a9be5ff90a7146a3
BLAKE2b-256 a765a6b8a39b090ea8de9c7833340a13415c6f22c6266fdb01aa030dda5de399

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page