From a6ce5faa7322efbdf85d7581bcaf7f65f0074453 Mon Sep 17 00:00:00 2001 From: kalp garg Date: Sun, 14 May 2023 02:58:58 +0530 Subject: [PATCH] Add /api/bot/online endpoint (#8) --- README.rst | 1 + berserk/clients.py | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/README.rst b/README.rst index 69d7d53..eb8174e 100644 --- a/README.rst +++ b/README.rst @@ -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 diff --git a/berserk/clients.py b/berserk/clients.py index e2f1268..c6b9b4d 100644 --- a/berserk/clients.py +++ b/berserk/clients.py @@ -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.