Skip to content

Commit 8998cac

Browse files
authored
Merge pull request #70 from MuRainBot/dev
合并Dev分支:引入 CLI 工具与全新命令系统,修改包名,作为pip包发布到pypi,修复一些问题
2 parents ac32935 + acba290 commit 8998cac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2010
-573
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Publish Python Package
2+
3+
on:
4+
release:
5+
types: [published] # 当一个 Release 被发布时触发
6+
7+
jobs:
8+
deploy:
9+
runs-on: ubuntu-latest
10+
11+
permissions:
12+
id-token: write
13+
14+
steps:
15+
- uses: actions/checkout@v3
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v4
19+
with:
20+
python-version: '3.12'
21+
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install build
26+
27+
- name: Build package
28+
run: python -m build
29+
30+
- name: Publish package to PyPI
31+
uses: pypa/gh-action-pypi-publish@release/v1

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
*.dump
1414
test.py
1515
*.zip
16-
/MURainBot2
16+
/MURainBot2

Lib/__init__.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

Lib/constants.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

Lib/core/__init__.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

Lib/utils/PluginConfig.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

Lib/utils/__init__.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

MANIFEST.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
recursive-include plugins *
2+
global-exclude __pycache__
3+
global-exclude *.pyc
4+
global-exclude *.pyo

README.md

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@ MuRainBot2 (MRB2) 是一个基于 Python、适配 OneBot v11 协议的轻量级
3232

3333
* **🪶 轻量高效:** 没有太多冗杂的功能,使用简单,内存占用较低。
3434
* **🧩 轻松扩展:** 灵活的插件系统,让您能够轻松、快速地添加、移除或定制所需功能。
35-
* **🔁 基于线程池:** 基于内置线程池实现并发处理,没有异步的较为复杂的语法,直接编写同步代码。
35+
* **🔁 基于线程池:** 基于内置线程池实现并发处理,没有异步的较为复杂的语法,直接编写同步代码,且如果你使用nogil版本的python解释器可以获得更高的性能。
36+
* **🤖 命令解析:** 命令系统吸收了像 FastAPI 一样现代 Web 框架的优点,为开发者带来简洁、高效的插件编写体验。
3637

3738
## 🚨 重要提醒:关于重构与兼容性
3839

40+
> [!CAUTION]
41+
> **请注意:** 本项目在 2025/6/29 进行了一次巨大修改&更新,修改了目录结构和包名,如果您是旧版本用户或拥有旧插件,请修改插件以进行适配。
42+
3943
> [!CAUTION]
4044
> **请注意:** 本项目在 2024 年底至 2025 年初进行了一次 **彻底的重构**(主要涉及 `dev` 分支并在 2025年1月29日 合并至 `master`)。
4145
>
@@ -74,7 +78,7 @@ MuRainBot2 (MRB2) 是一个基于 Python、适配 OneBot v11 协议的轻量级
7478
```
7579
├─ data MRB2及插件的临时/缓存文件
7680
│ ├─ ...
77-
├─ Lib MRB2的Lib库,插件和MRB2均需要依赖此Lib
81+
├─ murainbot MRB2的Lib库,插件和MRB2均需要依赖此Lib
7882
│ ├─ __init__.py MRB2Lib的初始化文件
7983
│ ├─ core 核心模块,负责配置文件读取、与实现端通信、插件加载等
8084
│ | ├─ ...
@@ -104,18 +108,32 @@ MuRainBot2 (MRB2) 是一个基于 Python、适配 OneBot v11 协议的轻量级
104108

105109
**本项目使用 Python 3.12+ 开发,并利用了其部分新特性 (如 [PEP 701](https://docs.python.org/zh-cn/3/whatsnew/3.12.html#whatsnew312-pep701))。推荐使用 Python 3.12 或更高版本运行,如果使用 Python 3.12 以下版本,由于未经测试,可能会导致部分代码出现问题。**
106110

107-
详细的部署步骤、配置说明和插件开发指南,请查阅:
111+
~~详细~~的部署步骤、配置说明和插件开发指南,请查阅:
108112

109113
### ➡️ [**MRB2 官方文档**](https://mrb2.xiaosu.icu)
110114

115+
#### 快速部署指南
116+
117+
- 安装murainbot2
118+
```bash
119+
pip install murainbot
120+
```
121+
- 创建项目
122+
```bash
123+
murainbot init
124+
```
125+
- 启动项目
126+
```bash
127+
murainbot run
128+
```
129+
111130
## 📕 关于版本
112131

113-
* 当前版本:`1.0.0-dev`
114-
* 版本号格式:`<主版本>.<次版本>.<修订版本>[-<特殊标识>]` (例如 `1.0.0`, `1.0.1-beta`, `1.1.0-dev`)。
132+
* 目前项目仍在开发中,属于测试版,未来还可能会有一些不兼容更改和新功能添加,也欢迎各位提供宝贵的建设性的意见。
115133

116134
## ❤️ 鸣谢 ❤️
117135

118-
**贡献指南:** 我们欢迎各种形式的贡献!包括 Issues 和 Pull Request,您可以向我们反馈 bug 提供建议,也可以通过 PR 直接帮我们编写代码来实现功能或者修复bug。请将您的 Pull Request 提交到 `dev` 分支。我们会定期将 `dev` 分支的稳定更新合并到 `master` 分支。
136+
**贡献指南:** 我们欢迎各种形式的贡献!包括 Issues 和 Pull Request,您可以向我们反馈 bug 提供建议,请求一些新功能,也可以通过 PR 直接帮我们编写代码来实现功能或者修复bug。请将您的 Pull Request 提交到 `dev` 分支。我们会定期将 `dev` 分支的稳定更新合并到 `master` 分支。
119137

120138
**感谢所有为 MRB2 付出努力的贡献者!**
121139

main.py

Lines changed: 2 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -2,172 +2,6 @@
22
MuRainBot2
33
"""
44

5-
# __ __ ____ _ ____ _ _____
6-
# | \/ |_ _| _ \ __ _(_)_ __ | __ ) ___ | |_|___ \
7-
# | |\/| | | | | |_) / _` | | '_ \ | _ \ / _ \| __| __) |
8-
# | | | | |_| | _ < (_| | | | | | | |_) | (_) | |_ / __/
9-
# |_| |_|\__,_|_| \_\__,_|_|_| |_| |____/ \___/ \__|_____|
10-
import atexit
11-
import logging
12-
import random
13-
import threading
14-
import time
5+
from murainbot.main import start
156

16-
BANNER = r""" __ __ ____ _ ____ _ _____
17-
| \/ |_ _| _ \ __ _(_)_ __ | __ ) ___ | |_|___ \
18-
| |\/| | | | | |_) / _` | | '_ \ | _ \ / _ \| __| __) |
19-
| | | | |_| | _ < (_| | | | | | | |_) | (_) | |_ / __/
20-
|_| |_|\__,_|_| \_\__,_|_|_| |_| |____/ \___/ \__|_____|"""
21-
BANNER_LINK = "https://github.com/MuRainBot/MuRainBot2"
22-
23-
24-
def color_text(text: str, text_color: tuple[int, int, int] = None, bg_color: tuple[int, int, int] = None):
25-
"""
26-
富文本生成器
27-
@param text: 文本
28-
@param text_color: 文本颜色
29-
@param bg_color: 背景颜色
30-
@return: 富文本
31-
"""
32-
text = text + "\033[0m" if text_color is not None or bg_color is not None else text
33-
if text_color is not None:
34-
text = f"\033[38;2;{text_color[0]};{text_color[1]};{text_color[2]}m" + text
35-
if bg_color is not None:
36-
text = f"\033[48;2;{bg_color[0]};{bg_color[1]};{bg_color[2]}m" + text
37-
return text
38-
39-
40-
def get_gradient(start_color: tuple[int, int, int], end_color: tuple[int, int, int], length: float):
41-
"""
42-
渐变色生成
43-
@param start_color: 开始颜色
44-
@param end_color: 结束颜色
45-
@param length: 0-1的值
46-
@return: RGB颜色
47-
"""
48-
return (
49-
int(start_color[0] + (end_color[0] - start_color[0]) * length),
50-
int(start_color[1] + (end_color[1] - start_color[1]) * length),
51-
int(start_color[2] + (end_color[2] - start_color[2]) * length)
52-
)
53-
54-
55-
def print_loading(wait_str):
56-
"""
57-
输出加载动画
58-
"""
59-
loading_string_list = [r"|/-\\", r"▁▂▃▄▅▆▇█▇▆▅▄▃▂", "\u2801\u2808\u2810\u2820\u2880\u2900\u2804\u2802", r"←↖↑↗→↘↓↙"]
60-
loading_string = random.choice(loading_string_list)
61-
i = 0
62-
while not is_done:
63-
if i == len(loading_string):
64-
i = 0
65-
print("\r" + wait_str + color_text(loading_string[i], banner_start_color), end="")
66-
time.sleep(0.07)
67-
i += 1
68-
69-
70-
# 主函数
71-
if __name__ == '__main__':
72-
banner_start_color = (14, 190, 255)
73-
banner_end_color = (255, 66, 179)
74-
banner = BANNER.split("\n")
75-
color_banner = ""
76-
# 输出banner
77-
for i in range(len(banner)):
78-
for j in range(len(banner[i])):
79-
color_banner += color_text(
80-
banner[i][j],
81-
get_gradient(
82-
banner_start_color,
83-
banner_end_color,
84-
((j / (len(banner[i]) - 1) + i / (len(banner) - 1)) / 2)
85-
)
86-
)
87-
color_banner += "\n"
88-
89-
print(color_banner.strip())
90-
91-
# 输出项目链接
92-
for c in color_text(BANNER_LINK, get_gradient(banner_start_color, banner_end_color, 0.5)):
93-
print(c, end="")
94-
95-
wait_str = color_text("正在加载 Lib, 首次启动可能需要几秒钟,请稍等...", banner_start_color)
96-
print("\n" + wait_str, end="")
97-
is_done = False
98-
99-
threading.Thread(target=print_loading, daemon=True, args=(wait_str,)).start()
100-
101-
# 开始加载
102-
start_loading = time.time()
103-
104-
from Lib.utils import Logger
105-
106-
Logger.init()
107-
108-
from Lib.core import *
109-
110-
from Lib import *
111-
112-
atexit.register(common.finalize_and_cleanup)
113-
114-
ThreadPool.init()
115-
116-
Logger.set_logger_level(logging.DEBUG if ConfigManager.GlobalConfig().debug.enable else logging.INFO)
117-
118-
is_done = True
119-
120-
print("\r" + color_text(
121-
f"Lib 加载完成!耗时: {round(time.time() - start_loading, 2)}s 正在启动 MuRainBot... ",
122-
banner_end_color
123-
)
124-
)
125-
126-
logger = Logger.get_logger()
127-
128-
logger.info("日志初始化完成,MuRainBot正在启动...")
129-
130-
if ConfigManager.GlobalConfig().account.user_id == 0 or not ConfigManager.GlobalConfig().account.nick_name:
131-
logger.info("正在尝试获取用户信息...")
132-
try:
133-
account = OnebotAPI.api.get_login_info()
134-
new_account = ConfigManager.GlobalConfig().config.get("account")
135-
new_account.update({
136-
"user_id": account['user_id'],
137-
"nick_name": account['nickname']
138-
})
139-
140-
ConfigManager.GlobalConfig().set("account", new_account)
141-
except Exception as e:
142-
logger.warning(f"获取用户信息失败, 可能会导致严重的问题: {repr(e)}")
143-
144-
logger.info(f"欢迎使用: {ConfigManager.GlobalConfig().account.nick_name}"
145-
f"({ConfigManager.GlobalConfig().account.user_id})")
146-
147-
logger.debug(f"准备加载插件")
148-
PluginManager.load_plugins()
149-
logger.info(f"插件加载完成!共成功加载了 {len(PluginManager.plugins)} 个插件"
150-
f"{': \n' if len(PluginManager.plugins) >= 1 else ''}"
151-
f"{'\n'.join(
152-
[
153-
f'{_['name']}: {_['info'].NAME}' if 'info' in _ and _['info'] else _['name']
154-
for _ in PluginManager.plugins
155-
]
156-
)}")
157-
158-
threading.Thread(target=AutoRestartOnebot.check_heartbeat, daemon=True).start()
159-
160-
logger.info(f"启动监听服务器: {ConfigManager.GlobalConfig().server.server}")
161-
162-
if ConfigManager.GlobalConfig().server.server == "werkzeug":
163-
# 禁用werkzeug的日志记录
164-
log = logging.getLogger('werkzeug')
165-
log.disabled = True
166-
167-
threading.Thread(target=ListenerServer.start_server, daemon=True).start()
168-
169-
try:
170-
while True:
171-
time.sleep(1)
172-
except KeyboardInterrupt:
173-
logger.info("正在关闭...")
7+
start()

0 commit comments

Comments
 (0)