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.
[x] the lichess response to a successful pairing could be used to set the gameid
[x] improve error handling
[x] potentially, if lichess rejects a token, we should invalidate it on our end
[x] we should probably notify players about a started game on slack as well.
[x] 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.
most of the important todos are done. there's a couple nice-to-haves as well:
[ ] as mentioned, a way to confirm a scheduled time via slack
[ ] 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)
[ ] possibly, whether a time was confirmed should be shown on the pairings page
[ ] potentially, it could be nice to have at least the time for starting the clocks be a league setting
[ ] 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)
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:
start_games
. if this is set to true,at least the following things are potential problems:
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.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.