Skip to content

Commit

Permalink
Fix KeyErrors for standard chess and cases where player hasn't played…
Browse files Browse the repository at this point in the history
… the variant
  • Loading branch information
qpwoeirut committed Jul 13, 2024
1 parent 25eef42 commit da8f1b2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion homemade.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,11 @@ def chat_command(self, game: model.Game, cmd: str) -> str:
def set_opening_book_player(self, game: model.Game, username: str) -> None:
self.opening_book_player = username
user_data = self.li.get_public_data(username)
self.opening_book_player_rating = user_data["perfs"][game.variant_key]["rating"]
variant = game.speed if game.variant_key == "standard" else game.variant_key
if variant in user_data["perfs"]:
self.opening_book_player_rating = user_data["perfs"][variant]["rating"]
else:
logger.info("%s not found in ratings, likely because user has played no games for this variant", variant)

# send request to the lichess server to start indexing games for this player
params = {"player": username, "moves": 100, "variant": game.variant_name, "recentGames": 0, "color": "white"}
Expand Down

0 comments on commit da8f1b2

Please sign in to comment.