Add Pterodactyl cog #19

Merged
cswimr merged 139 commits from pterodactyl into main 2024-03-01 23:07:42 -06:00
Showing only changes of commit 6e6559d80c - Show all commits

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):