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 私聊/频道/群聊
  • 转发模式黑白名单,仅允许/除了名单内的群/qq号转发
  • 使用指令临时关闭单向互通
  • 互通模式和转发模式可同时开启不会重复发送消息
  • 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
onebot2tg_forward_filter_mode str "none" 可选"none","blacklist","whitelist"
onebot2tg_forward_filter_list list [] 按照filter_mode的参数配置白名单或黑名单,如["12345678","123"]

🎉 使用示例

场景 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.11.tar.gz (7.8 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.11-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nonebot_plugin_onebot2tg-1.0.11.tar.gz
  • Upload date:
  • Size: 7.8 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.11.tar.gz
Algorithm Hash digest
SHA256 c3b5102dbf3d97dd7a5605c992b142124cc9a79594406d1a584b42f8e8b48dc1
MD5 f4291fd0d7328747b461f8e7ff92a7ad
BLAKE2b-256 e8f366995ee95bb88c5b90bbf56ad2d1edc212f943b448773f7668af212c2245

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nonebot_plugin_onebot2tg-1.0.11-py3-none-any.whl
  • Upload date:
  • Size: 8.4 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.11-py3-none-any.whl
Algorithm Hash digest
SHA256 7d0fbdfd5ff3021f1364867e2a3a136e6f4bb2a658c4b277f5417a1f1c6bb3d8
MD5 078de8d75df996656db162fe267a164c
BLAKE2b-256 7e9117331c7a85c2d733da3a02875c2545e883a57928226bb66274900c096263

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