Skip to content

Commit 4fdbc77

Browse files
authored
Merge pull request #756 from MaiM-with-u/dev
Dev
2 parents 9959d36 + 42ccb3d commit 4fdbc77

101 files changed

Lines changed: 7953 additions & 5440 deletions

File tree

Some content is hidden

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

.github/workflows/ruff.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11
name: Ruff
22
on: [ push, pull_request ]
3+
4+
permissions:
5+
contents: write
6+
37
jobs:
48
ruff:
59
runs-on: ubuntu-latest
610
steps:
711
- uses: actions/checkout@v4
12+
with:
13+
fetch-depth: 0
14+
ref: ${{ github.head_ref || github.ref_name }}
815
- uses: astral-sh/ruff-action@v3
16+
- run: ruff check --fix
17+
- run: ruff format
18+
- name: Commit changes
19+
if: success()
20+
run: |
21+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
22+
git config --local user.name "github-actions[bot]"
23+
git add -A
24+
git diff --quiet && git diff --staged --quiet || git commit -m "🤖 自动格式化代码 [skip ci]"
25+
git push
926

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ message_queue_window.bat
2020
message_queue_window.txt
2121
queue_update.txt
2222
memory_graph.gml
23+
/src/do_tool/tool_can_use/auto_create_tool.py
24+
/src/do_tool/tool_can_use/execute_python_code_tool.py
2325
.env
2426
.env.*
2527
.cursor
@@ -28,6 +30,9 @@ config/bot_config.toml
2830
config/bot_config.toml.bak
2931
src/plugins/remote/client_uuid.json
3032
run_none.bat
33+
(测试版)麦麦生成人格.bat
34+
(临时版)麦麦开始学习.bat
35+
src/plugins/utils/statistic.py
3136
# Byte-compiled / optimized / DLL files
3237
__pycache__/
3338
*.py[cod]
@@ -237,3 +242,4 @@ logs
237242
/config/*
238243
run_none.bat
239244
config/old/bot_config_20250405_212257.toml
245+

CLAUDE.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Commands
6+
- **Run Bot**: `python bot.py`
7+
- **Lint**: `ruff check --fix .` or `ruff format .`
8+
- **Run Tests**: `python -m unittest discover -v`
9+
- **Run Single Test**: `python -m unittest src/plugins/message/test.py`
10+
11+
## Code Style
12+
- **Formatting**: Line length 120 chars, use double quotes for strings
13+
- **Imports**: Group standard library, external packages, then internal imports
14+
- **Naming**: snake_case for functions/variables, PascalCase for classes
15+
- **Error Handling**: Use try/except blocks with specific exceptions
16+
- **Types**: Use type hints where possible
17+
- **Docstrings**: Document classes and complex functions
18+
- **Linting**: Follow ruff rules (E, F, B) with ignores E711, E501
19+
20+
When making changes, run `ruff check --fix .` to ensure code follows style guidelines. The codebase uses Ruff for linting and formatting.

README.md

Lines changed: 96 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,81 @@
11
# 麦麦!MaiCore-MaiMBot (编辑中)
2-
3-
## 新版0.6.0部署前先阅读:https://docs.mai-mai.org/manual/usage/mmc_q_a
4-
2+
<br />
53
<div align="center">
64

7-
![Python Version](https://img.shields.io/badge/Python-3.9+-blue)
8-
![License](https://img.shields.io/github/license/SengokuCola/MaiMBot)
9-
![Status](https://img.shields.io/badge/状态-开发中-yellow)
5+
![Python Version](https://img.shields.io/badge/Python-3.10+-blue)
6+
![License](https://img.shields.io/github/license/SengokuCola/MaiMBot?label=协议)
7+
![Status](https://img.shields.io/badge/状态-开发中-yellow)
8+
![Contributors](https://img.shields.io/github/contributors/MaiM-with-u/MaiBot.svg?style=flat&label=贡献者)
9+
![forks](https://img.shields.io/github/forks/MaiM-with-u/MaiBot.svg?style=flat&label=分支数)
10+
![stars](https://img.shields.io/github/stars/MaiM-with-u/MaiBot?style=flat&label=星标数)
11+
![issues](https://img.shields.io/github/issues/MaiM-with-u/MaiBot)
12+
13+
</div>
14+
15+
<p align="center">
16+
<a href="https://github.com/MaiM-with-u/MaiBot/">
17+
<img src="depends-data/maimai.png" alt="Logo" width="200">
18+
</a>
19+
<br />
20+
<a href="https://space.bilibili.com/1344099355">
21+
画师:略nd
22+
</a>
23+
24+
<h3 align="center">MaiBot(麦麦)</h3>
25+
<p align="center">
26+
一款专注于<strong> 群组聊天 </strong>的赛博网友
27+
<br />
28+
<a href="https://docs.mai-mai.org"><strong>探索本项目的文档 »</strong></a>
29+
<br />
30+
<br />
31+
<!-- <a href="https://github.com/shaojintian/Best_README_template">查看Demo</a>
32+
· -->
33+
<a href="https://github.com/MaiM-with-u/MaiBot/issues">报告Bug</a>
34+
·
35+
<a href="https://github.com/MaiM-with-u/MaiBot/issues">提出新特性</a>
36+
</p>
37+
38+
</p>
39+
40+
## 新版0.6.x部署前先阅读:https://docs.mai-mai.org/manual/usage/mmc_q_a
1041

11-
</div>
1242

1343
## 📝 项目简介
1444

1545
**🍔MaiCore是一个基于大语言模型的可交互智能体**
1646

17-
- LLM 提供对话能力
18-
- 动态Prompt构建器
19-
- 实时的思维系统
20-
- MongoDB 提供数据持久化支持
21-
- 可扩展,可支持多种平台和多种功能
2247

23-
**最新版本: v0.6.0** ([查看更新日志](changelogs/changelog.md))
48+
- 💭 **智能对话系统**:基于LLM的自然语言交互
49+
- 🤔 **实时思维系统**:模拟人类思考过程
50+
- 💝 **情感表达系统**:丰富的表情包和情绪表达
51+
- 🧠 **持久记忆系统**:基于MongoDB的长期记忆存储
52+
- 🔄 **动态人格系统**:自适应的性格特征
53+
54+
<div align="center">
55+
<a href="https://www.bilibili.com/video/BV1amAneGE3P" target="_blank">
56+
<img src="depends-data/video.png" width="200" alt="麦麦演示视频">
57+
<br>
58+
👆 点击观看麦麦演示视频 👆
59+
</a>
60+
</div>
61+
62+
63+
### 📢 版本信息
64+
65+
**最新版本: v0.6.2** ([查看更新日志](changelogs/changelog.md))
2466
> [!WARNING]
2567
> 请阅读教程后更新!!!!!!!
2668
> 请阅读教程后更新!!!!!!!
2769
> 请阅读教程后更新!!!!!!!
2870
> 次版本MaiBot将基于MaiCore运行,不再依赖于nonebot相关组件运行。
2971
> MaiBot将通过nonebot的插件与nonebot建立联系,然后nonebot与QQ建立联系,实现MaiBot与QQ的交互
3072
31-
**分支介绍:**
32-
- main 稳定版本
33-
- dev 开发版(不知道什么意思就别下)
34-
- classical 0.6.0以前的版本
73+
**分支说明:**
74+
- `main`: 稳定发布版本
75+
- `dev`: 开发测试版本(不知道什么意思就别下)
76+
- `classical`: 0.6.0之前的版本
3577

36-
<div align="center">
37-
<a href="https://www.bilibili.com/video/BV1amAneGE3P" target="_blank">
38-
<img src="docs/pic/video.png" width="300" alt="麦麦演示视频">
39-
<br>
40-
👆 点击观看麦麦演示视频 👆
4178

42-
</a>
43-
</div>
4479

4580
> [!WARNING]
4681
> - 项目处于活跃开发阶段,代码可能随时更改
@@ -49,6 +84,12 @@
4984
> - 由于持续迭代,可能存在一些已知或未知的bug
5085
> - 由于开发中,可能消耗较多token
5186
87+
### ⚠️ 重要提示
88+
89+
- 升级到v0.6.x版本前请务必阅读:[升级指南](https://docs.mai-mai.org/manual/usage/mmc_q_a)
90+
- 本版本基于MaiCore重构,通过nonebot插件与QQ平台交互
91+
- 项目处于活跃开发阶段,功能和API可能随时调整
92+
5293
### 💬交流群(开发和建议相关讨论)不一定有空回复,会优先写文档和代码
5394
- [五群](https://qm.qq.com/q/JxvHZnxyec) 1022489779
5495
- [一群](https://qm.qq.com/q/VQ3XZrWgMs) 766798517 【已满】
@@ -67,60 +108,41 @@
67108
- [📚 核心Wiki文档](https://docs.mai-mai.org) - 项目最全面的文档中心,你可以了解麦麦有关的一切
68109

69110
### 最新版本部署教程(MaiCore版本)
70-
- [🚀 最新版本部署教程](https://docs.mai-mai.org/manual/deployment/mmc_deploy.html) - 基于MaiCore的新版本部署方式(与旧版本不兼容)
111+
- [🚀 最新版本部署教程](https://docs.mai-mai.org/manual/deployment/mmc_deploy_windows.html) - 基于MaiCore的新版本部署方式(与旧版本不兼容)
71112

72113

73114
## 🎯 功能介绍
74115

75-
### 💬 聊天功能
76-
- 提供思维流(心流)聊天和推理聊天两种对话逻辑
77-
- 支持关键词检索主动发言:对消息的话题topic进行识别,如果检测到麦麦存储过的话题就会主动进行发言
78-
- 支持bot名字呼唤发言:检测到"麦麦"会主动发言,可配置
79-
- 支持多模型,多厂商自定义配置
80-
- 动态的prompt构建器,更拟人
81-
- 支持图片,转发消息,回复消息的识别
82-
- 支持私聊功能,可使用PFC模式的有目的多轮对话(实验性)
83-
84-
### 🧠 思维流系统
85-
- 思维流能够在回复前后进行思考,生成实时想法
86-
- 思维流自动启停机制,提升资源利用效率
87-
- 思维流与日程系统联动,实现动态日程生成
88-
89-
### 🧠 记忆系统 2.0
90-
- 优化记忆抽取策略和prompt结构
91-
- 改进海马体记忆提取机制,提升自然度
92-
- 对聊天记录进行概括存储,在需要时调用
93-
94-
### 😊 表情包系统
95-
- 支持根据发言内容发送对应情绪的表情包
96-
- 支持识别和处理gif表情包
97-
- 会自动偷群友的表情包
98-
- 表情包审查功能
99-
- 表情包文件完整性自动检查
100-
- 自动清理缓存图片
101-
102-
### 📅 日程系统
103-
- 动态更新的日程生成
104-
- 可自定义想象力程度
105-
- 与聊天情况交互(思维流模式下)
106-
107-
### 👥 关系系统 2.0
108-
- 优化关系管理系统,适用于新版本
109-
- 提供更丰富的关系接口
110-
- 针对每个用户创建"关系",实现个性化回复
111-
112-
### 📊 统计系统
113-
- 详细的使用数据统计
114-
- LLM调用统计
115-
- 在控制台显示统计信息
116-
117-
### 🔧 系统功能
118-
- 支持优雅的shutdown机制
119-
- 自动保存功能,定期保存聊天记录和关系数据
120-
- 完善的异常处理机制
121-
- 可自定义时区设置
122-
- 优化的日志输出格式
123-
- 配置自动更新功能
116+
| 模块 | 主要功能 | 特点 |
117+
|------|---------|------|
118+
| 💬 聊天系统 | • 心流/推理聊天<br>• 关键词主动发言<br>• 多模型支持<br>• 动态prompt构建<br>• 私聊功能(PFC) | 拟人化交互 |
119+
| 🧠 心流系统 | • 实时思考生成<br>• 自动启停机制<br>• 日程系统联动<br>• 工具调用能力 | 智能化决策 |
120+
| 🧠 记忆系统 | • 优化记忆抽取<br>• 海马体记忆机制<br>• 聊天记录概括 | 持久化记忆 |
121+
| 😊 表情系统 | • 情绪匹配发送<br>• GIF支持<br>• 自动收集与审查 | 丰富表达 |
122+
| 📅 日程系统 | • 动态日程生成<br>• 自定义想象力<br>• 思维流联动 | 智能规划 |
123+
| 👥 关系系统 | • 关系管理优化<br>• 丰富接口支持<br>• 个性化交互 | 深度社交 |
124+
| 📊 统计系统 | • 使用数据统计<br>• LLM调用记录<br>• 实时控制台显示 | 数据可视 |
125+
| 🔧 系统功能 | • 优雅关闭机制<br>• 自动数据保存<br>• 异常处理完善 | 稳定可靠 |
126+
| 🛠️ 工具系统 | • 知识获取工具<br>• 自动注册机制<br>• 多工具支持 | 扩展功能 |
127+
128+
## 📐 项目架构
129+
130+
```mermaid
131+
graph TD
132+
A[MaiCore] --> B[对话系统]
133+
A --> C[心流系统]
134+
A --> D[记忆系统]
135+
A --> E[情感系统]
136+
B --> F[多模型支持]
137+
B --> G[动态Prompt]
138+
C --> H[实时思考]
139+
C --> I[日程联动]
140+
D --> J[记忆存储]
141+
D --> K[记忆检索]
142+
E --> L[表情管理]
143+
E --> M[情绪识别]
144+
```
145+
124146

125147
## 开发计划TODO:LIST
126148

@@ -157,7 +179,6 @@ MaiCore是一个开源项目,我们非常欢迎你的参与。你的贡献,
157179
158180
## 致谢
159181

160-
- [nonebot2](https://github.com/nonebot/nonebot2): 跨平台 Python 异步聊天机器人框架
161182
- [NapCat](https://github.com/NapNeko/NapCatQQ): 现代化的基于 NTQQ 的 Bot 协议端实现
162183

163184
### 贡献者

bot.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@
77
import time
88
import platform
99
from dotenv import load_dotenv
10-
from src.common.logger import get_module_logger
10+
from src.common.logger import get_module_logger, LogConfig, CONFIRM_STYLE_CONFIG
11+
from src.common.crash_logger import install_crash_handler
1112
from src.main import MainSystem
1213

1314
logger = get_module_logger("main_bot")
14-
15+
confirm_logger_config = LogConfig(
16+
console_format=CONFIRM_STYLE_CONFIG["console_format"],
17+
file_format=CONFIRM_STYLE_CONFIG["file_format"],
18+
)
19+
confirm_logger = get_module_logger("confirm", config=confirm_logger_config)
1520
# 获取没有加载env时的环境变量
1621
env_mask = {key: os.getenv(key) for key in os.environ}
1722

@@ -165,8 +170,8 @@ def check_eula():
165170

166171
# 如果EULA或隐私条款有更新,提示用户重新确认
167172
if eula_updated or privacy_updated:
168-
print("EULA或隐私条款内容已更新,请在阅读后重新确认,继续运行视为同意更新后的以上两款协议")
169-
print(
173+
confirm_logger.critical("EULA或隐私条款内容已更新,请在阅读后重新确认,继续运行视为同意更新后的以上两款协议")
174+
confirm_logger.critical(
170175
f'输入"同意"或"confirmed"或设置环境变量"EULA_AGREE={eula_new_hash}"和"PRIVACY_AGREE={privacy_new_hash}"继续运行'
171176
)
172177
while True:
@@ -175,14 +180,14 @@ def check_eula():
175180
# print("确认成功,继续运行")
176181
# print(f"确认成功,继续运行{eula_updated} {privacy_updated}")
177182
if eula_updated:
178-
print(f"更新EULA确认文件{eula_new_hash}")
183+
logger.info(f"更新EULA确认文件{eula_new_hash}")
179184
eula_confirm_file.write_text(eula_new_hash, encoding="utf-8")
180185
if privacy_updated:
181-
print(f"更新隐私条款确认文件{privacy_new_hash}")
186+
logger.info(f"更新隐私条款确认文件{privacy_new_hash}")
182187
privacy_confirm_file.write_text(privacy_new_hash, encoding="utf-8")
183188
break
184189
else:
185-
print('请输入"同意"或"confirmed"以继续运行')
190+
confirm_logger.critical('请输入"同意"或"confirmed"以继续运行')
186191
return
187192
elif eula_confirmed and privacy_confirmed:
188193
return
@@ -193,6 +198,9 @@ def raw_main():
193198
if platform.system().lower() != "windows":
194199
time.tzset()
195200

201+
# 安装崩溃日志处理器
202+
install_crash_handler()
203+
196204
check_eula()
197205
print("检查EULA和隐私条款完成")
198206
easter_egg()

0 commit comments

Comments
 (0)