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 |
|
| 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 |
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -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",
|
||||||
|
|
Loading…
Reference in New Issue