Commit Graph

245 Commits

Author SHA1 Message Date
雅诺狐
679195d792 refactor(db): 修正SQLAlchemy异步操作调用方式
移除session.add()方法的不必要await调用,修正异步数据库操作模式。主要变更包括:

- 将 `await session.add()` 统一改为 `session.add()`
- 修正部分函数调用为异步版本(如消息查询函数)
- 重构SQLAlchemyTransaction为完全异步实现
- 重写napcat_adapter_plugin数据库层以符合异步规范
- 添加aiomysql和aiosqlite依赖支持
2025-11-19 23:05:17 +08:00
雅诺狐
0cffc0aa95 refactor(db): 将数据库操作异步化
- 将所有 session.add() 改为 await session.add()
- 将所有 session.commit() 改为 await session.commit()
- 将 session.refresh() 改为 await session.refresh()
2025-11-19 23:05:14 +08:00
tt-P607
5892ed1452 refactor(db): 重构数据库交互为异步模式
为了提升性能并与项目整体的异步架构保持一致,对核心数据库交互模块进行了异步化重构。

主要修改内容包括:
- 将 `PermissionManager` 中的所有数据库操作从同步改为异步,以避免阻塞事件循环。
- 使用 `async_sessionmaker` 和 `async with session` 替代原有的同步会话管理。
- 将 SQLAlchemy 查询语法更新为异步兼容的 `await session.execute(select(...))` 模式。
- 相应地,调用链中依赖数据库操作的多个方法也已更新为 `async` 函数。
2025-11-19 23:05:09 +08:00
雅诺狐
9ec8ea6310 Update message.py 2025-11-19 23:05:08 +08:00
雅诺狐
ca51182172 小修复 2025-11-19 23:05:07 +08:00
雅诺狐
26a4c492c3 将AFC合并至Master分支 2025-11-19 23:05:06 +08:00
tt-P607
d53238dfc9 4次修改 2025-11-19 23:05:02 +08:00
雅诺狐
93542cadef perf(methods): 通过移除不必要的 self 参数优化方法签名
在包括 chat、plugin_system、schedule 和 mais4u 在内的多个模块中,消除冗余的实例引用。此次改动将无需访问实例状态的实用函数转换为静态方法,从而提升了内存效率,并使方法依赖关系更加清晰。
2025-11-19 23:05:00 +08:00
tt-P607
aba4f1a947 三次修改 2025-11-19 23:02:01 +08:00
BuildTools
14a70496f7 feat(chat): 增强prompt构建功能并优化回复逻辑
- 为HfcContext和ChatStream添加focus_energy配置支持
- 修复默认回复生成器中识别自身消息的逻辑
- 完整实现prompt构建中的表达习惯、记忆、工具信息和知识模块
- 优化错误处理,使用原生异常链式传递
- 确保数据库操作中focus_energy字段的持久化

这些改进提升了聊天系统的上下文感知能力和回复质量,同时增强了模块的健壮性和可维护性。
2025-11-19 23:00:13 +08:00
Windpicker-owo
ea7d3b364f plugin_name改为permission_group 2025-11-19 22:59:12 +08:00
Windpicker-owo
3980509caa 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-11-19 22:58:17 +08:00
minecraft1024a
d66e04baff 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-11-19 22:57:44 +08:00
minecraft1024a
0172cf7b8b refactor(chat): 重构主动思考逻辑并将其集成到主聊天循环
将原有的 `ProactiveThinker` 类中的逻辑直接整合进 `HeartFChatting` 类中。此举简化了整体架构,减少了类之间的耦合,并使得主动思考的触发机制与主聊天循环的状态管理更加统一。

主要变更:
- 删除了独立的 `proactive_thinker.py` 文件。
- 将主动思考的监控循环、条件检查、动态间隔计算等功能实现为 `HeartFChatting` 的私有方法。
- 引入了 `ProactiveTriggerEvent` 事件,使触发源更加明确。
- 调整了相关模块的导入路径和配置项的调用方式,以适应新的结构。
2025-11-19 22:57:42 +08:00
Windpicker-owo
91454fe576 fix: at和回复只显示qq号的问题 2025-11-19 22:57:13 +08:00
Windpicker-owo
6cf59deef3 迁移:69a855d(feat:保存关键词到message数据库) 2025-11-19 22:56:10 +08:00
Windpicker-owo
276c08224e 迁移:685c759 (feat:将no_reply功能移动到主循环中) 2025-11-19 22:56:09 +08:00
minecraft1024a
50a458b9e1 refactor(context): 将能量值和睡眠压力状态持久化到数据库
将HFC上下文中的能量值(energy_value)和睡眠压力(sleep_pressure)的状态管理从本地文件存储(local_storage)迁移到主数据库。

这一重构的主要改动包括:
- 在`ChatStreams`数据库模型中添加`energy_value`和`sleep_pressure`字段。
- 更新`ChatStream`类,使其能够加载和保存这两个新字段。
- 移除`HfcContext`中原有的基于`local_storage`的加载和保存逻辑,改为直接通过`ChatStream`实例进行状态读写。
- 在`EnergyManager`中,每当能量或睡眠压力发生变化时,调用`save_context_state()`方法,确保状态能够实时持久化。

此举统一了应用的状态管理方式,提高了数据的可靠性和一致性,并为后续在多实例或分布式环境下部署应用奠定了基础。
2025-11-19 22:56:06 +08:00
Windpicker-owo
fe472dff60 修复代码格式和文件名大小写问题 2025-11-19 22:55:55 +08:00
Windpicker-owo
a3c07fb0f1 rust_video依赖检测 2025-11-19 22:53:57 +08:00
Windpicker-owo
e468dd1989 feat(plugin-system): 添加事件触发和订阅的白名单机制
为事件系统添加权限控制功能,包括:
- 在BaseEvent中新增allowed_subscribers和allowed_triggers白名单字段
- 事件管理器触发和订阅时进行白名单验证
- 为所有系统默认事件设置仅允许SYSTEM插件触发
- 在所有事件触发调用处显式传递plugin_name="SYSTEM"参数

确保只有授权插件可以触发特定事件和订阅处理器,增强系统安全性。
2025-11-19 22:49:20 +08:00
雅诺狐
a2873a71ef 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-11-19 22:48:49 +08:00
雅诺狐
ab3a36bfa7 全面更换orjson 2025-11-19 22:47:10 +08:00
tt-P607
88da5e24ca feat(config): 优化视频分析并引入可配置的提示词
将视频分析的提示词从硬编码字符串修改为从全局配置中读取,提高了灵活性和可维护性。同时,在生成回复时注入了新的引导语,使AI能以第一人称分享观后感,优化了用户体验。
2025-11-19 22:46:39 +08:00
Windpicker-owo
3bf38bb1dc 消息处理的细节 2025-11-19 22:46:33 +08:00
雅诺狐
8735bfbc88 feat: 添加视频处理多线程优化和消息切片重组功能
- 新增视频帧提取的线程池支持,提升大视频文件处理性能
- 集成消息切片重组器,支持长消息的自动重组处理
- 优化视频帧提取算法,使用numpy进行数值计算优化
- 重构权限管理插件,修复属性访问和方法签名问题
- 清理未使用的导入和代码,提升代码质量
- 默认启用插件管理功能
2025-11-19 22:46:27 +08:00
Windpicker-owo
5d1390d546 event重构暂时完成,待测试 2025-11-19 22:46:26 +08:00
雅诺狐
34252ea4a0 refactor: 清理代码质量和移除未使用文件
- 移除未使用的导入语句和变量
- 修复代码风格问题(空格、格式化等)
- 删除备份文件和测试文件
- 改进异常处理链式调用
- 添加权限系统数据库模型和配置
- 更新版本号至6.4.4
- 优化SQL查询使用正确的布尔表达式
2025-11-19 22:46:18 +08:00
雅诺狐
e39c34f366 fix: 修复视频分析并发处理和数据库存储问题
🔧 修复视频分析模块的关键并发和存储问题

**主要修复:**
1. **并发竞争条件修复**
   - 解决相同视频hash同时处理导致重复分析的问题
   - 重构并发控制机制,使用per-video独立锁和事件
   - 消除30秒超时后多个请求同时执行的竞争条件

2. **数据库存储优化**
   - 移除Videos表path字段的复杂唯一性检查逻辑
   - 简化为基于hash的纯唯一标识存储
   - 修复path字段重复导致的IntegrityError

3. **代码简化和清理**
   - 删除重编码视频检测功能(复杂且用处有限)
   - 移除不必要的特征匹配和计数更新逻辑
   - 简化存储路径生成,统一使用hash前缀

Fixes: 视频并发处理竞争条件、数据库存储冲突、聊天循环变量错误
2025-11-19 22:46:11 +08:00
雅诺狐
3360b22dca 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-11-19 22:46:06 +08:00
雅诺狐
1b9c86abef Refactor web search plugin and clean up code
Refactored the web search plugin by removing the old Bing search implementation and reorganizing the plugin structure. Introduced modular search engine classes under 'web_search_tool/engines' and utility tools under 'web_search_tool/tools' and 'web_search_tool/utils'. Updated references and initialization logic to support multiple search engines and improved maintainability. Also performed minor code cleanups and replaced 'except ...: pass' with 'except ...: ...' for brevity.
2025-11-19 22:45:42 +08:00
雅诺狐
31e028ab25 Refactor anti-injection system into modular subpackages
Split the anti-prompt-injector module into core, processors, management, and decision submodules for better maintainability and separation of concerns. Moved and refactored detection, shielding, statistics, user ban, message processing, and counter-attack logic into dedicated files. Updated imports and initialization in __init__.py and anti_injector.py to use the new structure. No functional changes to detection logic, but code organization is significantly improved.
2025-11-19 22:45:01 +08:00
雅诺狐
383f704b53 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-11-19 22:44:32 +08:00
minecraft1024a
d355153a19 feat(video): 视频识别功能开关与日志优化
根据全局配置 `global_config.video_analysis.enable` 控制视频识别功能的启用与禁用。

- 当视频识别功能禁用时,收到视频消息将直接返回 `[视频]` 或空字符串,不再进行分析,以节约资源。
2025-11-19 22:44:04 +08:00
minecraft1024a
d20daaf3e2 新增反击模式支持,允许在检测到提示词注入攻击时生成反击响应并发送。更新相关配置和处理逻辑,增强系统的防护能力。 2025-11-19 22:44:03 +08:00
雅诺狐
2d91a7d55c Refactor anti-injector process result handling
Introduced a ProcessResult enum to standardize anti-injector message processing outcomes. Updated anti_injector.py to return ProcessResult values instead of booleans, and refactored bot.py to handle these results with improved logging and clearer control flow. This change improves code clarity and maintainability for anti-prompt injection logic.
2025-11-19 22:43:58 +08:00
雅诺狐
16da725272 Add LLM anti-prompt injection system
Introduces a comprehensive anti-prompt injection system for LLMs, including rule-based and LLM-based detection, user ban/whitelist management, message shielding, and statistics tracking. Adds new modules under src/chat/antipromptinjector, integrates anti-injection checks into the message receive flow, updates configuration and database models, and provides test scripts. Also updates templates and logger aliases to support the new system.
2025-11-19 22:43:57 +08:00
雅诺狐
875e02d42f 数据库重构 2025-11-19 22:40:23 +08:00
minecraft1024a
38fed9b4cc 添加聊天类型限制功能,支持根据聊天类型过滤命令和动作,新增私聊和群聊专用命令及动作,优化相关日志记录。 2025-11-19 22:40:01 +08:00
Furina-1013-create
2d22b3d561 我靠我我视频识别怎么又给我炸了
--已重新修复......
2025-11-19 22:38:52 +08:00
雅诺狐
2dfd986ba4 Update storage.py 2025-11-19 22:37:40 +08:00
minecraft1024a
e6499e2fa7 修复interest_value为None的情况,确保在计算兴趣值时不会出现错误。将interest_value的默认值设置为0.0,以提高代码的健壮性。 2025-11-19 22:36:10 +08:00
雅诺狐
2e6ae2419b 优化项目结构,格式化代码 2025-11-19 22:35:40 +08:00
Furina-1013-create
2d1e131899 增加视频识别板块
采用抽帧的方式识别视频,可以自己配置详细参数 -详细请看bot_config最底下
更改了template模板
多bb一句:我真的是被这个炸服了,改完这里那里就又炸了,但是总之现在没问题了
2025-11-19 22:35:36 +08:00
雅诺狐
b966a2f09c 小修复 2025-11-19 22:35:34 +08:00
雅诺狐
4a1a1510c5 更新插件示例,及信息类型问题 2025-11-19 22:35:31 +08:00
雅诺狐
a588a2a695 添加了一个发送api 2025-11-19 22:35:26 +08:00
minecraft1024a
be13559563 fix(storage): 修复消息ID更新逻辑
将消息ID的更新逻辑从处理 "text" 和 "reply" 类型,调整为专门处理 "notify" 类型。
这确保了只有在收到通知类型的消息时才尝试获取和更新消息ID,避免了在其他消息类型上出现错误。
2025-11-19 22:35:19 +08:00
雅诺狐
23ee3767ef 初始化 2025-11-19 22:34:56 +08:00
UnCLAS-Prommer
1461338c0c typing fix 2025-08-13 22:51:34 +08:00