Skip to content

Use Timers instead of bools to filter opponents to allow temporary stops to challenges#1141

Merged
AttackingOrDefending merged 10 commits intolichess-bot-devs:masterfrom
MarkZH:opponent_acceptance_bool_to_timer
Oct 9, 2025
Merged

Use Timers instead of bools to filter opponents to allow temporary stops to challenges#1141
AttackingOrDefending merged 10 commits intolichess-bot-devs:masterfrom
MarkZH:opponent_acceptance_bool_to_timer

Conversation

@MarkZH
Copy link
Copy Markdown
Collaborator

@MarkZH MarkZH commented Oct 5, 2025

Type of pull request:

  • Bug fix
  • Feature
  • Other

Description:

Instead of preventing the challenging of another bot that declines a challenge for the rest of the lichess-bot run, default to a one-day timeout. Block lists still work, but are implemented as a 10-year timeout.

The primary reason for this PR is an upcoming change in lichess. Challenging another bot that has already played 100 games today will result in a 400 status code and an error message with information about when the bot's timeout will expire.

Related Issues:

This commit to lila tells bots how long to wait before challenging another bot that has reached the 100-bot-game per day limit: lichess-org/lila@53f2c4d

Checklist:

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

Screenshots/logs (if applicable):

MarkZH added 3 commits October 5, 2025 04:43
This will allow for filters to expire in case challenge declinations are
for temporary reasons. Also, in the case of an opponent reaching the
100-game daily limit, this will be useful for trying again in the time
given in the interval.
In an upcoming lichess update, challenging an opponent that has played 100 bot games will result in a similar error response to when the user's bot has played 100 bot games. This change distinguishes between them by checking if the error message contains the opponent's name.

This could also be distinguished by checking if the status code is 429 (user's bot) or 400 (opponent bot). But that information isn't returned from the Lichess.challenge() call.
@MarkZH
Copy link
Copy Markdown
Collaborator Author

MarkZH commented Oct 5, 2025

This PR is a draft since the change in the linked commit has not been deployed yet. This needs testing with a live bot session.

MarkZH added 6 commits October 5, 2025 07:23
A status code of 400 indicates that the opponent is rate limited, while
429 indicates that the bot is limited.

Also, put who is rate limited (if anyone) in the challenge response so
the Matchmaking class can use it.
Don't set rate limit when opponent is rate limited (400 status code).
@MarkZH MarkZH marked this pull request as ready for review October 8, 2025 04:11
@MarkZH
Copy link
Copy Markdown
Collaborator Author

MarkZH commented Oct 8, 2025

I think this is ready for testing beyond my computer. There is a bit of redundancy. The player timeout after 100 games is implemented in both the Lichess class and the Matchmaking class. This is probably unavoidable given their different functions.

@AttackingOrDefending AttackingOrDefending merged commit 5749ba8 into lichess-bot-devs:master Oct 9, 2025
23 checks passed
@MarkZH MarkZH deleted the opponent_acceptance_bool_to_timer branch October 10, 2025 07:30
r0950336 pushed a commit to r0950336/lichess-bot that referenced this pull request Dec 31, 2025
…ops to challenges (lichess-bot-devs#1141)

* Make matchmaking challenge filters time-limited

This will allow for filters to expire in case challenge declinations are
for temporary reasons. Also, in the case of an opponent reaching the
100-game daily limit, this will be useful for trying again in the time
given in the interval.

* Factor out variable

* Distinguish between bot limit and opponent limit

In an upcoming lichess update, challenging an opponent that has played 100 bot games will result in a similar error response to when the user's bot has played 100 bot games. This change distinguishes between them by checking if the error message contains the opponent's name.

This could also be distinguished by checking if the status code is 429 (user's bot) or 400 (opponent bot). But that information isn't returned from the Lichess.challenge() call.

* Be more specific about challenge pause delay

* Factor out function to get timeout from error

* Use status code to tell who is rate limited

A status code of 400 indicates that the opponent is rate limited, while
429 indicates that the bot is limited.

Also, put who is rate limited (if anyone) in the challenge response so
the Matchmaking class can use it.

* Simplify challenge control flow

* Only set rate limit when bot gets 429 status code

Don't set rate limit when opponent is rate limited (400 status code).

* Create a method to handle responses to challenges
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.

2 participants