Add all_info property
This commit is contained in:
parent
c56bc396fe
commit
62e8aad3a8
|
@ -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 |
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue