34 lines
1 KiB
Python
34 lines
1 KiB
Python
import os, json
|
|
from mcstatus import JavaServer
|
|
|
|
LINKS_DB = "/root/flexicraft-discord-setup/data/crossplay_links.json"
|
|
|
|
def get_live_status(host="151.247.192.82", port=25565):
|
|
try:
|
|
srv = JavaServer.lookup(f"{host}:{port}")
|
|
st = srv.status()
|
|
players = [p.name for p in st.players.sample] if st.players.sample else []
|
|
return {
|
|
"online": True,
|
|
"players_online": st.players.online,
|
|
"players_max": st.players.max,
|
|
"players_list": players,
|
|
"version": "Paper 1.21.11 (1.9 → 1.21.11+)"
|
|
}
|
|
except Exception:
|
|
return {
|
|
"online": False,
|
|
"players_online": 0,
|
|
"players_max": 25,
|
|
"players_list": [],
|
|
"version": "Paper 1.21.11"
|
|
}
|
|
|
|
def get_citizens_count():
|
|
if os.path.exists(LINKS_DB):
|
|
try:
|
|
with open(LINKS_DB, "r", encoding="utf-8") as f:
|
|
return len(json.load(f))
|
|
except Exception:
|
|
pass
|
|
return 0
|