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,59 +45,61 @@ 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':
|
||||||
regex_blacklist: dict = await config.regex_blacklist()
|
content = remove_ansi_escape_codes(message['args'][0])
|
||||||
matches = [re.search(regex, message['args'][0]) for regex in regex_blacklist.values()]
|
if await config.mask_ip() is True:
|
||||||
|
content = mask_ip(content)
|
||||||
|
logger.verbose("Received console output: %s", content)
|
||||||
|
|
||||||
if await config.current_status() in ('running', '') and not any(matches):
|
if await config.console_channel() is not None:
|
||||||
content = remove_ansi_escape_codes(message['args'][0])
|
regex_blacklist: dict = await config.regex_blacklist()
|
||||||
if await config.mask_ip() is True:
|
matches = [re.search(regex, message['args'][0]) for regex in regex_blacklist.values()]
|
||||||
content = mask_ip(content)
|
|
||||||
|
|
||||||
console_channel = coginstance.bot.get_channel(await config.console_channel())
|
if await config.current_status() in ('running', '') and not any(matches):
|
||||||
chat_channel = coginstance.bot.get_channel(await config.chat_channel())
|
console_channel = coginstance.bot.get_channel(await config.console_channel())
|
||||||
if console_channel is not None:
|
chat_channel = coginstance.bot.get_channel(await config.chat_channel())
|
||||||
if content.startswith('['):
|
if console_channel is not None:
|
||||||
pagified_content = pagify(content, delims=[" ", "\n"])
|
if content.startswith('['):
|
||||||
for page in pagified_content:
|
pagified_content = pagify(content, delims=[" ", "\n"])
|
||||||
await console_channel.send(content=page, allowed_mentions=discord.AllowedMentions.none())
|
for page in pagified_content:
|
||||||
|
await console_channel.send(content=page, allowed_mentions=discord.AllowedMentions.none())
|
||||||
|
|
||||||
server_message = await check_if_server_message(content)
|
server_message = await check_if_server_message(content)
|
||||||
if server_message:
|
if server_message:
|
||||||
if chat_channel is not None:
|
if chat_channel is not None:
|
||||||
await chat_channel.send(server_message if len(server_message) < 2000 else server_message[:1997] + '...', allowed_mentions=discord.AllowedMentions.none())
|
await chat_channel.send(server_message if len(server_message) < 2000 else server_message[:1997] + '...', allowed_mentions=discord.AllowedMentions.none())
|
||||||
|
|
||||||
chat_message = await check_if_chat_message(content)
|
chat_message = await check_if_chat_message(content)
|
||||||
if chat_message:
|
if chat_message:
|
||||||
info = await get_info(chat_message['username'])
|
info = await get_info(chat_message['username'])
|
||||||
if info is not None:
|
if info is not None:
|
||||||
await send_chat_discord(coginstance, chat_message['username'], chat_message['message'], info['data']['player']['avatar'])
|
await send_chat_discord(coginstance, chat_message['username'], chat_message['message'], info['data']['player']['avatar'])
|
||||||
else:
|
|
||||||
await send_chat_discord(coginstance, chat_message['username'], chat_message['message'], 'https://seafsh.cc/u/j3AzqQ.png')
|
|
||||||
|
|
||||||
join_message = await check_if_join_message(content)
|
|
||||||
if join_message:
|
|
||||||
if chat_channel is not None:
|
|
||||||
if coginstance.bot.embed_requested(chat_channel):
|
|
||||||
await chat_channel.send(embed=await generate_join_leave_embed(join_message, True))
|
|
||||||
else:
|
else:
|
||||||
await chat_channel.send(f"{join_message} joined the game", allowed_mentions=discord.AllowedMentions.none())
|
await send_chat_discord(coginstance, chat_message['username'], chat_message['message'], 'https://seafsh.cc/u/j3AzqQ.png')
|
||||||
|
|
||||||
leave_message = await check_if_leave_message(content)
|
join_message = await check_if_join_message(content)
|
||||||
if leave_message:
|
if join_message:
|
||||||
if chat_channel is not None:
|
if chat_channel is not None:
|
||||||
if coginstance.bot.embed_requested(chat_channel):
|
if coginstance.bot.embed_requested(chat_channel):
|
||||||
await chat_channel.send(embed=await generate_join_leave_embed(leave_message, False))
|
await chat_channel.send(embed=await generate_join_leave_embed(join_message, True))
|
||||||
else:
|
else:
|
||||||
await chat_channel.send(f"{leave_message} left the game", allowed_mentions=discord.AllowedMentions.none())
|
await chat_channel.send(f"{join_message} joined the game", allowed_mentions=discord.AllowedMentions.none())
|
||||||
|
|
||||||
achievement_message = await check_if_achievement_message(content)
|
leave_message = await check_if_leave_message(content)
|
||||||
if achievement_message:
|
if leave_message:
|
||||||
if chat_channel is not None:
|
if chat_channel is not None:
|
||||||
if coginstance.bot.embed_requested(chat_channel):
|
if coginstance.bot.embed_requested(chat_channel):
|
||||||
await chat_channel.send(embed=await generate_achievement_embed(achievement_message['username'], achievement_message['achievement'], achievement_message['challenge']))
|
await chat_channel.send(embed=await generate_join_leave_embed(leave_message, False))
|
||||||
else:
|
else:
|
||||||
await chat_channel.send(f"{achievement_message['username']} has {'completed the challenge' if achievement_message['challenge'] else 'made the advancement'} {achievement_message['achievement']}")
|
await chat_channel.send(f"{leave_message} left the game", allowed_mentions=discord.AllowedMentions.none())
|
||||||
|
|
||||||
|
achievement_message = await check_if_achievement_message(content)
|
||||||
|
if achievement_message:
|
||||||
|
if chat_channel is not None:
|
||||||
|
if coginstance.bot.embed_requested(chat_channel):
|
||||||
|
await chat_channel.send(embed=await generate_achievement_embed(achievement_message['username'], achievement_message['achievement'], achievement_message['challenge']))
|
||||||
|
else:
|
||||||
|
await chat_channel.send(f"{achievement_message['username']} has {'completed the challenge' if achievement_message['challenge'] else 'made the advancement'} {achievement_message['achievement']}")
|
||||||
|
|
||||||
if message['event'] == 'status':
|
if message['event'] == 'status':
|
||||||
old_status = await config.current_status()
|
old_status = await config.current_status()
|
||||||
|
@ -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