mirror of
https://github.com/catspace-dev/unicheckbot.git
synced 2024-11-24 23:03:45 +03:00
added minecraft checker
This commit is contained in:
parent
e57ab2dc49
commit
cad7e8d8c1
37
apps/api/api/checkers/minecraft.py
Normal file
37
apps/api/api/checkers/minecraft.py
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
from core.coretypes import Response, PortResponse, ErrorPayload, ErrorCodes, MinecraftResponse, ResponseStatus
|
||||||
|
from mcstatus import MinecraftServer
|
||||||
|
from .base import BaseChecker
|
||||||
|
import socket
|
||||||
|
|
||||||
|
|
||||||
|
class MinecraftChecker(BaseChecker):
|
||||||
|
|
||||||
|
def __init__(self, target: str, port: int):
|
||||||
|
self.port = port
|
||||||
|
super().__init__(target)
|
||||||
|
|
||||||
|
def check(self) -> Response:
|
||||||
|
try:
|
||||||
|
server = MinecraftServer.lookup(f"{self.target}:{self.port}")
|
||||||
|
status = server.status()
|
||||||
|
except socket.gaierror:
|
||||||
|
return Response(
|
||||||
|
status=ResponseStatus.ERROR,
|
||||||
|
payload=ErrorPayload(
|
||||||
|
message="Server does not respond!",
|
||||||
|
code=ErrorCodes.ConnectError
|
||||||
|
),
|
||||||
|
node=self.node_info
|
||||||
|
)
|
||||||
|
return Response(
|
||||||
|
status=ResponseStatus.OK,
|
||||||
|
payload=MinecraftResponse(
|
||||||
|
latency=status.latency,
|
||||||
|
max_players=status.players.max,
|
||||||
|
online=status.players.online
|
||||||
|
),
|
||||||
|
node=self.node_info
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user