Add all_info property

This commit is contained in:
trueold89 2024-07-07 23:02:28 +03:00
parent c56bc396fe
commit 62e8aad3a8
Signed by: trueold89
GPG Key ID: C122E85DD49E6B30
4 changed files with 27 additions and 1 deletions

View File

@ -69,6 +69,7 @@ print(name)
| players_count | Current number of players on the server | | players_count | Current number of players on the server |
| maxplayers | Max number of players on the server | | maxplayers | Max number of players on the server |
| players_list | List of current players on server | | players_list | List of current players on server |
| all_info | Dict with all information about server |
### As cli: ### As cli:
@ -85,3 +86,4 @@ MC_HOST=localhost MC_PORT=25565 mcaio name
| pcount | Current number of players on the server | | pcount | Current number of players on the server |
| pmax | Max number of players on the server | | pmax | Max number of players on the server |
| players | List of current players on server | | players | List of current players on server |
| all | Dict with all information about server |

View File

@ -37,6 +37,10 @@ async def get_players(server: AIOMCServer) -> tuple:
return tuple(await server.players_list) return tuple(await server.players_list)
async def get_all(server: AIOMCServer) -> dict:
return await server.all_info
async def action() -> None: async def action() -> None:
try: try:
HOST, PORT = get_env("MC_HOST"), int(get_env("MC_PORT")) HOST, PORT = get_env("MC_HOST"), int(get_env("MC_PORT"))
@ -52,6 +56,8 @@ async def action() -> None:
out = get_motd(server) out = get_motd(server)
case "players": case "players":
out = get_players(server) out = get_players(server)
case 'all':
out = get_all(server)
case _: case _:
raise RuntimeError raise RuntimeError
print(await out) print(await out)

View File

@ -65,6 +65,11 @@ class IMCServer(ABC):
async def players_list(self) -> Iterable: async def players_list(self) -> Iterable:
raise NotImplementedError raise NotImplementedError
@property
@abstractmethod
async def all_info(self) -> dict:
raise NotImplementedError
class AIOMCServer(IMCServer): class AIOMCServer(IMCServer):
@ -160,3 +165,16 @@ class AIOMCServer(IMCServer):
async def players_list(self) -> Iterable: async def players_list(self) -> Iterable:
await self.update() await self.update()
return self._players 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
}
}

View File

@ -6,7 +6,7 @@ long_description = (this_directory / "README.md").read_text()
setup( setup(
name="mcaio", name="mcaio",
version="0.1", version="0.2",
url="https://git.orudo.ru/trueold89/mcaio", url="https://git.orudo.ru/trueold89/mcaio",
author="trueold89", author="trueold89",
author_email="trueold89@orudo.ru", author_email="trueold89@orudo.ru",