From 2f21b2a0b41bebe28c9b9af746f9fc3ac5f714a5 Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 22 May 2026 13:36:05 +0800 Subject: [PATCH] =?UTF-8?q?refactor(fudai):=20=E6=8A=BD=20=5Fmaybe=5Frun?= =?UTF-8?q?=5Fyanghao=5Fduring=5Frun=20=E5=AE=9E=E7=8E=B0=E5=88=B0=20maybe?= =?UTF-8?q?=5Frun=5Fyanghao=5Fduring=5Frun?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将"按间隔触发推荐页养号"逻辑(约 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) --- douyin/core/douyin_fudai.py | 60 ++---------------- .../fudai_modules/fudai_detail_helpers.py | 61 +++++++++++++++++++ 2 files changed, 66 insertions(+), 55 deletions(-) diff --git a/douyin/core/douyin_fudai.py b/douyin/core/douyin_fudai.py index dc2bda0..7d5729e 100644 --- a/douyin/core/douyin_fudai.py +++ b/douyin/core/douyin_fudai.py @@ -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( diff --git a/douyin/core/fudai_modules/fudai_detail_helpers.py b/douyin/core/fudai_modules/fudai_detail_helpers.py index 859fca5..34a02de 100644 --- a/douyin/core/fudai_modules/fudai_detail_helpers.py +++ b/douyin/core/fudai_modules/fudai_detail_helpers.py @@ -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: