refactor: 将 anti_ban 作息逻辑从 script.py 抽出为 AntiBanGuard - #1760
Open
qiyh99 wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
嘿——我已经审阅了你的更改,看起来很棒!
Sourcery 评估
已批准。
请帮助我变得更有用!请在每条评论上点击 👍 或 👎,我会利用这些反馈来改进评审。
Original comment in English
Hey - I've reviewed your changes and they look great!
Sourcery assessment
Approved.
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
🟢 Approval recommended
变更为结构性重构且新旧逻辑路径(唤醒点计算、跨日重置、强制休息触发与清零)在关键分支上与原实现保持一致,未发现行为偏差或集成问题。
Pull request overview
将 script.py 中分散的 anti_ban 作息/活跃累计/强制休息逻辑抽离为独立的 AntiBanGuard,以降低 Script 类体积与隐式状态耦合,并保持原有调度行为不变。
Changes:
- 新增
module/config/anti_ban.py:引入AntiBanGuard,封装睡眠窗判断、跨日重置、每日活跃上限与强制长休息的唤醒时间计算。 - 精简
script.py:移除原先散插的 anti_ban 辅助函数与挂在Script上的隐式状态,改为通过anti_ban_guard.reset()/wake_time()/record_active()调用。 - 调度点保持一致:在
get_next_task()处抬高task.next_run,在任务结束处累计活跃秒数。
File summaries
| File | Description |
|---|---|
| script.py | 用 AntiBanGuard 替代原先散落在 Script 内部的 anti_ban 状态与计算逻辑,减少类内复杂度与隐式属性。 |
| module/config/anti_ban.py | 新增看守器类,集中实现睡眠窗/每日活跃上限/强制休息的状态维护与唤醒时间计算。 |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Findings
|
Change Summary
Reconstructed Intent点击此处展开
Observed Constraints点击此处展开
Intent Alignment
Release Risk
Validation Gaps点击此处展开
|
原本散插进 script.py 四处的睡眠窗/每日活跃上限/强制休息逻辑与隐式状态 (_active_*/_rest_until) 收拢为 module/config/anti_ban.py 的 AntiBanGuard, 镜像 InstanceGuard 范式。script.py 只留 import + 构造 + 三处一行调用, 行为完全不变。回应 script.py 变臃肿的反馈。
qiyh99
force-pushed
the
refactor/antiban-guard
branch
from
August 28, 2026 07:46
f383c2c to
7de0cd1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
回应上个 PR 合并时「script.py 已经变成一坨了」的反馈。
问题
防风控 PR(#1755)把 anti_ban 作息调度逻辑散插进了 script.py 的 4 处,运行时状态用
getattr(self, '_active_*', default)隐式挂在 Script 类上,让本就庞大的 Script 更臃肿。改动(纯结构调整,行为不变)
module/config/anti_ban.py的AntiBanGuard:自持状态(_active_date/_active_seconds_today/_rest_until),把睡眠窗/每日活跃上限/强制休息逻辑收拢为reset()/record_active()/wake_time(),镜像现有InstanceGuard范式。script.py抽空散插逻辑,只留 1 个 import + 1 个构造 + 3 处一行调用;删掉挂在 Script 上的隐式 anti_ban 状态。净减约 35 行。验证
py_compile+ 导入无环通过。Sourcery 总结
增强功能:
Original summary in English
Summary by Sourcery
Enhancements: