[+] Added exception handling to query

This commit is contained in:
Charles Le Maux 2024-09-06 17:56:56 +02:00
parent c9c542dcbc
commit 46dcb39495

View File

@ -6,6 +6,7 @@ from typing import Union
import mcipc.query
import mcipc.query.client
import file_manager
import firebase_manager
@ -87,9 +88,13 @@ class MinecraftServerManager:
def get_online_players(self, port) -> int:
if not self.servers[port]:
return 0
with mcipc.query.Client('127.0.0.1', port) as client:
stats: int = client.stats(full=False).num_players
return stats
try:
with mcipc.query.Client('127.0.0.1', port) as client:
stats: int = client.stats(full=False).num_players
return stats
except Exception as e:
file_manager.log_error(type(e).__name__, str(e))
return 0
def set_cooldown(self, user_id):
expiry_timestamp = time.time() + 30