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>")

# 编辑消息
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")

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)

事件监听

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": "message.receive.normal"  # 原始事件类型
}

平台特有字段

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

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

API 响应格式

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

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

事件处理范围

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

原始事件类型 OneBot12 类型 说明
push_message message 推送消息(包括私聊、群聊)
edit_message message 消息编辑事件

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

OneBot12 支持的 detail_type

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

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

开发状态

  • 基础适配器结构
  • 多账户支持
  • WebSocket 连接和消息接收
  • 自动重连机制
  • 事件转换(OneBot12 格式)
  • 消息发送(文本、图片、视频、文件、语音、Markdown、HTML)
  • 链式修饰(Reply、Buttons、At、AtAll)
  • 消息管理(Edit、Recall)
  • 用户邮箱登录
  • Raw_ob12 原始消息发送

致谢

相关链接

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-1.2.2.tar.gz (33.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_yunhuuseradapter-1.2.2-py3-none-any.whl (35.3 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for erispulse_yunhuuseradapter-1.2.2.tar.gz
Algorithm Hash digest
SHA256 273c49befdf5530bc77bb0f21d9224e04e161d21bc1485ef6865b362cde4562c
MD5 1ecfd702f9a145f34ffd32893e5e3165
BLAKE2b-256 1c92e9a7c722b2b489c311b6fff441dc8c41d56c5f6574682fbe465c665f65a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for erispulse_yunhuuseradapter-1.2.2.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-1.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for erispulse_yunhuuseradapter-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0428c2fdba9d1006fcb36e65e18f16c4ebdd30b6c8a6d7a7f981f5d577cc4fc5
MD5 88b43070fa09860f7f145419009c2725
BLAKE2b-256 d228143811d7877c70b6882cbccc405bb90da8996e2cdbdc3f1955be440b4374

See more details on using hashes here.

Provenance

The following attestation bundles were made for erispulse_yunhuuseradapter-1.2.2-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