feat(pterodactyl): added more verbose debug logging to establish_websocket_connection

This commit is contained in:
Seaswimmer 2024-02-28 08:10:46 -05:00
parent dcf0165a8a
commit 6e6559d80c
Signed by: cswimr
GPG key ID: B8953EC01E5C4063

View file

@ -29,6 +29,7 @@ class Pterodactyl(commands.Cog):
try:
client = PterodactylClient(base_url, api_key).client
websocket_credentials = client.servers.get_websocket(server_id)
self.logger.debug("Websocket connection details retrieved: " + websocket_credentials)
except exceptions.ClientConfigError as e:
self.logger.error(f'Failed to initialize Pterodactyl client: {e}')
return
@ -49,9 +50,14 @@ class Pterodactyl(commands.Cog):
while True:
message = await websocket.recv()
if json.loads(message)['event'] == 'token expiring':
if json.loads(message)['event'] in ['token expiring', 'token expired']:
self.logger.debug("Received token expiring/expired event. Refreshing token.")
websocket_credentials = client.servers.get_websocket(server_id)
auth_message = json.dumps({"event": "auth", "args": [websocket_credentials['data']['token']]})
await websocket.send(auth_message)
self.logger.debug("Authentication message sent")
if json.loads(message)['event'] == 'auth success':
self.logger.debug("Authentication successful")
self.logger.debug("Received message: %s", message)
async def cog_load(self):