From 62e8aad3a81982c6d0573409c80cc809d6c90830 Mon Sep 17 00:00:00 2001 From: trueold89 Date: Sun, 7 Jul 2024 23:02:28 +0300 Subject: [PATCH] Add all_info property --- README.md | 2 ++ mcaio/cli.py | 6 ++++++ mcaio/client.py | 18 ++++++++++++++++++ setup.py | 2 +- 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 803e532..41d3dc3 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ print(name) | players_count | Current number of players on the server | | maxplayers | Max number of players on the server | | players_list | List of current players on server | +| all_info | Dict with all information about server | ### As cli: @@ -85,3 +86,4 @@ MC_HOST=localhost MC_PORT=25565 mcaio name | pcount | Current number of players on the server | | pmax | Max number of players on the server | | players | List of current players on server | +| all | Dict with all information about server | diff --git a/mcaio/cli.py b/mcaio/cli.py index 2e9dc65..ad38863 100644 --- a/mcaio/cli.py +++ b/mcaio/cli.py @@ -37,6 +37,10 @@ async def get_players(server: AIOMCServer) -> tuple: return tuple(await server.players_list) +async def get_all(server: AIOMCServer) -> dict: + return await server.all_info + + async def action() -> None: try: HOST, PORT = get_env("MC_HOST"), int(get_env("MC_PORT")) @@ -52,6 +56,8 @@ async def action() -> None: out = get_motd(server) case "players": out = get_players(server) + case 'all': + out = get_all(server) case _: raise RuntimeError print(await out) diff --git a/mcaio/client.py b/mcaio/client.py index 02a2450..ee14031 100644 --- a/mcaio/client.py +++ b/mcaio/client.py @@ -65,6 +65,11 @@ class IMCServer(ABC): async def players_list(self) -> Iterable: raise NotImplementedError + @property + @abstractmethod + async def all_info(self) -> dict: + raise NotImplementedError + class AIOMCServer(IMCServer): @@ -160,3 +165,16 @@ class AIOMCServer(IMCServer): async def players_list(self) -> Iterable: await self.update() return self._players + + @property + async def all_info(self) -> dict: + await self.update() + return { + "name": self._name, + "motd": self._motd, + "players": { + "max": self._max, + "online": self._count, + "list": self._players + } + } diff --git a/setup.py b/setup.py index d6aeed6..a66ff9e 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ long_description = (this_directory / "README.md").read_text() setup( name="mcaio", - version="0.1", + version="0.2", url="https://git.orudo.ru/trueold89/mcaio", author="trueold89", author_email="trueold89@orudo.ru",