refactor(fudai): 提取 __init__ 中默认配置块到 fudai_init_defaults

将 fudai_analyse.__init__ 中 137 行简单的 self.X = literal 配置默认值赋值
统一抽到 fudai_modules/fudai_init_defaults.py 的 init_default_config 函数。
所有字段语义、默认值、类型注解保持完全一致;load_config() 仍然会用
config.json 覆盖这些默认值。

douyin_fudai.py: 3760 → 3627 行 (-133)
新增 fudai_init_defaults.py: 132 行

验证:
- pytest 1013 passed
- compile OK

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
CodexandClaude Opus 4.7 committed 2026-05-22 08:04:31 +08:00
1 parent c8df6a1588
commit 5d2a0ac3ff
2 files changed
+135 -136

No files matched your search

+3 -136
View File
@@ -136,143 +136,10 @@ class fudai_analyse:
self._reservations_state_last_write_ts: float = 0.0
self.last_fudai_x: int = 0 # 上次检测到的福袋图标X坐标(用于优化搜索)
# 与配置相关的核心字段(只初始化最关键的几项,其余保持默认)
self.contains_not_want: list[str] = []
self.contains_want: list[str] = []
self.min_prize_value_yuan: float = 0.0
self.min_participants: int = 0
self.max_participants: int = 0
self.skip_if_countdown_gt_seconds: int = 900
self.skip_if_countdown_lt_seconds: int = 0 # 倒计时小于该秒数则不参与
self.no_fudai_watchdog_enabled: bool = False
# 福袋图标检测节流相关默认值
# 实际识别到福袋一般需要 4–6 秒,这里取中间值 5 秒作为默认上限,具体值可在 GUI / config.json 中调整
# 注意:已改为使用时间限制(fudai_icon_max_wait_seconds),不再使用尝试次数限制
self.fudai_icon_retry_delay_seconds: float = 0.6
self.fudai_icon_max_wait_seconds: float = 5.0
# 连续未找到福袋超过此阈值后,自动按返回键退出直播间(默认999999=禁用)
self.fudai_exit_after_misses: int = 999999
# 是否启用自动返回键退出(默认False=禁用)
self.enable_back_on_misses: bool = False
# 点击福袋图标后等待详情页加载的时间(秒)
self.fudai_click_wait_seconds: float = 1.0
# 切换直播间后等待阶段诊断的时间(秒)
self.switch_room_wait_after_stage_diag_seconds: float = 7.0
# 滑动速度(毫秒),影响滑动持续时间,值越大滑动越慢
self.swipe_duration_ms: int = 600
# fudai_find_max_attempts 已废弃,保留仅为兼容性,实际不再使用
self.fudai_find_max_attempts: int = 10
# 与配置相关的核心字段(默认值由 helper 统一初始化,load_config() 会用 config.json 覆盖)
from douyin.core.fudai_modules.fudai_init_defaults import init_default_config
# 优化查找器相关配置
self.fudai_finder_optimized_enabled: bool = True # 默认启用优化查找器
self.fudai_click_verify_enabled: bool = True # 点击后验证是否成功打开详情页
self.fudai_find_max_retries: int = 3 # 最大重试次数
self.screenshot_diagnose_min_interval_seconds: float = 8.0
# 开奖页面检测红色占比阈值(0.0~1.0)
self.lucky_draw_red_ratio_threshold: float = 0.9
# 优惠券模板匹配阈值(0.0~1.0,默认0.75)
self.coupon_template_match_threshold: float = 0.75
# 参与按钮红色占比阈值(0.0~1.0,默认0.25)
self.attend_button_red_ratio_threshold: float = 0.25
# 粉丝团加入红色占比阈值(0.0~1.0,默认0.25)
self.fansclub_join_red_ratio_threshold: float = 0.25
# 直播间检测阈值(模板匹配阈值,0.0~1.0,默认0.8)
self.live_room_match_threshold: float = 0.8
# 福袋模板匹配开关(默认关闭)
self.fudai_template_match_enabled: bool = False
# 福袋模板匹配阈值(0.0~1.0,默认0.7)
self.fudai_template_match_threshold: float = 0.7
# —— 高价值福袋 / 预约相关配置(从原 fudai1 精简迁移) ——
# 是否启用“高价值福袋预约参与”
self.high_value_fudai_enabled: bool = False
# 高价值阈值(元)
self.high_value_fudai_threshold_yuan: float = 500.0
# 提前参与秒数:开奖前 N 秒回到该直播间并参与
self.high_value_fudai_join_ahead_seconds: int = 100
# 从当前位置最多回滑多少次以回到预约直播间
self.high_value_fudai_max_swipe_back: int = 35
# 同时记录的最大预约数量
self.high_value_fudai_max_reservations: int = 3
# 完成某个预约福袋后的动作:stay=停留当前直播间;continue=继续执行抢福袋
self.high_value_fudai_after_action: str = "continue"
self.high_value_fudai_after_stay_seconds: int = 120
# 开奖前轮询时间(秒,默认10.0)
self.high_value_fudai_poll_before_seconds: float = 10.0
# 高价值直播间"回访"相关(当前仅保留配置,不在本地版强制启用复杂逻辑)
self.high_value_room_revisit_enabled: bool = False
self.high_value_room_revisit_only_current_run: bool = False
self.high_value_room_revisit_min_interval_seconds: int = 300
self.high_value_room_revisit_max_per_run: int = 5
self.high_value_room_revisit_min_prize_value: float = 0.0
self.high_value_room_revisit_max_age_days: int = 30
# 粉丝团相关配置
self.auto_join_fansclub: bool = False # 是否自动加入粉丝团
self.fansclub_fail_action: str = (
"stay" # 粉丝团失败策略:stay=停留,switch=切换
)
# 预约回退相关
self.reservation_back_verify_enabled: bool = True # 默认启用回退校验
# 未做回退校验时的快速回滑延迟(秒)
self.reservation_back_swipe_delay: float = 0.6
# 滑动次数重置相关
self.reset_after_swipes_enabled: bool = False # 由 Web/CLI 显式开关
self.reset_after_swipes: int = 10 # 达到阈值次数后回退,需启用开关后生效
# 意外返回桌面自救相关
self.desktop_icon_x: int = 153 # 桌面图标 X 坐标(默认值)
self.desktop_icon_y: int = 260 # 桌面图标 Y 坐标(默认值)
self.yanghao_fallback_live_x: int = 540 # 养号备用直播按钮 X 坐标
self.yanghao_fallback_live_y: int = 2000 # 养号备用直播按钮 Y 坐标
self.yanghao_fallback_enter_live_x: int = 540 # 养号备用进入直播间 X 坐标
self.yanghao_fallback_enter_live_y: int = 1200 # 养号备用进入直播间 Y 坐标
# 推荐页养号默认配置(若 config.json 未设置则使用这些默认值)
self.yanghao_enabled: bool = True
self.yanghao_enable_actions: bool = True
self.yanghao_step_screenshot: bool = False
self.yanghao_recommend_duration_seconds: int = 60
self.yanghao_recommend_interval_seconds: int = 0
self.yanghao_like_prob: float = 0.15
self.yanghao_fav_prob: float = 0.05
self.yanghao_comment_prob: float = 0.0
self.yanghao_dwell_on_action_min_seconds: float = 5.0
self.yanghao_dwell_on_action_max_seconds: float = 30.0
self.yanghao_icon_roi_size: int = 180
# 调整默认阈值为 0.70(更宽松,减少漏检)
self.yanghao_icon_match_threshold: float = 0.70
self.yanghao_like_roi_scale: float = 1.5
self.yanghao_fav_roi_scale: float = 1.5
self.yanghao_like_icon_match_threshold: float | None = None
self.yanghao_fav_icon_match_threshold: float | None = None
# icon 坐标(基于 1080x2400)
self.yanghao_like_icon_x: int = 0
self.yanghao_like_icon_y: int = 0
self.yanghao_fav_icon_x: int = 0
self.yanghao_fav_icon_y: int = 0
# roi 偏移
self.yanghao_like_roi_offset_x: int = 0
self.yanghao_like_roi_offset_y: int = 0
self.yanghao_fav_roi_offset_x: int = 0
self.yanghao_fav_roi_offset_y: int = 0
# 评论相关默认坐标与文案列表
# 最近一次触发推荐页养号的时间戳(用于定时触发)
self._last_yanghao_ts: float = 0.0
self.yanghao_comment_btn_x: int = 0
self.yanghao_comment_btn_y: int = 0
self.yanghao_comment_input_x: int = 0
self.yanghao_comment_input_y: int = 0
self.yanghao_comment_send_x: int = 0
self.yanghao_comment_send_y: int = 0
self.yanghao_comment_close_x: int = 0
self.yanghao_comment_close_y: int = 0
self.yanghao_comment_texts: list[str] = []
init_default_config(self)
# —— 预约运行时状态(单次运行内有效) ——
# 高价值福袋预约队列
@@ -0,0 +1,132 @@
"""福袋分析器默认配置初始化
从 douyin_fudai.py:fudai_analyse.__init__ 中提取的默认配置块。
所有字段都是简单的 self.X = literal 赋值,无逻辑分支。
后续 load_config() 会从 config.json 读取覆盖这些默认值。
"""
from __future__ import annotations
def init_default_config(self) -> None:
"""初始化所有配置字段的默认值。
分组:
- 福袋筛选与基础配置
- 福袋图标检测节流
- 优化查找器与阈值
- 直播间检测阈值
- 高价值福袋 / 预约
- 粉丝团
- 预约回退
- 滑动次数重置
- 意外返回桌面自救
- 养号配置
"""
# 与配置相关的核心字段(只初始化最关键的几项,其余保持默认)
self.contains_not_want: list[str] = []
self.contains_want: list[str] = []
self.min_prize_value_yuan: float = 0.0
self.min_participants: int = 0
self.max_participants: int = 0
self.skip_if_countdown_gt_seconds: int = 900
self.skip_if_countdown_lt_seconds: int = 0
self.no_fudai_watchdog_enabled: bool = False
# 福袋图标检测节流
self.fudai_icon_retry_delay_seconds: float = 0.6
self.fudai_icon_max_wait_seconds: float = 5.0
self.fudai_exit_after_misses: int = 999999
self.enable_back_on_misses: bool = False
self.fudai_click_wait_seconds: float = 1.0
self.switch_room_wait_after_stage_diag_seconds: float = 7.0
self.swipe_duration_ms: int = 600
self.fudai_find_max_attempts: int = 10
# 优化查找器
self.fudai_finder_optimized_enabled: bool = True
self.fudai_click_verify_enabled: bool = True
self.fudai_find_max_retries: int = 3
self.screenshot_diagnose_min_interval_seconds: float = 8.0
self.lucky_draw_red_ratio_threshold: float = 0.9
self.coupon_template_match_threshold: float = 0.75
self.attend_button_red_ratio_threshold: float = 0.25
self.fansclub_join_red_ratio_threshold: float = 0.25
# 直播间检测阈值
self.live_room_match_threshold: float = 0.8
self.fudai_template_match_enabled: bool = False
self.fudai_template_match_threshold: float = 0.7
# 高价值福袋 / 预约
self.high_value_fudai_enabled: bool = False
self.high_value_fudai_threshold_yuan: float = 500.0
self.high_value_fudai_join_ahead_seconds: int = 100
self.high_value_fudai_max_swipe_back: int = 35
self.high_value_fudai_max_reservations: int = 3
self.high_value_fudai_after_action: str = "continue"
self.high_value_fudai_after_stay_seconds: int = 120
self.high_value_fudai_poll_before_seconds: float = 10.0
# 高价值直播间回访
self.high_value_room_revisit_enabled: bool = False
self.high_value_room_revisit_only_current_run: bool = False
self.high_value_room_revisit_min_interval_seconds: int = 300
self.high_value_room_revisit_max_per_run: int = 5
self.high_value_room_revisit_min_prize_value: float = 0.0
self.high_value_room_revisit_max_age_days: int = 30
# 粉丝团
self.auto_join_fansclub: bool = False
self.fansclub_fail_action: str = "stay"
# 预约回退
self.reservation_back_verify_enabled: bool = True
self.reservation_back_swipe_delay: float = 0.6
# 滑动次数重置
self.reset_after_swipes_enabled: bool = False
self.reset_after_swipes: int = 10
# 意外返回桌面自救
self.desktop_icon_x: int = 153
self.desktop_icon_y: int = 260
self.yanghao_fallback_live_x: int = 540
self.yanghao_fallback_live_y: int = 2000
self.yanghao_fallback_enter_live_x: int = 540
self.yanghao_fallback_enter_live_y: int = 1200
# 养号配置
self.yanghao_enabled: bool = True
self.yanghao_enable_actions: bool = True
self.yanghao_step_screenshot: bool = False
self.yanghao_recommend_duration_seconds: int = 60
self.yanghao_recommend_interval_seconds: int = 0
self.yanghao_like_prob: float = 0.15
self.yanghao_fav_prob: float = 0.05
self.yanghao_comment_prob: float = 0.0
self.yanghao_dwell_on_action_min_seconds: float = 5.0
self.yanghao_dwell_on_action_max_seconds: float = 30.0
self.yanghao_icon_roi_size: int = 180
self.yanghao_icon_match_threshold: float = 0.70
self.yanghao_like_roi_scale: float = 1.5
self.yanghao_fav_roi_scale: float = 1.5
self.yanghao_like_icon_match_threshold: float | None = None
self.yanghao_fav_icon_match_threshold: float | None = None
self.yanghao_like_icon_x: int = 0
self.yanghao_like_icon_y: int = 0
self.yanghao_fav_icon_x: int = 0
self.yanghao_fav_icon_y: int = 0
self.yanghao_like_roi_offset_x: int = 0
self.yanghao_like_roi_offset_y: int = 0
self.yanghao_fav_roi_offset_x: int = 0
self.yanghao_fav_roi_offset_y: int = 0
self._last_yanghao_ts: float = 0.0
self.yanghao_comment_btn_x: int = 0
self.yanghao_comment_btn_y: int = 0
self.yanghao_comment_input_x: int = 0
self.yanghao_comment_input_y: int = 0
self.yanghao_comment_send_x: int = 0
self.yanghao_comment_send_y: int = 0
self.yanghao_comment_close_x: int = 0
self.yanghao_comment_close_y: int = 0
self.yanghao_comment_texts: list[str] = []