From 40db4a559df162fef054dc8c8c6111176974af55 Mon Sep 17 00:00:00 2001 From: kgarg Date: Thu, 11 May 2023 21:40:50 +0530 Subject: [PATCH 1/5] added bot online API --- README.rst | 1 + berserk/clients.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/README.rst b/README.rst index 69d7d53..9bd24b2 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.online 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 816e0b9..48e203b 100644 --- a/berserk/clients.py +++ b/berserk/clients.py @@ -1077,6 +1077,18 @@ 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 the results + """ + path = f"api/bot/online" + params = {"nb" : limit} + return self._r.get(path, params=params, stream=True) + def make_move(self, game_id: str, move: str) -> None: """Make a move in a bot game. From e21e6e10616359c9c38ab3073bd3263860ead3de Mon Sep 17 00:00:00 2001 From: kgarg Date: Thu, 11 May 2023 21:53:24 +0530 Subject: [PATCH 2/5] fix formatting --- berserk/clients.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/berserk/clients.py b/berserk/clients.py index 48e203b..3c1414c 100644 --- a/berserk/clients.py +++ b/berserk/clients.py @@ -1077,8 +1077,7 @@ 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]]: + def get_online_bots(self, limit: int | None = None) -> Iterator[Dict[str, Any]]: """ Stream the online bot users. @@ -1086,7 +1085,7 @@ def get_online_bots(self, limit: int | None = None :return: Iterator over the results """ path = f"api/bot/online" - params = {"nb" : limit} + params = {"nb": limit} return self._r.get(path, params=params, stream=True) def make_move(self, game_id: str, move: str) -> None: From 33d092bd49631a9f47d83ee0412849ea05196447 Mon Sep 17 00:00:00 2001 From: kalp garg Date: Fri, 12 May 2023 09:56:36 +0530 Subject: [PATCH 3/5] Apply suggestions from code review Co-authored-by: icp --- README.rst | 2 +- berserk/clients.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 9bd24b2..eb8174e 100644 --- a/README.rst +++ b/README.rst @@ -125,7 +125,7 @@ Most of the API is available: client.board.claim_victory client.board.go_berserk - client.bots.online + 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 3c1414c..f516eec 100644 --- a/berserk/clients.py +++ b/berserk/clients.py @@ -1082,11 +1082,15 @@ 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 + :type limit: int, optional :return: Iterator over the results + :return: iterator over online bots """ - path = f"api/bot/online" + path = "api/bot/online" params = {"nb": limit} - return self._r.get(path, params=params, stream=True) + 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. From 6870ce3d901aaeae8eed1893364a59bc6ec49a72 Mon Sep 17 00:00:00 2001 From: kalp garg Date: Fri, 12 May 2023 15:06:12 +0530 Subject: [PATCH 4/5] Add /api/bot/online endpoint Co-authored-by: icp --- berserk/clients.py | 1 - 1 file changed, 1 deletion(-) diff --git a/berserk/clients.py b/berserk/clients.py index f516eec..3a0b81a 100644 --- a/berserk/clients.py +++ b/berserk/clients.py @@ -1083,7 +1083,6 @@ def get_online_bots(self, limit: int | None = None) -> Iterator[Dict[str, Any]]: :param limit: Maximum number of bot users to fetch :type limit: int, optional - :return: Iterator over the results :return: iterator over online bots """ path = "api/bot/online" From 3f5e1ed513e29a347e119230e40b2c83bb944e1c Mon Sep 17 00:00:00 2001 From: Benedikt Werner <1benediktwerner@gmail.com> Date: Sat, 13 May 2023 23:27:42 +0200 Subject: [PATCH 5/5] Don't need type doc comments when we already have type hints in the code --- berserk/clients.py | 1 - 1 file changed, 1 deletion(-) diff --git a/berserk/clients.py b/berserk/clients.py index 3a0b81a..e3efc37 100644 --- a/berserk/clients.py +++ b/berserk/clients.py @@ -1082,7 +1082,6 @@ 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 - :type limit: int, optional :return: iterator over online bots """ path = "api/bot/online"