Skip to content

online block list #1104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config.yml.default
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
21 changes: 21 additions & 0 deletions lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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"])

Expand Down Expand Up @@ -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)

Expand Down
Empty file modified test_bot/buggy_engine_macos
100644 → 100755
Empty file.
2 changes: 2 additions & 0 deletions wiki/Configure-lichess-bot.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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. <br/> <br/>
The overrides section must have the following:
Expand Down
Loading