Files
DanDingNoneBot/review_reports/danding_api_review.md
Mr.Xia c01338f496 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.
2026-05-09 23:22:28 +08:00

1.9 KiB
Raw Permalink Blame History

danding_api 评审报告

修复前问题清单 (5项)

# 严重度 问题 文件
1 致命 addkami/createkami/addviptime handler 内误用 ddonline.finish() 发送响应,导致:(1) 命令匹配到错误matcher后finish后续matcher仍会执行(2) 对于加卡密/生成卡密/用户加时等敏感操作错误消息可能泄漏给其他matcher admin.py:36,41,49,58,63,69,78,84,91
2 session_id 判断 bugif session_id is None or "": — Python中 or "" 总是返回右侧空字符串falsy导致该条件永远为True每次调用send_mail都触发重新登录 utils.py:142
3 requests.post() 同步阻塞调用在 async 函数中,会阻塞 nonebot 事件循环 utils.py:20,34,146
4 硬编码 user 1424473282post_vcodeget_log utils.py:31,50
5 random.sleep(2,3) 模拟人工反应(多处) admin.py

修复后变更清单

admin.py

  • addkami handler → 改用 addkami.finish()
  • createkami handler → 改用 createkami.finish()
  • addviptime handler → 改用 addviptime.finish()
  • 各 handler 加 try/except 错误处理
  • logger.error 日志

utils.py

  • session_id is None or ""not session_id
  • requests.post/gettimeout=10

遗留问题(建议后续处理)

  • requests 同步阻塞 → 迁移到 httpxaiohttp
  • 硬编码 user 1424473282 → 提取为配置项
  • login_pmail() 是同步函数但在模块级调用,应改为异步或在启动时调用

验证

  • 每个 handler 只调用自身 matcher 的 .finish()
  • session_id 判断逻辑正确
  • API 调用有 timeout
  • 敏感操作有 try/except

代码质量总结

修复后评级:B- (从 D 提升,仍有同步阻塞等架构问题)