Commit Graph

64 Commits

Author SHA1 Message Date
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
雅诺狐
aeef71284b 去掉一行注释 2025-08-21 00:18:19 +08:00
雅诺狐
d26dd0fb2a 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-08-20 14:57:37 +08:00
minecraft1024a
ee0b61b8df fix(bot): 移除加权随机彩蛋功能。(不要再闲的没事动那beyond的彩蛋了) 2025-08-20 12:56:20 +08:00
tt-P607
17bbff8066 refactor(bot): 统一关闭逻辑到finally块
将优雅关闭(graceful_shutdown)的调用逻辑从`KeyboardInterrupt`异常处理块移动到`finally`块中。

这确保了无论程序是正常退出、收到中断信号,还是发生其他任何异常,都会尝试执行统一的、可靠的清理和关闭流程,从而增强了程序的健壮性。
2025-08-20 10:33:28 +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
1b2c5393e5 refactor(utils): 移除自定义加权随机函数并改用 random.choices
将原先在 `bot.py` 中实现的 `weighted_choice` 函数移除,并在 `src/main.py` 中改用 Python 内置的 `random.choices` 函数来实现启动时彩蛋的加权随机选择。

这一更改简化了代码,提高了可读性,并利用了标准库的优化实现。同时调整了彩蛋文本和对应的权重。
2025-08-19 12:15:24 +08:00
雅诺狐
5f87605eba Add rare easter egg message and adjust weights
Introduced a new rare easter egg message to the items list and updated the selection weights to make the new message extremely rare while adjusting the probabilities of the existing messages.
2025-08-19 12:05:32 +08:00
ikun两年半
3b295938e0 更新 bot.py
修改彩蛋权重喵~主打一个众生平等喵
2025-08-19 11:59:15 +08:00
雅诺狐
723a9d0098 Add weighted_choice utility and improve easter_egg randomness
Introduced a weighted_choice function for weighted random selection. Refactored the easter_egg function to use weighted_choice for more flexible and controlled message selection, replacing the previous randint-based logic.
2025-08-19 11:53:01 +08:00
minecraft1024a
5cce105acc feat(彩蛋): 增加彩蛋文本的随机性
在 `easter_egg` 函数中引入了随机数生成逻辑。
现在有20%的概率显示猫娘文本,80%的概率显示一个原有的文本,增加了趣味性。
2025-08-19 11:34:53 +08:00
ikun-11451
bfc131afdf 喵喵~ 2025-08-19 05:55:42 +08:00
minecraft1024a
cd3ccba8ad refactor(core): 调整数据库初始化时机
将数据库的初始化、表结构创建和自动迁移逻辑从配置文件加载时移动到主程序 `raw_main` 函数中。

这一改动旨在解决循环导入问题,并确保数据库在所有配置和核心模块加载完毕后才进行初始化,提高了程序的启动鲁棒性和模块独立性。
2025-08-17 15:59:56 +08:00
雅诺狐
2d4745cd58 初始化 2025-08-11 19:34:18 +08:00