Commit Graph

49 Commits

Author SHA1 Message Date
tt-P607
8d9aa4fb9e refactor(db): 重构数据库交互为异步模式
为了提升性能并与项目整体的异步架构保持一致,对核心数据库交互模块进行了异步化重构。

主要修改内容包括:
- 将 `PermissionManager` 中的所有数据库操作从同步改为异步,以避免阻塞事件循环。
- 使用 `async_sessionmaker` 和 `async with session` 替代原有的同步会话管理。
- 将 SQLAlchemy 查询语法更新为异步兼容的 `await session.execute(select(...))` 模式。
- 相应地,调用链中依赖数据库操作的多个方法也已更新为 `async` 函数。
2025-09-20 13:07:06 +08:00
雅诺狐
898208f425 perf(methods): 通过移除不必要的 self 参数优化方法签名
在包括 chat、plugin_system、schedule 和 mais4u 在内的多个模块中,消除冗余的实例引用。此次改动将无需访问实例状态的实用函数转换为静态方法,从而提升了内存效率,并使方法依赖关系更加清晰。
2025-09-20 10:55:06 +08:00
Windpicker-owo
02a636a8ce plugin_name改为permission_group 2025-09-07 19:03:42 +08:00
Windpicker-owo
742b47c099 fix:修复插件组件无法正确获取插件配置的问题 2025-09-06 20:39:59 +08:00
Windpicker-owo
41dc58d4fb 继续尝试迁移,但是组件获取插件配置存在问题 2025-09-06 05:45:00 +08:00
Windpicker-owo
90cbd5773e Merge branch 'dev' of https://github.com/MoFox-Studio/MoFox_Bot into dev 2025-09-06 00:11:31 +08:00
Windpicker-owo
c9b712d8fa refactor(prompt): 重构并统一提示词系统
- 删除旧的智能提示词系统(smart_prompt.py)和相关参数模块(prompt_parameters.py)
- 将 prompt_builder.py 重命名为 prompt.py 并精简功能
- 更新所有模块的导入路径从 `src.chat.utils.prompt_builder` 到 `src.chat.utils.prompt`
- 统一提示词构建接口,使用新的 PromptContext 替代 SmartPromptParameters
- 移除重复和冗余代码,简化系统架构

BREAKING CHANGE: 旧的 SmartPrompt 系统已被完全移除,所有相关模块需要改用新的统一 Prompt 系统
2025-09-06 00:10:54 +08:00
minecraft1024a
e1fbdaad8c rrrrrrrrrrrrrruuuuuuuuuuuuuuuuuuuuffffffffffffffffffffffffff 2025-09-05 21:01:32 +08:00
minecraft1024a
513757a8ee chore: format code and remove redundant blank lines
This commit applies automated code formatting across the project. The changes primarily involve removing unnecessary blank lines and ensuring consistent code style, improving readability and maintainability without altering functionality.
2025-09-05 20:58:03 +08:00
tt-P607
da4dd63fd3 feat(plugin_system): 实现 on_plugin_loaded 异步钩子
在插件成功加载和注册后,添加一个新的生命周期钩子 `on_plugin_loaded`。

此钩子允许插件在加载完成后执行异步的初始化任务,例如建立数据库连接、加载数据或启动后台服务。通过使用 `asyncio.create_task`,确保了钩子的执行不会阻塞插件的加载流程,从而提高了系统的响应性和健壮性。
2025-09-01 11:38:20 +08:00
Windpicker-owo
30e66d5938 Merge branch 'master' of https://github.com/MoFox-Studio/MoFox_Bot 2025-08-31 20:56:35 +08:00
Windpicker-owo
8149731925 修复代码格式和文件名大小写问题 2025-08-31 20:50:17 +08:00
Windpicker-owo
2dee32e5ad feat(chat): 引入SmartPrompt智能提示构建系统
重构DefaultReplyer对话提示构建逻辑,统一使用SmartPrompt抽象组件替代原冗长的模板选择与参数拼装流程。将原160+行的分支式模板处理逻辑压缩为统一的SmartPrompt.build_prompt()调用,实现提示构建策略的可插拔与可维护性提升。

- 新增 src.chat.utils.smart_prompt 模块(SmartPrompt类及参数封装)
- 移除旧的normal/s4u分支硬编码,由SmartPrompt内部按需适配
- 事件管理器仅补充HandlerResult显式导入,无功能变动
2025-08-31 15:33:16 +08:00
minecraft1024a
cc2d8a89ee chore: 调整日志级别和更新默认配置
- 将事件注册成功的日志级别从INFO调整为DEBUG,以减少不必要的日志输出。
- 修正`maizone_refactored`插件中图片目录路径的表示方法,使用`.as_posix()`确保跨平台兼容性。
- 将备用Cookie获取服务的默认主机地址从一个具体的IP(`172.20.130.55`)更改为`127.0.0.1`,这更符合本地开发的通用配置。
2025-08-31 12:40:50 +08:00
minecraft1024a
901a3f0ed5 refactor(plugin_system): 重构插件配置同步逻辑
将插件配置同步逻辑重构为更清晰、更健壮的实现。此更改将复杂的同步过程分解为两个独立的、职责单一的方法:

- `_sync_central_config_to_plugin`: 专注于将中央配置单向同步到插件目录。
- `_is_file_content_identical`: 提供一个高效的文件内容比较方法,通过MD5哈希值避免不必要的IO操作。

这种重构提高了代码的可读性、可维护性,并增强了错误处理能力。同时,代码库从 `os.path` 迁移到了现代的 `pathlib`,以实现更简洁、更面向对象的路径操作。
2025-08-30 20:57:00 +08:00
minecraft1024a
589638200f 紧急修复一下我写出来的问题,修复同步插件配置文件时配置文件路径错误的问题 2025-08-30 20:43:31 +08:00
Windpicker-owo
7b765d5726 ruff 2025-08-30 19:59:54 +08:00
minecraft1024a
7cb5c3844e refactor(plugin): 优化插件配置加载与同步机制
- 移除全局插件配置开关 `plugins.centralized_config`。
- 简化 `PluginBase` 的配置加载逻辑,不再使用模板文件,而是直接在中央配置目录生成默认配置。
- 在 `PluginManager` 中增加配置同步逻辑,在加载插件时,实现插件目录与中央配置目录之间的双向同步,确保配置一致性。
- 更新 `bot_config_template.toml`,移除已废弃的 `[plugins]` 配置项并提升版本号。
2025-08-30 11:21:26 +08:00
minecraft1024a
1bad63fcbd ruff ci 2025-08-29 18:34:13 +08:00
雅诺狐
f33bb57c75 Merge branch 'master' of https://github.com/MoFox-Studio/MoFox_Bot 2025-08-29 13:48:01 +08:00
雅诺狐
865159ece3 Refactor plugin system and update permission checks
Removed the permission_example plugin and its files. Refactored plugin hot reload and manager logic for more robust reloading, deep reload, and cache clearing, including improved debounce and plugin name resolution. Updated MaiZone plugin and actions to use the new permission API for feed read/send actions, and registered new permission nodes. Enhanced plugin management commands with PlusCommand, improved help, and added hot reload and cache management commands.
2025-08-29 13:47:54 +08:00
Windpicker-owo
8c660934d0 Merge branch 'master' of https://github.com/MoFox-Studio/MoFox_Bot 2025-08-28 21:05:17 +08:00
minecraft1024a
add68fcf58 docs: remove outdated and unused documentation files
A significant number of documentation files, including design documents, user guides, and old images, have been removed to clean up the repository and eliminate outdated information. This reduces clutter and ensures that the documentation accurately reflects the current state of the project.

Key removals include:
- `memory_system_design_v3.md`
- `model_configuration_guide.md`
- `PERMISSION_SYSTEM.md`
- `CONTRIBUTE.md`
- `vector_db_usage_guide.md
2025-08-28 20:41:44 +08:00
minecraft1024a
eb1feeeb0b refactor(cache): 重构工具缓存机制并优化LLM请求重试逻辑
将工具缓存的实现从`ToolExecutor`的装饰器模式重构为直接集成。缓存逻辑被移出`cache_manager.py`并整合进`ToolExecutor.execute_tool_call`方法中,简化了代码结构并使其更易于维护。

主要变更:
- 从`cache_manager.py`中移除了`wrap_tool_executor`函数。
- 在`tool_use.py`中,`execute_tool_call`现在包含完整的缓存检查和设置逻辑。
- 调整了`llm_models/utils_model.py`中的LLM请求逻辑,为模型生成的空回复或截断响应增加了内部重试机制,增强了稳定性。
- 清理了项目中未使用的导入和过时的文档文件,以保持代码库的整洁。
2025-08-28 20:10:32 +08:00
Windpicker-owo
b3176fea40 修复event权限,现在每个component都拥有plugin_name属性 2025-08-28 19:52:08 +08:00
Windpicker-owo
2e2fd90497 feat(plugin-system): 添加事件触发和订阅的白名单机制
为事件系统添加权限控制功能,包括:
- 在BaseEvent中新增allowed_subscribers和allowed_triggers白名单字段
- 事件管理器触发和订阅时进行白名单验证
- 为所有系统默认事件设置仅允许SYSTEM插件触发
- 在所有事件触发调用处显式传递plugin_name="SYSTEM"参数

确保只有授权插件可以触发特定事件和订阅处理器,增强系统安全性。
2025-08-28 18:25:33 +08:00
Windpicker-owo
786a830da5 fix(plugin): 为事件处理器添加异步锁和并行执行支持
在BaseEvent类中引入asyncio.Lock确保同一个事件不能同时激活多次
重构事件触发逻辑,使用asyncio.gather并行执行所有订阅者处理器
提高事件处理效率的同时保证线程安全
2025-08-28 17:18:01 +08:00
Windpicker-owo
935a82fa58 引入lock防止同一个事件同时触发 2025-08-28 16:57:25 +08:00
雅诺狐
1d48478e79 Add PlusCommand enhanced command system
Introduces the PlusCommand system for simplified command development, including new base classes, argument parsing utilities, and registration logic. Updates the plugin system, component registry, and bot message handling to support PlusCommand components alongside traditional commands. Adds documentation and configuration for command prefixes, and provides a developer guide for the new system.
2025-08-27 22:21:03 +08:00
minecraft1024a
5076410a00 Reapply "【迁移】工具系统再完善:工具缓存、ttl支持、自动记录、长期保存、自动清理缓存、将记录与执行分离、api记录查询、时间聊天工具筛选查询..."
This reverts commit 3d93bc4079.
2025-08-27 17:58:18 +08:00
Furina-1013-create
9fca087b2c feat(plugin_system): 增加工具执行日志记录
feat(plugin_system): 增加工具执行日志记录

在工具执行前添加一行日志,用于记录正在调用的工具名称和参数,方便调试和追踪。
2025-08-27 17:10:56 +08:00
Windpicker-owo
3d93bc4079 Revert "【迁移】工具系统再完善:工具缓存、ttl支持、自动记录、长期保存、自动清理缓存、将记录与执行分离、api记录查询、时间聊天工具筛选查询..."
This reverts commit 80ab0c687c.
2025-08-27 12:46:00 +08:00
Windpicker-owo
80ab0c687c 【迁移】工具系统再完善:工具缓存、ttl支持、自动记录、长期保存、自动清理缓存、将记录与执行分离、api记录查询、时间聊天工具筛选查询... 2025-08-27 11:04:20 +08:00
minecraft1024a
1e037e5ce9 feat(maizone): 新增QQ空间互通组功能,根据聊天上下文生成说说
引入了全新的“QQ空间互通组”功能。用户可以配置多个群聊为一个互通组。
在通过指令发布说说时,系统会自动获取这些群聊的近期聊天记录作为上下文,从而生成与当前讨论话题更相关的说说内容。

- 在 `config.toml` 中新增了 `[maizone_intercom]` 配置项用于定义互通组。
- 重构并增强了动态(说说)的拉取逻辑,提高了对不同数据格式的兼容性和解析的稳定性。
- 对项目中的多个文件进行了代码清理,移除了未使用的导入,使代码更加整洁。
2025-08-26 20:20:54 +08:00
Windpicker-owo
084a425a4f 注册EventHandler组件 2025-08-25 18:18:54 +08:00
Windpicker-owo
cbf9a21c1f event重构暂时完成,待测试 2025-08-25 17:46:23 +08:00
Windpicker-owo
faf13e39b6 feat: 迁移Windpicker-owo的Event系统重构\n\n- 引入新的BaseEvent和HandlerResult架构\n- 实现灵活的事件订阅与激活机制\n- 添加事件管理器单例模式\n- 支持事件缓存和权重排序\n- 统一事件处理接口 2025-08-25 16:42:34 +08:00
雅诺狐
38b64eb339 Update permission_manager.py 2025-08-24 22:44:48 +08:00
雅诺狐
f308adcf5b refactor: 清理代码质量和移除未使用文件
- 移除未使用的导入语句和变量
- 修复代码风格问题(空格、格式化等)
- 删除备份文件和测试文件
- 改进异常处理链式调用
- 添加权限系统数据库模型和配置
- 更新版本号至6.4.4
- 优化SQL查询使用正确的布尔表达式
2025-08-24 22:11:20 +08:00
雅诺狐
8d8d9fbda1 Refactor anti-injection system and remove command skip list
Removed the command skip list feature and related code from the anti-injection system, including configuration options, plugin command collection, and management commands. Refactored anti-injector logic to operate directly on message dictionaries and simplified whitelist and message content extraction. Updated response handling to perform anti-injection checks before reply generation, and removed skip list refresh logic from the plugin manager.
2025-08-22 15:48:21 +08:00
minecraft1024a
87ee286614 refactor(cleanup): 移除未使用的导入项与冗余代码
清理了整个代码库中所有无用的模块导入、重复定义以及冗余变量引用,具体包括:
- bot.py 去掉了 random、typing 的未使用 import
- antipromptinjector 模块统一移除未引用的 DetectionResult、Dict、List 等
- chat_loop 中删除了未调用的 Timer、mai_thinking_manager、events_manager 等引用
- qzone_service 删除多余 f-string 大括号,避免日志警告格式问题
- 其他模块同步剔除各自范围内的冗余 import(asyncio、datetime 等共 20+ 处)

保持功能不变,仅作代码整洁度优化,无破坏性变更。(并添加了一个现在暂时还没加进去的必应搜索源文件)
2025-08-21 21:09:52 +08:00
雅诺狐
5265132cb6 Improve anti-injection detection logging and text extraction
Added detailed debug logs for text extraction and LLM detection input in the anti-injector module. Refactored message processing to only use user-added content for detection, avoiding duplicate text. Fixed import paths for command_skip_list in plugin manager and anti_injector_manager to reflect new module structure.
2025-08-20 15:53:10 +08:00
雅诺狐
1405b50d5a Refactor config system to use Pydantic validation
Refactored configuration classes to inherit from a new ValidatedConfigBase using Pydantic for robust validation and error reporting. Updated api_ada_configs.py, config.py, config_base.py, and official_configs.py to replace dataclasses with Pydantic models, add field validation, and improve error messages. This change enhances configuration reliability and developer feedback for misconfigurations. Also includes minor code cleanups and removal of unused variables in other modules.
2025-08-19 15:33:43 +08:00
minecraft1024a
5ef9a42f78 refactor(chat): 禁用工具执行器的缓存功能(因为这玩意真的没几次命中过的) 2025-08-19 12:06:00 +08:00
雅诺狐
5e91f9ef5f Remove unused imports across multiple modules
Cleaned up various files by removing unused or redundant import statements to improve code readability and reduce potential confusion. No functional changes were made.
2025-08-19 11:55:24 +08:00
tt-P607
15ae0ea609 <Thinking>
我需要分析这个git diff,并生成一个与之前完全不同的commit message。

让我先分析变更内容:

1. **主要变更**:
   - 在 `anti_injector.py` 中添加了新的 `auto` 处理模式
   - 添加了命令跳过列表功能 (`command_skip_list`)
   - 重构了反注入管理命令,从独立插件移动到核心动作插件
   - 更新了配置文件以支持新功能
   - 在插件管理器中添加了跳过列表刷新逻辑

2. **之前的commit message重点**:
   - 强调了"advanced anti-injection capabilities"
   - 重点描述了"intelligent 'auto' mode"
   - 提到了"command skip list"
   - 强调了"dynamically assesses threats"
   - 提到了"refactored and integrated into core actions plugin"

3. **我需要完全不同的角度**:
   - 可以从架构重构的角度
   - 可以从用户体验改进的角度
   - 可以从系统集成的角度
   - 可以从性能优化的角度

让我从**系统架构优化和插件整合**的角度来写这个commit message,重点强调:
- 插件系统的重构和整合
- 管理命令的迁移和统一
- 跳过机制的实现
- 自动化决策系统的引入

这样就能避免使用之前message中的关键词和结构。
</Thinking>

refactor(plugins): 重构反注入插件架构并优化命令管理体系

将反注入管理功能从独立插件迁移至核心动作模块,实现更好的系统集成。新增智能跳过机制,允许已注册的插件命令绕过检测流程,有效减少误判。同时引入自适应处理策略,系统可根据威胁评估结果自主选择最适当的响应方式。

插件管理器现已集成自动刷新功能,确保跳过列表与插件状态保持同步。配置系统扩展支持多种跳过模式和自定义规则,提升了整体可维护性和用户体验。
ps:谢谢雅诺狐姐姐投喂的提交喵^ω^
2025-08-18 21:49:17 +08:00
minecraft1024a
ee66fbe827 优化插件热重载管理,支持多个监听目录 2025-08-14 13:43:22 +08:00
雅诺狐
4da66f39c9 小修复 2025-08-12 22:38:26 +08:00
雅诺狐
2d4745cd58 初始化 2025-08-11 19:34:18 +08:00