diff --git a/lib/config.py b/lib/config.py index 4f8b9c097..d68f61b07 100644 --- a/lib/config.py +++ b/lib/config.py @@ -70,7 +70,7 @@ def config_assert(assertion: bool, error_message: str) -> None: def config_warn(assertion: bool, warning_message: str) -> None: - """Raise an exception if an assertion is false.""" + """Print a warning message if an assertion is false.""" if not assertion: logger.warning(warning_message) @@ -297,6 +297,23 @@ def validate_config(CONFIG: CONFIG_DICT_TYPE) -> None: config_assert(CONFIG["challenge"]["preference"] in ["none", "human", "bot"], "challenge.preference should be `none`, `human`, or `bot`.") + min_max_template = ("challenge.max_{setting} < challenge.min_{setting} will result " + "in no {game_type} challenges being accepted.") + for setting in ["increment", "base", "days"]: + game_type = "correspondence" if setting == "days" else "real-time" + config_warn(CONFIG["challenge"][f"min_{setting}"] <= CONFIG["challenge"][f"max_{setting}"], + min_max_template.format(setting=setting, game_type=game_type)) + + matchmaking = CONFIG["matchmaking"] + matchmaking_enabled = matchmaking["allow_matchmaking"] + + if matchmaking_enabled: + config_warn(matchmaking["opponent_min_rating"] <= matchmaking["opponent_max_rating"], + "matchmaking.opponent_max_rating < matchmaking.opponent_min_rating will result in " + "no challenges being created.") + config_warn(matchmaking.get("opponent_rating_difference", 0) >= 0, + "matchmaking.opponent_rating_difference < 0 will result in no challenges being created.") + pgn_directory = CONFIG["pgn_directory"] in_docker = os.environ.get("LICHESS_BOT_DOCKER") config_warn(not pgn_directory or not in_docker, "Games will be saved to '{}', please ensure this folder is in a mounted " @@ -310,9 +327,6 @@ def validate_config(CONFIG: CONFIG_DICT_TYPE) -> None: f"The `pgn_file_grouping` choice of `{config_pgn_choice}` is not valid. " f"Please choose from {valid_pgn_grouping_options}.") - matchmaking = CONFIG.get("matchmaking") or {} - matchmaking_enabled = matchmaking.get("allow_matchmaking") or False - def has_valid_list(name: str) -> bool: entries = matchmaking.get(name) return isinstance(entries, list) and entries[0] is not None