refactor(plugins): comprehensive code review - ~35 fixes across 14 plugins

Phase 1 - Plugin code review (14/14 plugins):
- Security: 3x token leak in print→logger.debug, Bearer prefix handling
- Bug: bare except→specific exceptions, HorseState type safety, sync→async
- Critical: response_model undefined, route dead code, sync blocking event loop
- Quality: 11x print()→logger, variable name shadowing, consistent logging

Phase 2 - Deep analysis:
- Fix: payout int truncation→max(1, round(amount*odds))
- Fix: room_store get_lock race condition→dict.setdefault()
- Verify: data_manager f-string SQL is safe (uses ? placeholders)

Infrastructure: review reports generated for all plugins.
This commit is contained in:
2026-05-09 23:22:28 +08:00
parent 9a8cb3ad6d
commit c01338f496
43 changed files with 4233 additions and 3645 deletions

View File

@@ -0,0 +1,64 @@
# Danding-Bot 插件代码评审报告 - Round 1
**日期**: 2026-05-09
**评审人**: Agent
**进度**: 2/13 插件已完成
---
## 1. auto_friend_accept ✅ 已完成
### 发现问题 (4项)
| # | 严重度 | 问题 | 文件 | 行号 |
|---|--------|------|------|------|
| 1 | 低 | 导入`validator`但未使用 | config.py | 1 |
| 2 | 中 | `Optional[str] = ""`语义不清None和空串应区分 | config.py | 9 |
| 3 | 低 | 导入`T_State`但未使用 | auto_accept.py | 3 |
| 4 | 高 | 嵌套try-except缩进深违反篇幅分布原则 | auto_accept.py | 23-48 |
| 5 | 中 | 随机延迟硬编码(2-5s),应可配置 | auto_accept.py | 35 |
| 6 | 中 | 日志缺少flag标识出问题难追溯 | auto_accept.py | 全局 |
### 修复项
- 移除未使用的`validator`导入
- `auto_reply_message`默认值改为`None`
- 新增`reply_delay_min/max`配置项
- 移除未使用的`T_State`导入
- 消除嵌套try-except扁平化控制流
- 日志加入`user_id``flag`标识
### 待改进
- 无明显待改进项
---
## 2. auto_recall ✅ 已完成
### 发现问题 (6项)
| # | 严重度 | 问题 | 文件 | 行号 |
|---|--------|------|------|------|
| 1 | 中 | `Bot`重复导入line 4和7覆盖 | __init__.py | 4,7 |
| 2 | 低 | `T_State`导入未使用 | __init__.py | 8 |
| 3 | 低 | `get_driver`导入未使用 | __init__.py | 3 |
| 4 | 高 | `asyncio.create_task`未保存引用可能被GC回收触发RuntimeWarning | __init__.py | 48 |
| 5 | 高 | 撤回失败用`"success" in str(e).lower()`判断忽略,极其脆弱 | __init__.py | 56 |
| 6 | 低 | 未拦截`send_private_msg`,私聊消息不会撤回 | __init__.py | 26 |
| 7 | 低 | 配置无边界校验(延迟可为负数) | config.py | 4-5 |
### 修复项
- 移除重复/未使用的导入Bot/T_State/get_driver/MockApiException
- 新增`_recall_tasks`集合+`_track_task()`防止task被GC回收
- 移除脆弱的字符串匹配错误忽略逻辑,统一记录错误
- API拦截列表加入`send_private_msg`
- config添加`ge=1`约束和validator
- 日志加入`msg_id`便于追溯
### 待改进
- 可考虑撤回失败时的重试机制(但当前简单记录已足够)
---
## 跨插件一致性观察
- 两个插件配置类风格已统一:均为`BaseModel`子类
- 日志格式趋于统一:`操作描述: 关键标识=value error={e}`
- 待后续全局检查时进一步统一