feat(pterodactyl): added support for bridging messages sent by the server
Some checks failed
Actions / Lint Code (Ruff & Pylint) (pull_request) Failing after 18s
Actions / Build Documentation (MkDocs) (pull_request) Successful in 21s

This commit is contained in:
SeaswimmerTheFsh 2024-02-29 23:50:54 -05:00
parent 457f1da7f4
commit 0d21a52ce3
Signed by: cswimr
GPG key ID: B8953EC01E5C4063
3 changed files with 29 additions and 0 deletions

View file

@ -65,6 +65,12 @@ async def loop(coginstance: Pterodactyl, websocket: websockets.WebSocketClientPr
else:
await send_chat_discord(coginstance, chat_message['username'], chat_message['message'], 'https://seafsh.cc/u/j3AzqQ.png')
server_message = await check_if_server_message(content)
if server_message:
channel = coginstance.bot.get_channel(await config.chat_channel())
if channel is not None:
await channel.send(server_message if len(server_message) < 2000 else server_message[:1997] + '...')
if json.loads(message)['event'] == 'status':
current_status = json.loads(message)['args'][0]
if await config.console_channel() is not None:
@ -99,6 +105,16 @@ def remove_ansi_escape_codes(text: str) -> str:
#NOTE - https://chat.openai.com/share/d92f9acf-d776-4fd6-a53f-b14ac15dd540
return ansi_escape.sub('', text)
async def check_if_server_message(text: str) -> Union[bool, str]:
logger.debug("Checking if message is a server message")
regex = await config.server_regex()
match: Optional[re.Match[str]] = re.match(regex, text)
if match:
logger.debug("Message is a server message")
return match.group(1)
logger.debug("Message is not a server message")
return False
async def check_if_chat_message(text: str) -> Union[bool, dict]:
logger.debug("Checking if message is a chat message")
regex = await config.chat_regex()