Skip to main content

OneBot adapter for lss233/chatgpt-mirai-qq-bot

Project description

OneBot-adapter for ChatGPT-Mirai-QQ-Bot

本项目是 ChatGPT-Mirai-QQ-Bot 的一个插件,用于将OneBot协议的消息转换为ChatGPT-Mirai-QQ-Bot的消息格式。

安装

pip install chatgpt-mirai-qq-bot-onebot-adapter

使用

config.yaml 中的 ims 中添加以下内容:

ims:
  enable:
    onebot: ['onebot-default']
    ... # 其他IM配置
  configs:
    onebot-default:
      host: '0.0.0.0'
      port: '5545'
      access_token: ''
      filter_file: 'filter.json'
      name: 'onebot'
      heartbeat_interval: '15000'    # 心跳间隔(毫秒)
      reconnect_interval: '3000'     # 重连间隔(毫秒)
    ... # 其他IM配置

什么是filter.json

filter.json事件过滤器,用于过滤消息的规则文件,具体请参考 CQHTTP-API

项目工作原理

sequenceDiagram
    participant 客户端 as OneBot Client
    participant 适配器 as OneBotAdapter
    participant 过滤器 as EventFilter
    participant 消息处理 as MessageHandler
    participant 命令处理 as CommandHandler
    participant 消息转换 as MessageConverter

    客户端->>适配器: WebSocket消息
    适配器->>适配器: 处理消息事件
    适配器->>过滤器: 检查是否需要处理

    alt 通过过滤
        过滤器-->>适配器: 返回true
        适配器->>消息处理: 转换为统一消息格式
        消息处理-->>适配器: 返回Message对象
        Note over 适配器: 提取会话ID和文本内容
        适配器->>命令处理: 解析命令

        alt 是命令消息
            命令处理-->>适配器: 返回命令和参数
            适配器->>适配器: 处理命令
            Note over 适配器: 创建响应消息
        else 普通消息
            命令处理-->>适配器: 返回空字符串
            适配器->>适配器: 处理普通消息
        end

        Note over 适配器: 创建文本消息响应
        适配器->>消息转换: 转换为OneBot消息格式
        Note over 消息转换: 转换各种消息元素
        消息转换-->>适配器: 返回OneBot消息

        alt 私聊消息
            适配器->>客户端: 发送私聊消息
        else 群聊消息
            适配器->>客户端: 发送群聊消息
        end

        客户端-->>适配器: 消息发送完成

    else 被过滤
        过滤器-->>适配器: 返回false
        Note over 适配器: 忽略该消息
    end

开源协议

本项目基于 ChatGPT-Mirai-QQ-Bot 开发,遵循其 开源协议

感谢

感谢 ChatGPT-Mirai-QQ-Bot 的作者 lss233 提供框架支持

感谢 AIOCQHTTP 的作者 nonebot 提供CQHTTP协议支持

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

chatgpt_mirai_qq_bot_onebot_adapter-0.1.0.tar.gz (20.7 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file chatgpt_mirai_qq_bot_onebot_adapter-0.1.0.tar.gz.

File metadata

File hashes

Hashes for chatgpt_mirai_qq_bot_onebot_adapter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 df9eb46e55d8da7e676d7372b7b9786e4d8258a0283c8c8e857d3dd2623d777e
MD5 175b5dea8c6cac3883143d9309b08b89
BLAKE2b-256 868f9e14968a2e48ec14936ff23451282fb93d6cf7dab0bdc86d1700b75498ed

See more details on using hashes here.

File details

Details for the file chatgpt_mirai_qq_bot_onebot_adapter-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for chatgpt_mirai_qq_bot_onebot_adapter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 159489acf0bc3cf640b8c79b07752687dfbb7b9c85094be017e5630032b421bf
MD5 41c4a6715c5a1615f432e0a7615c3358
BLAKE2b-256 7ac43b124ca0f5f59998cf1de2e72965dd1950fbe6a2401c61167feef9489032

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