Skip to main content

ErisPulse的OneBotV11协议适配模块,异步的OneBot触发器

Project description

OneBotAdapter 模块文档

简介

OneBotAdapter 是基于 ErisPulse 架构开发的 OneBot V11 协议适配器模块。它提供统一的事件处理机制、连接管理功能,并支持 Server 和 Connect 两种运行模式。


消息发送示例(DSL 链式风格)

文本消息

await onebot.Send.To("group", 123456).Text("Hello World!")

图片消息

await onebot.Send.To("user", 123456).Image("http://example.com/image.jpg")

语音消息

await onebot.Send.To("user", 123456).Voice("http://example.com/audio.mp3")

视频消息

await onebot.Send.To("group", 123456).Video("http://example.com/video.mp4")

发送原生 CQ 消息

await onebot.Send.To("user", 123456).Raw([
    {"type": "text", "data": {"text": "你好"}},
    {"type": "image", "data": {"file": "http://example.com/image.png"}}
])

支持的消息类型及对应方法

方法名 参数说明 用途
.Text(text: str) 发送纯文本消息 基础消息类型
.Image(file: str) 发送图片消息(URL 或 Base64) 支持 CQ 格式
.Voice(file: str) 发送语音消息 支持 CQ 格式
.Video(file: str) 发送视频消息 支持 CQ 格式
.Raw(message_list: List[Dict]) 发送原始 OneBot 消息结构 自定义消息内容

配置说明

[OneBotv11_Adapter]
mode = "client"

[OneBotv11_Adapter.server]
path = "/"
token = ""

[OneBotv11_Adapter.client]
url = "ws://127.0.0.1:3001"
token = ""

API 调用方式

通过 call_api 方法调用 OneBot 提供的任意 API 接口:

response = await onebot.call_api(
    endpoint="send_msg",
    message_type="group",
    group_id=123456,
    message="Hello!"
)

该方法会自动处理响应结果并返回,若超时将抛出异常。


运行模式说明

Server 模式(作为服务端监听连接)

  • 启动一个 WebSocket 服务器等待 OneBot 客户端连接。
  • 适用于部署多个 bot 客户端连接至同一服务端的场景。

Client 模式(主动连接 OneBot)

  • 主动连接到 OneBot 服务(如 go-cqhttp)。
  • 更适合单个 bot 实例直接连接的情况。

生命周期管理

启动适配器

await sdk.adapter.startup()

此方法会根据配置启动 Server 或连接到 OneBot 客户端。

关闭适配器

await sdk.adapter.shutdown()

确保资源释放,关闭 WebSocket 连接。


注意事项

  1. 所有 .Send.*() 方法返回 asyncio.Task,建议使用 await 等待执行完成。
  2. 确保在调用 startup() 前完成所有事件处理器注册。
  3. 生产环境建议启用 Token 认证以保证安全性。
  4. 若使用 Server 模式,请注意防火墙和端口开放情况。
  5. 程序退出时请调用 shutdown() 释放资源。

参考链接

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

erispulse_onebot11adapter-3.1.1.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

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

erispulse_onebot11adapter-3.1.1-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file erispulse_onebot11adapter-3.1.1.tar.gz.

File metadata

File hashes

Hashes for erispulse_onebot11adapter-3.1.1.tar.gz
Algorithm Hash digest
SHA256 517117f32a5ae7495dc45beaa212a8a3cb7f51aebc9df993295807bec3abd497
MD5 134c986a3769dcf36fd3ad34178d6b9b
BLAKE2b-256 4008450532990a2b0fe3111b7a8d08c8a6e4630fcc36e54ff7dc69b6a83c95bb

See more details on using hashes here.

Provenance

The following attestation bundles were made for erispulse_onebot11adapter-3.1.1.tar.gz:

Publisher: python-publish.yml on ErisPulse/ErisPulse-OneBot11Adapter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file erispulse_onebot11adapter-3.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for erispulse_onebot11adapter-3.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d77f44855c1e10ef3c5bcd7fbbdf9cc6090c3ee9b9c6f76246eba5bff49c0db9
MD5 344d3235ebe33f36b245110920a74877
BLAKE2b-256 f4955afc69e4795ac628fb211e1bf040fa77d988d8a90ff1ae8cc531092b5fef

See more details on using hashes here.

Provenance

The following attestation bundles were made for erispulse_onebot11adapter-3.1.1-py3-none-any.whl:

Publisher: python-publish.yml on ErisPulse/ErisPulse-OneBot11Adapter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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