Add Pterodactyl cog #19
1 changed files with 44 additions and 45 deletions
|
@ -71,7 +71,7 @@ class Pterodactyl(commands.Cog):
|
|||
|
||||
while True:
|
||||
message = await websocket.recv()
|
||||
if json.loads(message)['event'] in ['token expiring', 'token expired']:
|
||||
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']]})
|
||||
|
@ -82,7 +82,7 @@ class Pterodactyl(commands.Cog):
|
|||
self.logger.info("WebSocket authentication successful")
|
||||
|
||||
if json.loads(message)['event'] == 'console output' and await self.config.console_channel() is not None:
|
||||
if current_status == 'running' or current_status == 'offline' or current_status == '':
|
||||
if current_status in ('running', 'offline', ''):
|
||||
content = self.remove_ansi_escape_codes(json.loads(message)['args'][0])
|
||||
|
||||
channel = self.bot.get_channel(await self.config.console_channel())
|
||||
|
@ -117,9 +117,9 @@ class Pterodactyl(commands.Cog):
|
|||
regex = await self.config.chat_regex()
|
||||
match: Optional[re.Match[str]] = re.match(regex, text)
|
||||
if match:
|
||||
dict = {"time": match.group(1), "username": match.group(2), "message": match.group(3)}
|
||||
self.logger.debug("Message is a chat message\n%s", json.dumps(dict))
|
||||
return dict
|
||||
groups = {"time": match.group(1), "username": match.group(2), "message": match.group(3)}
|
||||
self.logger.debug("Message is a chat message\n%s", json.dumps(groups))
|
||||
return groups
|
||||
self.logger.debug("Message is not a chat message")
|
||||
return False
|
||||
|
||||
|
@ -131,7 +131,6 @@ class Pterodactyl(commands.Cog):
|
|||
if response.status == 200:
|
||||
self.logger.debug("Player info retrieved for %s\n%s", username, json.dumps(await response.json()))
|
||||
return await response.json()
|
||||
else:
|
||||
self.logger.error("Failed to retrieve player info for %s: %s", username, response.status)
|
||||
return None
|
||||
|
||||
|
@ -165,7 +164,7 @@ class Pterodactyl(commands.Cog):
|
|||
fut.result()
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
except Exception as e:
|
||||
except Exception as e: # pylint: disable=broad-exception-caught
|
||||
self.logger.error("WebSocket task has failed: %s", e, exc_info=e)
|
||||
self.task.cancel()
|
||||
self.task = self.get_task()
|
||||
|
|
Loading…
Reference in a new issue