支持情况
事件支持情况
- 基础消息事件 / 指令消息事件
- 关注 / 取关机器人事件
- 加入 / 退出群事件
- 按钮事件上报接收
- 快捷菜单事件 (
bot.shortcut.menu) - 机器人设置事件 (
bot.setting) - A2UI 表单 / 按钮事件 (
a2ui.button.report) - 按钮发送
- 表单接收
事件接收方式
- Webhook 上报 (需要公网地址)
- WebSocket 订阅 (无需公网地址,断线自动重连)
支持的消息元素
| 元素 | 支持情况 |
|---|---|
| 文本 Text | ✅ |
| 图片 Image | ✅ |
| 提及用户 At(user) | ✅ |
| 按钮 Buttons | ✅ |
| 表单 Form | ⬇️ |
| 表情包 expression | ⬇️ |
| 语音 Audio | ⬇️ |
| 视频 Video | ✅ |
| 文件 File | ✅ |
| HTML HTML | ✅ |
| 文章 Post | ⬇️ |
| Markdown | ✅ |
| 提示信息 Tip | ⬇️ |
| 回复 Reply | ✅ |
支持的消息操作
| 操作 | 支持情况 |
|---|---|
| 发送 Send | ✅ |
| 撤回 Recall | ✅ |
| 编辑 Edit | ✅ |
| 表情响应 Reaction | 🚫 |
简介
nonebot-adapter-yunhu 是为 NoneBot2 设计的云湖(YunHu)平台适配器,支持开发云湖机器人,提供完整的消息和服务支持。
安装
使用 pip 安装
pip install nonebot-adapter-yunhu
使用 nb-cli 安装
nb adapter install nonebot-adapter-yunhu
使用 poetry 安装
poetry add nonebot-adapter-yunhu
配置
在您的 NoneBot 项目配置文件 .env 中添加以下配置。适配器支持两种事件接收方式,可在同一项目中混用。
| 配置项 | 必填 | 默认值 | 说明 |
|---|---|---|---|
token |
是 | 机器人 Token | |
app_id |
否 | 机器人 ID,留空时通过 token 自动获取 | |
connection_type |
否 | websocket |
事件接收方式:websocket / webhook |
ws_url |
否 | wss://ws.jwzhd.com/subscribe |
WebSocket 订阅地址,token 会自动拼接,一般无需修改 |
reconnect_interval |
否 | 3.0 |
WebSocket 断线重连初始间隔(秒),失败时指数退避至 60 秒 |
use_stream |
否 | false |
是否使用流式回复(仅 text / markdown) |
方式一:WebSocket 订阅(默认,无需公网地址)
适配器会主动连接 wss://ws.jwzhd.com/subscribe?token={token} 接收事件,只需要填写 token:
DRIVER=~httpx+~websockets
YUNHU_BOTS='[{
"token": "xxx"
}]'
WebSocket 模式需要支持 WebSocket 客户端的驱动器,如
~websockets或~aiohttp。 若不需要同时开启 webhook,可以不使用~fastapi等 ASGI 驱动器。
方式二:Webhook 上报
DRIVER=~fastapi+~httpx
YUNHU_BOTS='[{
"token": "xxx",
"connection_type": "webhook"
}]'
HOST=0.0.0.0
PORT=8080
在云湖控制台,上报地址填写为 http(s)://{HOST}:{PORT}/yunhu/{app_id},其中 app_id 为机器人 ID(启动日志会打印实际地址)。
app_id会在启动时通过 token 自动获取;若启动时无法访问云湖接口,可手动填写"app_id": "123456"跳过该步骤。
注册适配器
在 bot.py 中注册适配器:
import nonebot
from nonebot.adapters.yunhu import Adapter as YunhuAdapter
nonebot.init()
driver = nonebot.get_driver()
driver.register_adapter(YunhuAdapter)
使用方法
基本用法
from nonebot import on_command
from nonebot.adapters.yunhu import Bot, Event
echo = on_command("echo")
@echo.handle()
async def handle_echo(bot: Bot, event: Event):
await echo.finish(event.get_message())
发送不同类型的消息
具体类型参考 message.py
from nonebot import on_command
from nonebot.adapters.yunhu import Bot, Event, MessageSegment
test = on_command("test")
@test.handle()
async def handle_send_image(bot: Bot, event: Event):
# 发送文本
await test.send(MessageSegment.text("Hello World"))
# 发送图片, 也可以直接传参 raw=bytes 或 raw="imageKey"
await test.send(MessageSegment.image(url="xxxxx"))
# @某人
await test.send(MessageSegment.at("user_id"))
其他 API
除消息收发外,Bot 还封装了官方开放平台的以下接口:
| 方法 | 说明 |
|---|---|
get_self_info() |
获取当前机器人信息(停用/封禁状态) |
get_bot_groups(page, size) |
分页获取机器人所在群 |
get_group_detail(group_id) |
获取群信息及机器人在群内的管理权限 |
get_group_members(group_id, page, size) |
分页获取群成员(需群内授权) |
batch_send_msg(type, ids, content, content_type) |
批量发送消息 |
get_msgs / get_msg / edit_msg / delete_msg |
消息列表 / 编辑 / 撤回 |
gag_member(group_id, user_id, duration) |
禁言(0 解除,-1 永久) |
remove_group_member(group_id, user_id) |
移除群成员 |
set_group_msg_type_limit(group_id, types) |
群内消息类型控制 |
get_group_tags / create_group_tag / edit_group_tag / delete_group_tag |
群标签管理 |
add_user_tag / remove_user_tag |
为群成员添加 / 移除标签 |
set_*_board / dismiss_*_board |
看板管理 |
获取帮助
- 加入云湖群聊【NoneBot 云湖适配器交流群】: 链接
- 群 ID: 519215204
相关链接
Metadata
Release files for nonebot-adapter-yunhu 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nonebot_adapter_yunhu-0.2.0.tar.gz | 34.8 kB | Without provenance | Details for nonebot_adapter_yunhu-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nonebot_adapter_yunhu-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for nonebot_adapter_yunhu-0.2.0-py3-none-any.whl |
Total release size: 71.9 kB
Release files / nonebot_adapter_yunhu-0.2.0.tar.gz
| Download URL | nonebot_adapter_yunhu-0.2.0.tar.gz |
|---|---|
| Size | 34.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
456159cd595e80b8686e3576880019745dc123e8f3d8debab798669e4a0d1fad
|
|
BLAKE2b-256 checksum How to use checksums |
2245fe46d1c43d7b8ccf2afab66f70d0180cbea7d0c7eee98cf994199eef8c85
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.5.2 CPython/3.15.2 Linux/7.0.0-1020-azure
|
Release files / nonebot_adapter_yunhu-0.2.0-py3-none-any.whl
| Download URL | nonebot_adapter_yunhu-0.2.0-py3-none-any.whl |
|---|---|
| Size | 37.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e0600cae03dae80a161117b0c7e221706bdb1e6ed5b38b57c4f37b3a26ca066a
|
|
BLAKE2b-256 checksum How to use checksums |
d5944b40ff4d60e072e5cd0b8d738a01c3a3ac098807f2e17972061b460a4dee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.5.2 CPython/3.15.2 Linux/7.0.0-1020-azure
|
Security for nonebot-adapter-yunhu 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.