18 lines
827 B
Python
18 lines
827 B
Python
import aiohttp
|
|
|
|
|
|
async def get_status(host: str, port: int = 25565) -> tuple[bool, dict]:
|
|
"""Get the status of a Minecraft server using the [mcsrvstat.us API](https://api.mcsrvstat.us).
|
|
|
|
Args:
|
|
host (str): The host of the server.
|
|
port (int, optional): The port to connect to. Defaults to 25565.
|
|
|
|
Returns:
|
|
A tuple containing a boolean and a dictionary. The boolean is True if the server is online, or False if it is offline. The dictionary contains the response from the API."""
|
|
async with aiohttp.ClientSession() as session:
|
|
async with session.get(f"https://api.mcsrvstat.us/2/{host}:{port}") as response:
|
|
response = await response.json() # noqa: PLW2901
|
|
if response["online"]:
|
|
return (True, response)
|
|
return (False, response)
|