Skip to main content

云湖用户账户驱动适配器,支持通过用户账号与云湖平台交互

Project description

ErisPulse 云湖用户账户驱动适配器

基于云湖用户账户而实现的 ErisPulse 适配器

安装

pip install ErisPulse-YunhuUserAdapter

使用方法

基础使用

from ErisPulse.Core import adapter

# 获取适配器实例
yunhu = adapter.get("yunhu_user")

# 发送文本消息
await yunhu.Send.To("user", "user_id").Text("Hello World!")

# 发送到群聊
await yunhu.Send.To("group", "group_id").Text("群消息")

# 发送图片
await yunhu.Send.To("group", "group_id").Image("https://example.com/image.jpg")

多账户使用

from ErisPulse.Core import adapter

yunhu = adapter.get("yunhu_user")

# 使用指定账户发送消息
await yunhu.Send.Using("default").To("group", "group_id").Text("来自默认账户的消息")

# 使用第二个账户发送消息
await yunhu.Send.Using("account2").To("user", "user_id").Text("来自账户2的消息")

# 或者使用 Account 方法(与 Using 等效)
await yunhu.Send.Account("account2").To("group", "group_id").Text("消息内容")

链式修饰

# 回复消息
await yunhu.Send.To("group", "group_id").Reply("message_id").Text("回复内容")

await yunhu.Send.To("group", "group_id").Reply("message_id").At("user_id").Text("@用户并回复")

# 因为用户账户较为特殊,即便你不是管理员,也可以@全体 故这里只会发送一个艾特全体的文本
# 这是一个伪@全体
await yunhu.Send.To("group", "group_id").Reply("message_id").AtAll().Text("@全体并回复")

# 添加按钮
buttons = [
    [
        {"text": "确认", "actionType": 3, "value": "confirm"},
        {"text": "取消", "actionType": 3, "value": "cancel"}
    ]
]
await yunhu.Send.To("group", "group_id").Buttons(buttons).Text("请选择")

# 组合使用
await yunhu.Send.Using("default").To("group", "group_id").Reply("msg_id").Buttons(buttons).Text("回复消息")

消息类型

# 文本消息
await yunhu.Send.To("user", "user_id").Text("纯文本消息")

# Markdown 消息
await yunhu.Send.To("group", "group_id").Markdown("**粗体** 和 *斜体*")

# HTML 消息
await yunhu.Send.To("group", "group_id").Html("<b>加粗</b> 和 <i>斜体</i>")

# A2UI 消息
await yunhu.Send.To("group", "group_id").A2ui({"type": "card", "content": "..."})

# 编辑消息
await yunhu.Send.To("group", "group_id").Edit("message_id", "新内容")

# 编辑消息(指定内容类型)
await yunhu.Send.To("group", "group_id").Edit("message_id", "新内容", content_type="markdown")

# 撤回消息
await yunhu.Send.To("group", "group_id").Recall("message_id")

# 以下媒体消息均支持URL和二进制传入

# 图片消息(URL)
await yunhu.Send.To("group", "group_id").Image("https://example.com/image.jpg")

# 视频消息
await yunhu.Send.To("group", "group_id").Video("https://example.com/video.mp4")

# 文件消息
await yunhu.Send.To("group", "group_id").File("https://example.com/document.pdf")

# 语音消息
await yunhu.Send.To("group", "group_id").Audio("https://example.com/audio.mp3")

# 表情消息(URL 或 表情ID 或 二进制数据)
await yunhu.Send.To("group", "group_id").Face("https://example.com/sticker.png")

OneBot12 原始消息

# 发送 OneBot12 格式消息段
ob12_message = [
    {"type": "text", "data": {"text": "Hello"}},
    {"type": "image", "data": {"file_id": "image_id"}}
]
await yunhu.Send.To("group", "group_id").Raw_ob12(ob12_message)

配置

config.toml 中配置:

[YunhuUserAdapter]
ws_reconnect_interval = 30
ws_timeout = 70

[YunhuUserAdapter.accounts.default]
email = "your_email@example.com"
password = "your_password"
platform = "windows"
device_id = ""
enabled = true

配置说明

字段 类型 默认值 说明
ws_reconnect_interval int 30 WebSocket 重连间隔(秒)
ws_timeout int 70 WebSocket 超时时间(秒)
accounts.<name>.email str - 登录邮箱
accounts.<name>.password str - 登录密码
accounts.<name>.platform str "windows" 登录平台
accounts.<name>.device_id str "" 设备ID(留空自动生成)
accounts.<name>.enabled bool true 是否启用

事件监听

from ErisPulse.Core.Event import message, command, notice

# 消息事件
@message.on_message()
async def message_handler(event):
    if event["platform"] == "yunhu_user":
        await event.reply("Echo: " + event.get_alt_message())

# 命令处理
@command("hello", help="发送问候")
async def hello_command(event):
    await event.reply("你好!我是云湖用户机器人。")

事件格式

消息事件

{
    "id": "event_id",
    "time": 1234567890,
    "type": "message",
    "detail_type": "group",  # 或 "private"
    "platform": "yunhu_user",
    "self": {
        "platform": "yunhu_user",
        "user_id": "your_user_id"
    },
    "message": [
        {"type": "text", "data": {"text": "消息内容"}}
    ],
    "alt_message": "消息内容",
    "user_id": "sender_user_id",
    "user_nickname": "发送者昵称",
    "group_id": "group_id",   # 群消息时包含
    "yunhu_user_raw": {...},  # 原始事件数据
    "yunhu_user_raw_type": "push_message"  # 原始事件类型
}

平台特有字段

所有云湖用户特有字段都以 yunhu_user_ 前缀标识:

  • yunhu_user_raw: 原始事件数据(包含完整的云湖协议数据)
  • yunhu_user_raw_type: 原始事件类型(如 push_messageedit_message 等)

API 响应格式

适配器的 call_api 方法返回符合 OneBot12 的响应格式:

{
    "status": "ok",  # 或 "failed"
    "retcode": 0,  # 0 表示成功,其他为错误码
    "data": {...},  # 响应数据
    "message_id": "message_id",  # 消息ID
    "message": "",  # 错误信息(成功时为空)
    "yunhu_user_raw": {...}  # 原始响应数据
}

事件处理范围

适配器支持了以下云湖 WebSocket 事件:

原始事件类型 OneBot12 类型 说明
push_message message 推送消息(包括私聊、群聊)
edit_message notice 消息编辑事件
file_send_message notice 超级文件分享事件
bot_board_message notice 机器人公告设置事件

其他事件类型(如 heartbeat_ackdraft_input 等)会被忽略。

OneBot12 支持的 detail_type

适配器将云湖消息转换为以下 OneBot12 类型:

OneBot12 detail_type 云湖 chat_type 说明
private 1 私聊消息
group 2 群聊消息
bot 3 机器人消息

开发状态

  • 基础适配器结构
  • 多账户支持(AccountConfigClass 声明式配置)
  • WebSocket 连接和消息接收(使用 sdk.client.ws_connect)
  • 自动重连机制
  • 事件转换(OneBot12 格式)
  • 消息发送(文本、图片、视频、文件、语音、Markdown、HTML、A2UI、表情)
  • 链式修饰(Reply、Buttons、At、AtAll)
  • 消息管理(Edit、Recall)
  • 用户邮箱登录
  • Raw_ob12 原始消息发送
  • sdk.client 统一 HTTP 客户端(移除直接 aiohttp 依赖)
  • sdk.client.ws_connect 统一 WebSocket 客户端(移除直接 websockets 依赖)

致谢

相关链接

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_yunhuuseradapter-4.0.0.tar.gz (47.3 kB view details)

Uploaded Source

Built Distribution

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

erispulse_yunhuuseradapter-4.0.0-py3-none-any.whl (44.5 kB view details)

Uploaded Python 3

File details

Details for the file erispulse_yunhuuseradapter-4.0.0.tar.gz.

File metadata

File hashes

Hashes for erispulse_yunhuuseradapter-4.0.0.tar.gz
Algorithm Hash digest
SHA256 bf477bb28a9c5eeaa7a855a7eacaad103767d31be6c0a8eaa54bc03dfbd4df7c
MD5 b2517ba66610eba13474ea7dc447ae87
BLAKE2b-256 6e01f909d247570661045c69c684a1f9192d811de706cd83cc12cc7e3fa12655

See more details on using hashes here.

Provenance

The following attestation bundles were made for erispulse_yunhuuseradapter-4.0.0.tar.gz:

Publisher: python-publish.yml on wsu2059q/ErisPulse-YunhuUserAdapter

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_yunhuuseradapter-4.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for erispulse_yunhuuseradapter-4.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bac4ef79d8bae66b902d74cc8b76ce5770ba4f49531d48160b472e13f4ed3846
MD5 49c1ee527ee6fba0487b188575dd45bb
BLAKE2b-256 05e8ac39a8f2a0f7a7fa5084a04093d949a48f56b779a19c520c53db5aeafcf8

See more details on using hashes here.

Provenance

The following attestation bundles were made for erispulse_yunhuuseradapter-4.0.0-py3-none-any.whl:

Publisher: python-publish.yml on wsu2059q/ErisPulse-YunhuUserAdapter

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