Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

xu-shawn
Copy link
Contributor

@xu-shawn xu-shawn commented Oct 6, 2025

Type of pull request:

  • Bug fix
  • Feature
  • Other

Description:

The online blocklist introduced in #1104 requires manually refreshing the bot to refresh the blocklist, which can be tedious for long running bots. This PR refactors the online blocklist to a separate class and refresh every time before it is used.

Checklist:

  • I have read and followed the contribution guidelines.
  • I have added necessary documentation (if applicable).
  • The changes pass all existing tests.

@xu-shawn xu-shawn force-pushed the refresh_blocklist branch 2 times, most recently from 80b5b72 to 3e7971f Compare October 6, 2025 22:53
Comment on lines +31 to +36
try:
for url in self.urls:
blocklist.extend(_parse_block_list_from_url(url))
except Exception:
logger.warning("Failed to refresh online blocklists")
return
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this logic, if any site is unreachable or returns an error, then none of the sites update the blocklist. Is this what you want to happen? If you put the try-except blocks inside the for-loop, then the block list can be partially updated, even when a URL results in an error.

Comment on lines +8 to +10
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")]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We risk being a burden a site with a blocklist if we don't somehow moderate how often the blocklist is updated. Imagine some blocklist becomes popular among many bot owners and all of them are downloading from the server several times a minute. If the blocklist is long, that can be a substantial amount of data being downloaded. If the list is not changing often, that's a lot of useless bandwidth usage.

I can think of two options:

  1. Capture the last-modified or etag header of the response. With these saved, send the next request with an if-modified-since or if-none-match header, respectively. This will probably require keeping the individual blocklists in a dictionary with the URL as the key.
  2. Use a Timer to limit refreshes to some reasonable frequency, like a few times an hour. Create the timer with self.refresh_timer = Timer(minutes(30)). Then, in refresh(), if not self.refresh_timer.is_expired(): return. Finally, after refreshing, self.refresh_timer.reset().

for name in self.matchmaking_cfg.block_list:
self.add_to_block_list(name)

self.online_block_list = OnlineBlocklist(self.matchmaking_cfg.online_block_list)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be the same online_block_list that was created in lichess_bot_main(). There's no reason to have two copies of the class pinging the servers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.