forked from cswimr/SeaCogs
fix(pterodactyl): cleanup
This commit is contained in:
parent
f2d54ce23b
commit
b775439967
1 changed files with 15 additions and 22 deletions
|
@ -7,7 +7,7 @@ from typing import Optional, Union
|
|||
import aiohttp
|
||||
import discord
|
||||
import websockets
|
||||
from pydactyl import PterodactylClient, exceptions
|
||||
from pydactyl import PterodactylClient
|
||||
from redbot.core.utils.chat_formatting import pagify
|
||||
|
||||
from pterodactyl.config import config
|
||||
|
@ -21,8 +21,6 @@ async def establish_websocket_connection(coginstance: Pterodactyl) -> None:
|
|||
logger.info("Establishing WebSocket connection")
|
||||
|
||||
websocket_credentials = await retrieve_websocket_credentials(coginstance)
|
||||
if not websocket_credentials:
|
||||
return logger.error("Failed to retrieve WebSocket credentials. WebSocket connection not established")
|
||||
|
||||
async with websockets.connect(websocket_credentials['data']['socket'], origin=base_url, ping_timeout=60, logger=getLogger("red.sea.pterodactyl.websocket")) as websocket:
|
||||
logger.info("WebSocket connection established")
|
||||
|
@ -121,17 +119,16 @@ async def retrieve_websocket_credentials(coginstance: Pterodactyl) -> Optional[d
|
|||
api_key = pterodactyl_keys.get("api_key")
|
||||
if api_key is None:
|
||||
coginstance.task.cancel()
|
||||
return logger.error("Pterodactyl API key not set. Please set it using `[p]set api`.")
|
||||
raise ValueError("Pterodactyl API key not set. Please set it using `[p]set api`.")
|
||||
base_url = await config.base_url()
|
||||
if base_url is None:
|
||||
coginstance.task.cancel()
|
||||
return logger.error("Pterodactyl base URL not set. Please set it using `[p]ptero set url`.")
|
||||
raise ValueError("Pterodactyl base URL not set. Please set it using `[p]pterodactyl config url`.")
|
||||
server_id = await config.server_id()
|
||||
if server_id is None:
|
||||
coginstance.task.cancel()
|
||||
return logger.error("Pterodactyl server ID not set. Please set it using `[p]ptero set serverid`.")
|
||||
raise ValueError("Pterodactyl server ID not set. Please set it using `[p]pterodactyl config serverid`.")
|
||||
|
||||
try:
|
||||
client = PterodactylClient(base_url, api_key, debug=True).client
|
||||
coginstance.client = client
|
||||
websocket_credentials = client.servers.get_websocket(server_id)
|
||||
|
@ -143,10 +140,6 @@ async def retrieve_websocket_credentials(coginstance: Pterodactyl) -> Optional[d
|
|||
)
|
||||
return websocket_credentials
|
||||
#NOTE - The token is truncated to prevent it from being logged in its entirety, for security reasons
|
||||
except exceptions.ClientConfigError as e:
|
||||
return logger.error('Failed to initialize Pterodactyl client: %s', e)
|
||||
except exceptions.PterodactylApiError as e:
|
||||
return logger.error('Failed to retrieve Pterodactyl websocket: %s', e)
|
||||
|
||||
def remove_ansi_escape_codes(text: str) -> str:
|
||||
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
|
||||
|
|
Loading…
Reference in a new issue