Skip to content

Commit c6cdaa0

Browse files
committed
Refactor code structure for improved readability and maintainability
1 parent 1f43568 commit c6cdaa0

4 files changed

Lines changed: 2418 additions & 14 deletions

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ venv.bak/
120120
# Project specific
121121
test/
122122
bot.py
123-
pyproject.toml
124123
.vscode/
125124

126125
# Spyder project settings

README.md

Lines changed: 80 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1-
# nonebot-plugin-onebot2tg
1+
<div align="center">
2+
<a href="https://v2.nonebot.dev/store">
3+
<img src="https://raw.githubusercontent.com/fllesser/nonebot-plugin-template/refs/heads/resource/.docs/NoneBotPlugin.svg" width="310" alt="logo"></a>
24

3-
> OneBot V11 与 Telegram 消息转发插件
5+
## ✨ nonebot-plugin-onebot2tg ✨
6+
[![LICENSE](https://img.shields.io/github/license/SoulGateKey/nonebot-plugin-onebot2tg.svg)](./LICENSE)
7+
[![pypi](https://img.shields.io/pypi/v/nonebot-plugin-onebot2tg.svg)](https://pypi.python.org/pypi/nonebot-plugin-onebot2tg)
8+
[![python](https://img.shields.io/badge/python-3.10|3.11|3.12|3.13-blue.svg)](https://www.python.org)
9+
[![uv](https://img.shields.io/badge/package%20manager-uv-black?style=flat-square&logo=uv)](https://github.com/astral-sh/uv)
10+
<br/>
11+
[![ruff](https://img.shields.io/badge/code%20style-ruff-black?style=flat-square&logo=ruff)](https://github.com/astral-sh/ruff)
12+
[![pre-commit](https://results.pre-commit.ci/badge/github/SoulGateKey/nonebot-plugin-onebot2tg/master.svg)](https://results.pre-commit.ci/latest/github/SoulGateKey/nonebot-plugin-onebot2tg/master)
13+
</div>
414

15+
OneBot V11 与 Telegram 消息转发插件
516

6-
## 功能
17+
18+
## 📖 功能
719

820
- [x] **互通模式**:指定一个 QQ 群与一个 Telegram 群/频道双向互通,消息实时同步
921
- [x] **转发模式**:将 QQ 所有接收到的消息单向转发到 Telegram 私聊/频道/群聊
@@ -18,24 +30,79 @@
1830
- [ ] 在实现Reply消息后 实现转发模式双向转发
1931
...
2032

21-
## 安装
33+
## 💿 安装
34+
<details open>
35+
<summary>使用 nb-cli 安装</summary>
36+
在 nonebot2 项目的根目录下打开命令行, 输入以下指令即可安装
2237

23-
```bash
24-
nb plugin install nonebot-plugin-onebot2tg
25-
```
38+
nb plugin install nonebot-plugin-onebot2tg --upgrade
39+
使用 **pypi** 源安装
2640

27-
或手动安装:
41+
nb plugin install nonebot-plugin-onebot2tg --upgrade -i "https://pypi.org/simple"
42+
使用**清华源**安装
2843

29-
```bash
30-
pip install nonebot-plugin-onebot2tg
31-
```
44+
nb plugin install nonebot-plugin-onebot2tg --upgrade -i "https://pypi.tuna.tsinghua.edu.cn/simple"
45+
46+
47+
</details>
48+
49+
<details>
50+
<summary>使用包管理器安装</summary>
51+
在 nonebot2 项目的插件目录下, 打开命令行, 根据你使用的包管理器, 输入相应的安装命令
52+
53+
<details open>
54+
<summary>uv</summary>
55+
56+
uv add nonebot-plugin-onebot2tg
57+
安装仓库 master 分支
58+
59+
uv add git+https://github.com/SoulGateKey/nonebot-plugin-onebot2tg@master
60+
</details>
61+
62+
<details>
63+
<summary>pdm</summary>
64+
65+
pdm add nonebot-plugin-onebot2tg
66+
安装仓库 master 分支
67+
68+
pdm add git+https://github.com/SoulGateKey/nonebot-plugin-onebot2tg@master
69+
</details>
70+
<details>
71+
<summary>poetry</summary>
72+
73+
poetry add nonebot-plugin-onebot2tg
74+
安装仓库 master 分支
75+
76+
poetry add git+https://github.com/SoulGateKey/nonebot-plugin-onebot2tg@master
77+
</details>
78+
79+
打开 nonebot2 项目根目录下的 `pyproject.toml` 文件, 在 `[tool.nonebot]` 部分追加写入
80+
81+
plugins = ["nonebot_plugin_onebot2tg"]
82+
83+
</details>
84+
85+
<details>
86+
<summary>使用 nbr 安装(使用 uv 管理依赖可用)</summary>
87+
88+
[nbr](https://github.com/fllesser/nbr) 是一个基于 uv 的 nb-cli,可以方便地管理 nonebot2
89+
90+
nbr plugin install nonebot-plugin-onebot2tg
91+
使用 **pypi** 源安装
92+
93+
nbr plugin install nonebot-plugin-onebot2tg -i "https://pypi.org/simple"
94+
使用**清华源**安装
95+
96+
nbr plugin install nonebot-plugin-onebot2tg -i "https://pypi.tuna.tsinghua.edu.cn/simple"
97+
98+
</details>
3299

33100
## 依赖适配器
34101

35102
- [nonebot-adapter-onebot](https://github.com/nonebot/adapter-onebot) (OneBot V11)
36103
- [nonebot-adapter-telegram](https://github.com/nonebot/adapter-telegram) (Telegram)
37104

38-
## 配置
105+
## ⚙️ 配置
39106

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

@@ -59,7 +126,7 @@ pip install nonebot-plugin-onebot2tg
59126
|--------|------|--------|------|
60127
| `ONEBOT2TG_FORWARD_TARGET_CHAT_ID` | `str \| int` | `""` | 转发模式下,QQ 消息转发到 TG 的目标 chat_id 或 用户ID |
61128

62-
## 使用示例
129+
## 🎉 使用示例
63130

64131
### 场景 1:QQ 群与 Telegram 群互通
65132

pyproject.toml

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
[project]
2+
name = "nonebot-plugin-onebot2tg"
3+
version = "1.0.1"
4+
description = "OneBot V11 与 Telegram 消息转发插件"
5+
readme = "README.md"
6+
requires-python = ">=3.10"
7+
authors = [{ name = "SoulGateKey", email = "SoulGateKey@gmail.com" }]
8+
dependencies = [
9+
"httpx>=0.27.0,<1.0.0",
10+
"nonebot-plugin-alconna>=0.60.0,<1.0.0",
11+
"nonebot-plugin-apscheduler>=0.5.0,<1.0.0",
12+
"nonebot-plugin-localstore>=0.7.4,<1.0.0",
13+
"nonebot-plugin-uninfo>=0.10.0,<1.0.0",
14+
"nonebot2>=2.5.0,<3.0.0",
15+
]
16+
17+
[project.urls]
18+
Homepage = "https://github.com/SoulGateKey/nonebot-plugin-tgqbridge"
19+
Issues = "https://github.com/SoulGateKey/nonebot-plugin-tgqbridge/issues"
20+
Repository = "https://github.com/SoulGateKey/nonebot-plugin-tgqbridge.git"
21+
22+
[dependency-groups]
23+
dev = [
24+
"bump-my-version>=1.2.7",
25+
"nonebot2[fastapi]>=2.5.0,<3.0.0",
26+
"poethepoet>=0.42.1",
27+
"ruff>=0.15.2,<1.0.0",
28+
{ include-group = "test" },
29+
]
30+
test = [
31+
"nonebot-adapter-onebot>=2.4.6,<3.0.0",
32+
"nonebot-adapter-telegram>=0.1.0b1,<1.0.0",
33+
"nonebot2[fastapi]>=2.5.0,<3.0.0",
34+
"nonebug>=0.4.4,<1.0.0",
35+
"pytest>=9.0.2,<10.0.0",
36+
"poethepoet>=0.42.1",
37+
"pytest-asyncio>=1.3.0,<1.4.0",
38+
"pytest-cov>=7.0.0",
39+
"pytest-xdist>=3.8.0,<4.0.0",
40+
]
41+
42+
[build-system]
43+
requires = ["uv_build>=0.10.0,<0.11.0"]
44+
build-backend = "uv_build"
45+
46+
[tool.bumpversion]
47+
current_version = "1.0.1"
48+
commit = true
49+
message = "release: bump version from {current_version} to {new_version}"
50+
tag = true
51+
52+
[[tool.bumpversion.files]]
53+
filename = "pyproject.toml"
54+
search = 'version = "{current_version}"'
55+
replace = 'version = "{new_version}"'
56+
57+
[tool.coverage.report]
58+
exclude_lines = [
59+
"raise NotImplementedError",
60+
"if TYPE_CHECKING:",
61+
"@overload",
62+
"except ImportError:",
63+
]
64+
65+
[tool.nonebot]
66+
plugins = ["nonebot_plugin_onebot2tg"]
67+
68+
[tool.poe.tasks]
69+
test = "pytest --cov=src --cov-report xml --junitxml=./junit.xml -n auto"
70+
bump = "bump-my-version bump"
71+
show-bump = "bump-my-version show-bump"
72+
73+
[tool.pyright]
74+
pythonVersion = "3.10"
75+
pythonPlatform = "All"
76+
defineConstant = { PYDANTIC_V2 = true }
77+
executionEnvironments = [
78+
{ root = "./tests", extraPaths = [
79+
"./src",
80+
] },
81+
{ root = "./src" },
82+
]
83+
typeCheckingMode = "standard"
84+
disableBytesTypePromotions = true
85+
86+
[tool.pytest]
87+
addopts = [
88+
"--import-mode=prepend",
89+
"--strict-markers",
90+
"--tb=short",
91+
"-ra",
92+
"-s",
93+
"-v",
94+
]
95+
pythonpath = ["src"]
96+
asyncio_mode = "auto"
97+
asyncio_default_fixture_loop_scope = "session"
98+
99+
[tool.ruff]
100+
line-length = 88
101+
102+
[tool.ruff.format]
103+
line-ending = "lf"
104+
105+
[tool.ruff.lint]
106+
select = [
107+
"F",
108+
"W",
109+
"E",
110+
"I",
111+
"UP",
112+
"ASYNC",
113+
"C4",
114+
"T10",
115+
"T20",
116+
"PYI",
117+
"PT",
118+
"Q",
119+
"TID",
120+
"RUF",
121+
]
122+
ignore = [
123+
"E402",
124+
"UP037",
125+
"RUF001",
126+
"RUF002",
127+
"RUF003",
128+
"W191",
129+
"TID252",
130+
]
131+
132+
[tool.ruff.lint.isort]
133+
length-sort = true
134+
known-first-party = ["tests/*"]
135+
extra-standard-library = ["typing_extensions"]
136+
137+
[tool.ruff.lint.pyupgrade]
138+
keep-runtime-typing = true

0 commit comments

Comments
 (0)