Skip to content

Commit

Permalink
ok now all challenge endpoints have been implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
Anupya committed Oct 22, 2023
1 parent 69af9d7 commit 950d552
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ Most of the API is available:
client.challenges.decline
client.challenges.cancel
client.challenges.start_clocks
client.challenges.add_time_to_opponent_clock
client.challenges.create_tokens_for_multiple_users
client.explorer.get_lichess_games
client.explorer.get_masters_games
Expand Down
29 changes: 27 additions & 2 deletions berserk/clients/challenges.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

class Challenges(BaseClient):
def get_mine(self) -> Dict[str, List[Any]]:
"""Get a list of outgoing challenges (created by me) and incoming challenges (targeted at me).
"""Get all outgoing challenges (created by me) and incoming challenges (targeted at me).
:return: array of incoming challenges keyed by "in" and array of outgoing challenges keyed by "out"
:return: all my outgoing and incoming challenges
"""
path = "/api/challenge"
return self._r.get(path)
Expand Down Expand Up @@ -209,3 +209,28 @@ def start_clocks(
path = f"/api/challenge/{game_id}/start-clocks"
params = {"token1": token_player_1, "token2": token_player_2}
self._r.post(path=path, params=params)

def add_time_to_opponent_clock(self, game_id: str, seconds: int) -> None:
"""Add seconds to the opponent's clock. Can be used to create games with time odds.
:param game_id: game ID
:param seconds: number of seconds to add to opponent's clock
"""
path = f"/api/round/{game_id}/add-time/{seconds}"
self._r.post(path)

def create_tokens_for_multiple_users(
self, usernames: str, description: str
) -> Dict[str, str]:
"""This endpoint can only be used by Lichess admins.
Create and obtain challenge:write tokens for multiple users.
If a similar token already exists for a user, it is reused. This endpoint is idempotent.
:param usernames: usernames separated with commas
:param description: user-visible token description
:return: challenge:write tokens of each user
"""
path = "/api/token/admin-challenge"
return self._r.post(path)

0 comments on commit 950d552

Please sign in to comment.