SeaCogs/pterodactyl/mcsrvstatus.py
cswimr 3fdb0836cf
Some checks are pending
Actions / Lint Code (Ruff & Pylint) (push) Waiting to run
Actions / Build Documentation (MkDocs) (push) Waiting to run
chore(pterodactyl): bump version
2025-02-21 10:27:10 -06:00

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)