#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 检查GUI参数设置冲突的脚本 """ import json import os import sys # 修复Windows控制台编码问题 if sys.platform == "win32": try: sys.stdout.reconfigure(encoding="utf-8") except Exception: pass try: import path_config CONFIG_PATH = path_config.get_config_path() except Exception: import path_config CONFIG_PATH = path_config.get_config_path() def check_conflicts(cfg: dict) -> list: """检查配置参数冲突,返回冲突列表""" conflicts = [] # 1. 检查倒计时参数冲突 skip_gt = int(cfg.get("skip_if_countdown_gt_seconds", 900) or 900) skip_lt = int(cfg.get("skip_if_countdown_lt_seconds", 5) or 5) join_ahead = int(cfg.get("high_value_fudai_join_ahead_seconds", 300) or 300) if skip_lt >= skip_gt: conflicts.append( { "type": "倒计时阈值冲突", "message": f"倒计时小于阈值({skip_lt}秒) >= 倒计时大于阈值({skip_gt}秒),这会导致所有福袋都被过滤", "params": { "skip_if_countdown_lt_seconds": skip_lt, "skip_if_countdown_gt_seconds": skip_gt, }, } ) if join_ahead > skip_gt: conflicts.append( { "type": "预约参与阈值冲突", "message": f"预约参与阈值({join_ahead}秒) > 倒计时大于阈值({skip_gt}秒),高价值福袋即使剩余时间在预约阈值内也会被过滤", "params": { "high_value_fudai_join_ahead_seconds": join_ahead, "skip_if_countdown_gt_seconds": skip_gt, }, } ) if join_ahead < skip_lt: conflicts.append( { "type": "预约参与阈值冲突", "message": f"预约参与阈值({join_ahead}秒) < 倒计时小于阈值({skip_lt}秒),可能导致高价值福袋在预约阈值内也被过滤", "params": { "high_value_fudai_join_ahead_seconds": join_ahead, "skip_if_countdown_lt_seconds": skip_lt, }, } ) # 2. 检查参与人数参数冲突 min_participants = int(cfg.get("min_participants", 0) or 0) max_participants = int(cfg.get("max_participants", 0) or 0) if max_participants > 0 and min_participants > max_participants: conflicts.append( { "type": "参与人数阈值冲突", "message": f"最小参与人数({min_participants}) > 最大参与人数({max_participants}),这会导致所有福袋都被过滤", "params": { "min_participants": min_participants, "max_participants": max_participants, }, } ) # 3. 检查价值参数冲突 min_value = float(cfg.get("min_prize_value_yuan", 0) or 0) high_value_threshold = float( cfg.get("high_value_fudai_threshold_yuan", 1000) or 1000 ) if high_value_threshold < min_value: conflicts.append( { "type": "价值阈值冲突", "message": f"高价值阈值({high_value_threshold}元) < 最小价值({min_value}元),高价值福袋可能被最小价值过滤掉", "params": { "high_value_fudai_threshold_yuan": high_value_threshold, "min_prize_value_yuan": min_value, }, } ) # 4. 检查高价值预约相关参数 high_value_enabled = bool(cfg.get("high_value_fudai_enabled", False)) if high_value_enabled and high_value_threshold <= 0: conflicts.append( { "type": "高价值预约配置错误", "message": f"已启用高价值预约,但高价值阈值({high_value_threshold}元) <= 0,预约功能无法正常工作", "params": { "high_value_fudai_enabled": high_value_enabled, "high_value_fudai_threshold_yuan": high_value_threshold, }, } ) # 5. 检查预约相关参数合理性 if high_value_enabled: max_reservations = int(cfg.get("high_value_fudai_max_reservations", 5) or 5) if max_reservations <= 0: conflicts.append( { "type": "预约数量配置错误", "message": f"最多记录数量({max_reservations}) <= 0,预约功能无法正常工作", "params": { "high_value_fudai_max_reservations": max_reservations, }, } ) # 6. 检查福袋查找相关参数 fudai_icon_max_wait = float(cfg.get("fudai_icon_max_wait_seconds", 5.0) or 5.0) fudai_icon_retry_delay = float( cfg.get("fudai_icon_retry_delay_seconds", 0.6) or 0.6 ) if fudai_icon_max_wait < fudai_icon_retry_delay: conflicts.append( { "type": "福袋查找参数不合理", "message": f"最大等待时间({fudai_icon_max_wait}秒) < 重试延迟({fudai_icon_retry_delay}秒),可能导致只检测一次就放弃", "params": { "fudai_icon_max_wait_seconds": fudai_icon_max_wait, "fudai_icon_retry_delay_seconds": fudai_icon_retry_delay, }, } ) return conflicts def main(): """主函数""" if not os.path.exists(CONFIG_PATH): print(f"配置文件不存在: {CONFIG_PATH}") return try: with open(CONFIG_PATH, "r", encoding="utf-8") as f: cfg = json.load(f) except Exception as e: print(f"读取配置文件失败: {e}") return conflicts = check_conflicts(cfg) if not conflicts: print("[OK] 未发现参数冲突") return print(f"发现 {len(conflicts)} 个参数冲突:\n") for i, conflict in enumerate(conflicts, 1): print(f"{i}. 【{conflict['type']}】") print(f" {conflict['message']}") print(f" 相关参数: {conflict['params']}") print() if __name__ == "__main__": main()