Compare commits
1 commit
main
...
pterodacty
Author | SHA1 | Date | |
---|---|---|---|
e90dc60643 |
1 changed files with 51 additions and 48 deletions
|
@ -34,6 +34,7 @@ async def establish_websocket_connection(coginstance: Pterodactyl) -> None:
|
||||||
|
|
||||||
while True: # pylint: disable=too-many-nested-blocks
|
while True: # pylint: disable=too-many-nested-blocks
|
||||||
message = json.loads(await websocket.recv())
|
message = json.loads(await websocket.recv())
|
||||||
|
logger.verbose("Received message: %s", message)
|
||||||
if message['event'] in ('token expiring', 'token expired'):
|
if message['event'] in ('token expiring', 'token expired'):
|
||||||
logger.info("Received token expiring/expired event. Refreshing token.")
|
logger.info("Received token expiring/expired event. Refreshing token.")
|
||||||
websocket_credentials = await retrieve_websocket_credentials(coginstance)
|
websocket_credentials = await retrieve_websocket_credentials(coginstance)
|
||||||
|
@ -44,15 +45,17 @@ async def establish_websocket_connection(coginstance: Pterodactyl) -> None:
|
||||||
if message['event'] == 'auth success':
|
if message['event'] == 'auth success':
|
||||||
logger.info("WebSocket authentication successful")
|
logger.info("WebSocket authentication successful")
|
||||||
|
|
||||||
if message['event'] == 'console output' and await config.console_channel() is not None:
|
if message['event'] == 'console output':
|
||||||
|
content = remove_ansi_escape_codes(message['args'][0])
|
||||||
|
if await config.mask_ip() is True:
|
||||||
|
content = mask_ip(content)
|
||||||
|
logger.verbose("Received console output: %s", content)
|
||||||
|
|
||||||
|
if await config.console_channel() is not None:
|
||||||
regex_blacklist: dict = await config.regex_blacklist()
|
regex_blacklist: dict = await config.regex_blacklist()
|
||||||
matches = [re.search(regex, message['args'][0]) for regex in regex_blacklist.values()]
|
matches = [re.search(regex, message['args'][0]) for regex in regex_blacklist.values()]
|
||||||
|
|
||||||
if await config.current_status() in ('running', '') and not any(matches):
|
if await config.current_status() in ('running', '') and not any(matches):
|
||||||
content = remove_ansi_escape_codes(message['args'][0])
|
|
||||||
if await config.mask_ip() is True:
|
|
||||||
content = mask_ip(content)
|
|
||||||
|
|
||||||
console_channel = coginstance.bot.get_channel(await config.console_channel())
|
console_channel = coginstance.bot.get_channel(await config.console_channel())
|
||||||
chat_channel = coginstance.bot.get_channel(await config.chat_channel())
|
chat_channel = coginstance.bot.get_channel(await config.chat_channel())
|
||||||
if console_channel is not None:
|
if console_channel is not None:
|
||||||
|
@ -142,11 +145,11 @@ async def retrieve_websocket_credentials(coginstance: Pterodactyl) -> Optional[d
|
||||||
websocket_credentials['data']['token'][:20]
|
websocket_credentials['data']['token'][:20]
|
||||||
)
|
)
|
||||||
return websocket_credentials
|
return websocket_credentials
|
||||||
#NOTE - The token is truncated to prevent it from being logged in its entirety, for security reasons
|
# The token is truncated to prevent it from being logged in its entirety, for security reasons
|
||||||
|
|
||||||
def remove_ansi_escape_codes(text: str) -> str:
|
def remove_ansi_escape_codes(text: str) -> str:
|
||||||
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
|
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
|
||||||
#NOTE - https://chat.openai.com/share/d92f9acf-d776-4fd6-a53f-b14ac15dd540
|
# https://chatgpt.com/share/d92f9acf-d776-4fd6-a53f-b14ac15dd540
|
||||||
return ansi_escape.sub('', text)
|
return ansi_escape.sub('', text)
|
||||||
|
|
||||||
async def check_if_server_message(text: str) -> Union[bool, str]:
|
async def check_if_server_message(text: str) -> Union[bool, str]:
|
||||||
|
|
Loading…
Reference in a new issue