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.0.tar.gz (38.3 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.0-py3-none-any.whl (45.0 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for nonebot_adapter_bilibili_live-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ba8269acd3e1d41e02060eba1e6ec638f0044d5dcc613f6bd3f2ccebc7fb1129
MD5 9e91393a5d640840ad56a32a5a9d85c4
BLAKE2b-256 2ff3cf17ef95e10a861e75182034ec3782ae9e39aac53d30905289a8cd9fbc7b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nonebot_adapter_bilibili_live-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8c1c59062b1c2c7308bda63b94f03c02cd27104406040fb29ba32c94269c3955
MD5 ff48afd65f44bf8d1f750724c5d80ce6
BLAKE2b-256 87fe6eeba64eb7343a2d77010c29c322e50dfd7583073b288da9d6d3e860bc6e

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