Skip to content
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

Start games automatically #523

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

glbert-does
Copy link
Member

@glbert-does glbert-does commented Nov 1, 2023

closes #491.

with this pull request, we try to use the lichess bulk pairing api to create games and start clocks automatically at the scheduled time. here is how it is supposed to work:

  • new league setting start_games. if this is set to true,
  • players can confirm the time they have scheduled for.
  • if the scheduled time changes, players need to confirm again.
  • every */5 minutes scheduled games 30 seconds to 5:30 in the future are started (if both players confirmed that is), clocks are set to start in 6 minutes. lichess sends a message pointing to the game using the account that did the apicall.
  • in practice this should mean that games started for "nice" numbers like :00 or :30 are started five minutes before they are scheduled, and the clocks are started one minute after the game is scheduled.
  • players cannot claim a win (yay!), but they can abort a game. which should help if an opponent does not show up. potentially, we could disallow early draws (move 30), but i don't think this would do much other than annoy players.

at least the following things are potential problems:

  • the account doing the bulk pairing needs a token with challenge:bulk scope. i believe in our case this would be lichess.org/@/lichess4545 – i assume the token currently used might not have that yet.
  • if we do not have a valid token for a player, or the account is closed, lichess returns an error and lists the token(s) in question, without starting any games. i try to handle this, but it is rather not elegant. i assume there should be a better way than to use regexp on the error message. should work better now.
  • after 20 minutes, we used to check whether games have started by simply checking for a game id. this is not enough anymore, i now try to check in the move list whether more than one move was made. at this point i have tested this a lot of times, and everything seems to be working as expected.
  • the page to confirm scheduled times is rather ... bad. i did not put too much work into it, because i assume long term we will create a way to confirm times via slack.

i tried to test a lot of stuff, but it is difficult to get it anywhere close to what it would look like in prod.

@glbert-does
Copy link
Member Author

glbert-does commented Nov 1, 2023

todo:

  • the lichess response to a successful pairing could be used to set the gameid
  • improve error handling
  • potentially, if lichess rejects a token, we should invalidate it on our end
  • we should probably notify players about a started game on slack as well.
  • we now hit update_lichess_presence way harder, since we cannot stop once a gamelink is set. maybe we can check games for moves earlier to reduce this.

@glbert-does
Copy link
Member Author

glbert-does commented Nov 14, 2023

most of the important todos are done. there's a couple nice-to-haves as well:

  1. as mentioned, a way to confirm a scheduled time via slack
  2. when a token was declined by lichess, it would be nice to force the player to get a new one, e.g. by logging them out (edit: this can potentially be done by changing their password via User.objects.get(username=[username]).set_password("whatever") - not sure if this would work for our oauth based system)
  3. possibly, whether a time was confirmed should be shown on the pairings page
  4. potentially, it could be nice to have at least the time for starting the clocks be a league setting
  5. maybe whether the clocks will be started at all could be a league setting too (edit: but personally i do not see much of a disadvantage to starting clocks)

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.

Start games automatically
1 participant