refactor(fudai): 抽 _maybe_run_yanghao_during_run 实现到 maybe_run_yanghao_during_run
将"按间隔触发推荐页养号"逻辑(约 56 行)抽到 fudai_detail_helpers.maybe_run_yanghao_during_run。 跳过条件:interval <= 0 / 等待开奖 / 参与预约 / 有预约队列 / 预约焦点期内 / 距上次触发不足 interval。 类内方法保留薄包装。 douyin_fudai.py: 999 → 949 行 (-50) fudai_detail_helpers.py: 3033 → 3094 行 douyin_fudai.py 跌破 950 行(4121 → 949,本会话累计削减 3172 行 = -77%) 验证: - pytest 1013 passed - compile OK Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
acd8f5c387
commit
2f21b2a0b4
2 files changed
+66
-55
No files matched your search
@@ -312,62 +312,12 @@ class fudai_analyse:
|
||||
return 60
|
||||
|
||||
def _maybe_run_yanghao_during_run(self) -> None:
|
||||
"""If configured, trigger recommendation-page yanghao at configured intervals.
|
||||
"""如果配置了,按间隔触发推荐页养号。"""
|
||||
from douyin.core.fudai_modules.fudai_detail_helpers import (
|
||||
maybe_run_yanghao_during_run,
|
||||
)
|
||||
|
||||
This respects `yanghao_enabled` and will not trigger during lottery-result waiting.
|
||||
"""
|
||||
try:
|
||||
interval = int(getattr(self, "yanghao_recommend_interval_seconds", 0) or 0)
|
||||
if interval <= 0:
|
||||
return
|
||||
|
||||
# 不在等待开奖期间触发养号
|
||||
if getattr(self, "_waiting_for_lottery_result", False):
|
||||
return
|
||||
|
||||
# 如果正在处理预约或有未完成的预约队列,则跳过触发
|
||||
try:
|
||||
if getattr(self, "_current_attending_reservation_fudai", False):
|
||||
return
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
reservations = getattr(self, "reservations", None)
|
||||
if reservations and len(reservations) > 0:
|
||||
# 有预约队列,等待预约完成
|
||||
return
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
reservation_focus_until = float(
|
||||
getattr(self, "reservation_focus_until_ts", 0.0) or 0.0
|
||||
)
|
||||
if reservation_focus_until > time.time():
|
||||
# 当前处于预约焦点期,跳过养号
|
||||
return
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
now = time.time()
|
||||
last = float(getattr(self, "_last_yanghao_ts", 0.0) or 0.0)
|
||||
if now - last < interval:
|
||||
return
|
||||
|
||||
try:
|
||||
self._log_kv("养号", "定时触发推荐页养号", interval_seconds=interval)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
self._last_yanghao_ts = now
|
||||
seconds = int(getattr(self, "yanghao_recommend_duration_seconds", 60) or 60)
|
||||
try:
|
||||
self._yanghao_wait(seconds)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
maybe_run_yanghao_during_run(self)
|
||||
|
||||
# ========== 兼容旧入口:主循环 ==========
|
||||
def fudai_choujiang(
|
||||
|
||||
@@ -273,6 +273,67 @@ def handle_no_fudai_in_live_room(analyser, room_pos_ref, start_time: float) -> N
|
||||
)
|
||||
|
||||
|
||||
def maybe_run_yanghao_during_run(analyser) -> None:
|
||||
"""如果配置了 yanghao_recommend_interval_seconds,按间隔触发推荐页养号。
|
||||
|
||||
跳过条件:
|
||||
- interval <= 0
|
||||
- 正在等待开奖
|
||||
- 正在参与预约福袋
|
||||
- 有预约队列
|
||||
- 处于预约焦点期
|
||||
- 距上次触发不足 interval
|
||||
"""
|
||||
try:
|
||||
interval = int(getattr(analyser, "yanghao_recommend_interval_seconds", 0) or 0)
|
||||
if interval <= 0:
|
||||
return
|
||||
|
||||
if getattr(analyser, "_waiting_for_lottery_result", False):
|
||||
return
|
||||
|
||||
try:
|
||||
if getattr(analyser, "_current_attending_reservation_fudai", False):
|
||||
return
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
reservations = getattr(analyser, "reservations", None)
|
||||
if reservations and len(reservations) > 0:
|
||||
return
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
reservation_focus_until = float(
|
||||
getattr(analyser, "reservation_focus_until_ts", 0.0) or 0.0
|
||||
)
|
||||
if reservation_focus_until > time.time():
|
||||
return
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
now = time.time()
|
||||
last = float(getattr(analyser, "_last_yanghao_ts", 0.0) or 0.0)
|
||||
if now - last < interval:
|
||||
return
|
||||
|
||||
try:
|
||||
analyser._log_kv("养号", "定时触发推荐页养号", interval_seconds=interval)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
analyser._last_yanghao_ts = now
|
||||
seconds = int(getattr(analyser, "yanghao_recommend_duration_seconds", 60) or 60)
|
||||
try:
|
||||
analyser._yanghao_wait(seconds)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def swipe_with_fallback(analyser, start_x: int, start_y: int, end_x: int, end_y: int, duration_ms: int = 300) -> None:
|
||||
"""fudai_analyse.swipe 的实现:转发到底层 operation.swipe,失败时回退到 ADB direct。"""
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user