Skip to main content

OneBot V11 与 Telegram 消息转发插件

Project description

logo

✨ nonebot-plugin-onebot2tg ✨

LICENSE pypi python uv
ruff pre-commit

OneBot V11 与 Telegram 消息转发插件

📖 功能

  • 互通模式:指定一个 QQ 群与一个 Telegram 群/频道双向互通,消息实时同步
  • 转发模式:将 QQ 所有接收到的消息单向转发到 Telegram 私聊/频道/群聊
  • 使用指令临时关闭单向互通
  • 互通模式和转发模式可同时开启不会重复发送消息
  • Telegram 图片/贴纸下载会自动走适配器配置的代理
  • 消息类型支持:文本、图片、贴纸
  • 贴纸图片过大时自动压缩?
  • GIF转发
  • 显示具体表情而不是表情ID
  • 显示@人的昵称而不是QQ号
  • 双向转发Reply消息 这个可能需要做数据库
  • 在实现Reply消息后 实现转发模式双向转发
    ...

💿 安装

使用 nb-cli 安装 在 nonebot2 项目的根目录下打开命令行, 输入以下指令即可安装
nb plugin install nonebot-plugin-onebot2tg --upgrade

使用 pypi 源安装

nb plugin install nonebot-plugin-onebot2tg --upgrade -i "https://pypi.org/simple"

使用清华源安装

nb plugin install nonebot-plugin-onebot2tg --upgrade -i "https://pypi.tuna.tsinghua.edu.cn/simple"
使用包管理器安装 在 nonebot2 项目的插件目录下, 打开命令行, 根据你使用的包管理器, 输入相应的安装命令
uv
uv add nonebot-plugin-onebot2tg

安装仓库 main 分支

uv add git+https://github.com/SoulGateKey/nonebot-plugin-onebot2tg@main
pdm
pdm add nonebot-plugin-onebot2tg

安装仓库 main 分支

pdm add git+https://github.com/SoulGateKey/nonebot-plugin-onebot2tg@main
poetry
poetry add nonebot-plugin-onebot2tg

安装仓库 main 分支

poetry add git+https://github.com/SoulGateKey/nonebot-plugin-onebot2tg@main

打开 nonebot2 项目根目录下的 pyproject.toml 文件, 在 [tool.nonebot] 部分追加写入

plugins = ["nonebot_plugin_onebot2tg"]
使用 nbr 安装(使用 uv 管理依赖可用)

nbr 是一个基于 uv 的 nb-cli,可以方便地管理 nonebot2

nbr plugin install nonebot-plugin-onebot2tg

使用 pypi 源安装

nbr plugin install nonebot-plugin-onebot2tg -i "https://pypi.org/simple"

使用清华源安装

nbr plugin install nonebot-plugin-onebot2tg -i "https://pypi.tuna.tsinghua.edu.cn/simple"

依赖适配器

⚙️ 配置

.env 文件中添加以下配置项:

模式开关

配置项 类型 默认值 说明
ONEBOT2TG_ENABLE_BRIDGE bool True 开启互通模式(双向转发,需配置互通群号,默认开启)
ONEBOT2TG_ENABLE_FORWARD bool False 开启转发模式(QQ 所有消息单向转发到 TG)

互通模式配置

配置项 类型 默认值 说明
ONEBOT2TG_BRIDGE_GROUP_ID str | int "" 互通模式下,要互通的 QQ 群号
ONEBOT2TG_BRIDGE_TG_CHAT_ID str | int "" 互通模式下,TG 对应的 chat_id(群或频道)

互通模式指令表

指令 触发端 作用
/ruler Telegram 临时关闭 TG → QQ 的互通转发
/sese QQ 临时关闭 QQ → TG 的互通转发

转发模式配置

配置项 类型 默认值 说明
ONEBOT2TG_FORWARD_TARGET_CHAT_ID str | int "" 转发模式下,QQ 消息转发到 TG 的目标 chat_id 或 用户ID

🎉 使用示例

场景 1:QQ 群与 Telegram 群互通

ONEBOT2TG_ENABLE_BRIDGE=true
ONEBOT2TG_ENABLE_FORWARD=false
ONEBOT2TG_BRIDGE_GROUP_ID=123456789
ONEBOT2TG_BRIDGE_TG_CHAT_ID=-1001234567890

配置后,该 QQ 群与 Telegram 群的消息会实时双向同步。

场景 2:QQ 消息单向转发到 Telegram

ONEBOT2TG_ENABLE_BRIDGE=false
ONEBOT2TG_ENABLE_FORWARD=true
ONEBOT2TG_FORWARD_TARGET_CHAT_ID=-1001234567890

配置后,QQ 群/私聊接收到的所有消息会单向转发到指定的 Telegram 聊天。

场景 3:互通和转发模式同时开启

注意事项

  • 目前仅测试过QQ与TG互转,其他onebot实现欢迎提交测试结果及PR
  • 互通模式为一对一配置,暂不支持多群互通
  • 转发模式为单向(QQ → TG),TG 消息不会转发回 QQ

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

nonebot_plugin_onebot2tg-1.0.9.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

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

nonebot_plugin_onebot2tg-1.0.9-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file nonebot_plugin_onebot2tg-1.0.9.tar.gz.

File metadata

  • Download URL: nonebot_plugin_onebot2tg-1.0.9.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for nonebot_plugin_onebot2tg-1.0.9.tar.gz
Algorithm Hash digest
SHA256 3ab35bd7e9140890544b6efbe27f9d726b06df4b9a2dc48f828aeb5167d3d5ca
MD5 4eabbe62ba0badc9f8f56b9edb0ba8de
BLAKE2b-256 d66453e31d282d76560ace7d485508e1fd21af90bfa160741fc5847732c5d418

See more details on using hashes here.

File details

Details for the file nonebot_plugin_onebot2tg-1.0.9-py3-none-any.whl.

File metadata

  • Download URL: nonebot_plugin_onebot2tg-1.0.9-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for nonebot_plugin_onebot2tg-1.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 053d8d316685f93bd38b0f971c761d55f4c832135a697885328eedbce42115ba
MD5 49b0b1a5491062e45f1035e614e23681
BLAKE2b-256 1c5e73ca919e3a5c711fa6316ea11f781b1ed48e74f7faf52793e364b47753a5

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