Skip to content

Commit

Permalink
Add /api/bot/online endpoint (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
kalpgarg authored May 13, 2023
1 parent 91a0e36 commit a6ce5fa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ Most of the API is available:
client.board.claim_victory
client.board.go_berserk
client.bots.get_online_bots
client.bots.stream_incoming_events
client.bots.stream_game_state
client.bots.make_move
Expand Down
13 changes: 13 additions & 0 deletions berserk/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,19 @@ def stream_game_state(self, game_id: str) -> Iterator[Dict[str, Any]]:
path = f"api/bot/game/stream/{game_id}"
yield from self._r.get(path, stream=True, converter=models.GameState.convert)

def get_online_bots(self, limit: int | None = None) -> Iterator[Dict[str, Any]]:
"""
Stream the online bot users.
:param limit: Maximum number of bot users to fetch
:return: iterator over online bots
"""
path = "api/bot/online"
params = {"nb": limit}
yield from self._r.get(
path, params=params, stream=True, fmt=NDJSON, converter=models.User.convert
)

def make_move(self, game_id: str, move: str) -> None:
"""Make a move in a bot game.
Expand Down

0 comments on commit a6ce5fa

Please sign in to comment.