diff --git a/config.yml.default b/config.yml.default index cac46f9e0..47c03f284 100644 --- a/config.yml.default +++ b/config.yml.default @@ -163,6 +163,8 @@ challenge: # Incoming challenges. # block_list: # List of users from which the challenges are always declined. # - user1 # - user2 +# online_block_list: # The urls from which to retrieve a list of bot names that will not be challenged. The list should be a text file where each line contains the name of a blocked bot +# - example.com/blocklist # allow_list: # List of users from which challenges are exclusively accepted, all others being declined. If empty, challenges from all users may be accepted. # - user3 # - user4 @@ -211,6 +213,8 @@ matchmaking: # block_list: # The list of bots that will not be challenged # - user1 # - user2 +# online_block_list: # The urls from which to retrieve a list of bot names that will not be challenged. The list should be a text file where each line contains the name of a blocked bot +# - example.com/blocklist include_challenge_block_list: false # Do not challenge bots in the challenge: block_list in addition to the matchmaking block list. # overrides: # List of overrides for the matchmaking specifications above. When a challenge is created, either the default specification above or one of the overrides will be randomly chosen. diff --git a/lib/config.py b/lib/config.py index ba0f65894..e0646fc3f 100644 --- a/lib/config.py +++ b/lib/config.py @@ -4,6 +4,7 @@ import os import logging import math +import requests from abc import ABCMeta from typing import Any, Union, ItemsView, Callable from lib.lichess_types import CONFIG_DICT_TYPE, FilterType @@ -209,6 +210,7 @@ def insert_default_values(CONFIG: CONFIG_DICT_TYPE) -> None: set_config_default(CONFIG, "challenge", key="max_days", default=math.inf) set_config_default(CONFIG, "challenge", key="min_days", default=1) set_config_default(CONFIG, "challenge", key="block_list", default=[], force_empty_values=True) + set_config_default(CONFIG, "challenge", key="online_block_list", default=[], force_empty_values=True) set_config_default(CONFIG, "challenge", key="allow_list", default=[], force_empty_values=True) set_config_default(CONFIG, "challenge", key="max_simultaneous_games_per_user", default=5) set_config_default(CONFIG, "correspondence", key="checkin_period", default=600) @@ -217,6 +219,7 @@ def insert_default_values(CONFIG: CONFIG_DICT_TYPE) -> None: set_config_default(CONFIG, "matchmaking", key="challenge_timeout", default=30, force_empty_values=True) CONFIG["matchmaking"]["challenge_timeout"] = max(CONFIG["matchmaking"]["challenge_timeout"], 1) set_config_default(CONFIG, "matchmaking", key="block_list", default=[], force_empty_values=True) + set_config_default(CONFIG, "matchmaking", key="online_block_list", default=[], force_empty_values=True) set_config_default(CONFIG, "matchmaking", key="include_challenge_block_list", default=False, force_empty_values=True) default_filter = (CONFIG.get("matchmaking") or {}).get("delay_after_decline") or FilterType.NONE.value set_config_default(CONFIG, "matchmaking", key="challenge_filter", default=default_filter, force_empty_values=True) @@ -248,6 +251,23 @@ def insert_default_values(CONFIG: CONFIG_DICT_TYPE) -> None: for target in ["", "_spectators"]: set_config_default(CONFIG, "greeting", key=greeting + target, default="", force_empty_values=True) + +def process_block_list(CONFIG: CONFIG_DICT_TYPE) -> None: + """ + Retrieve online block lists and copy over challenge blocklist if necessary. + + :param CONFIG: The bot's config. + """ + def parse_block_list_from_url(url: str) -> list[str]: + block_list = requests.get(url).text.strip() + return [username.strip() for username in block_list.split("\n")] + + for url in CONFIG["matchmaking"]["online_block_list"]: + CONFIG["matchmaking"]["block_list"].extend(parse_block_list_from_url(url)) + + for url in CONFIG["challenge"]["online_block_list"]: + CONFIG["challenge"]["block_list"].extend(parse_block_list_from_url(url)) + if CONFIG["matchmaking"]["include_challenge_block_list"]: CONFIG["matchmaking"]["block_list"].extend(CONFIG["challenge"]["block_list"]) @@ -408,6 +428,7 @@ def load_config(config_file: str) -> Configuration: CONFIG["token"] = os.environ["LICHESS_BOT_TOKEN"] insert_default_values(CONFIG) + process_block_list(CONFIG) log_config(CONFIG) validate_config(CONFIG) diff --git a/test_bot/buggy_engine_macos b/test_bot/buggy_engine_macos old mode 100644 new mode 100755 diff --git a/wiki/Configure-lichess-bot.md b/wiki/Configure-lichess-bot.md index aa32db359..24b75cde9 100644 --- a/wiki/Configure-lichess-bot.md +++ b/wiki/Configure-lichess-bot.md @@ -192,6 +192,7 @@ will precede the `go` command to start thinking with `sd 5`. The other `go_comma -casual ``` - `block_list`: An indented list of usernames from which the challenges are always declined. If this option is not present, then the list is considered empty. + - `online_block_list`: An indented list of urls from which additional block lists are retrieved. An online block list is a plain text file where each line contains a single username. If this option is not present, then the list is considered empty. - `allow_list`: An indented list of usernames from which challenges are exclusively accepted. A challenge from a user not on this list is declined. If this option is not present or empty, any user's challenge may be accepted. - `recent_bot_challenge_age`: Maximum age of a bot challenge to be considered recent in seconds - `max_recent_bot_challenges`: Maximum number of recent challenges that can be accepted from the same bot @@ -255,6 +256,7 @@ will precede the `go` command to start thinking with `sd 5`. The other `go_comma The `challenge_filter` option can be useful if your matchmaking settings result in a lot of declined challenges. The bots that accept challenges will be challenged more often than those that have declined. The filter will remain until lichess-bot quits or the connection with lichess.org is reset. - `block_list`: An indented list of usernames of bots that will not be challenged. If this option is not present, then the list is considered empty. + - `online_block_list`: An indented list of urls from which additional block lists are retrieved. An online block list is a plain text file where each line contains a single username. If this option is not present, then the list is considered empty. - `include_challenge_block_list`: If `true`, do not send challenges to the bots listed in the `challenge: block_list`. Default is `false`. - `overrides`: Create variations on the matchmaking settings above for more specific circumstances. If there are any subsections under `overrides`, the settings below that will override the settings in the matchmaking section. Any settings that do not appear will be taken from the settings above.

The overrides section must have the following: