feat(pterodactyl): added support for bridging messages sent by the server

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

View file

@ -12,6 +12,7 @@ def register_config(config_obj: Config) -> None:
startup_arguments=None,
power_action_in_progress=False,
chat_regex=r"\[(\d{2}:\d{2}:\d{2})\sINFO\]:\s<(\w+)>\s(.*)",
server_regex=r"^\[\d{2}:\d{2}:\d{2} INFO\]: \[Not Secure\] \[.*\] (.*)",
chat_command='tellraw @a ["",{"text":".$U ","color":".$C"},{"text":" (DISCORD): ","color":"blue"},{"text":".$M","color":"white"}]',
api_endpoint="minecraft",
chat_channel=None

View file

@ -153,3 +153,15 @@ class Pterodactyl(commands.Cog):
return await ctx.send(f"Chat command is currently set to:\n{box(command, 'json')}")
await config.chat_command.set(command)
await ctx.send(f"Chat command set to:\n{box(command, 'json')}")
@pterodactyl_config_chat.command(name = "server")
async def pterodactyl_config_chat_server(self, ctx: commands.Context, *, regex: str = None) -> None:
"""Set the regex pattern to match server messages on the server.
See [documentation]() for more information."""
#TODO - fix this link
if regex is None:
regex = await config.server_regex()
return await ctx.send(f"Server regex is currently set to:\n{box(regex, 'regex')}")
await config.server_regex.set(regex)
await ctx.send(f"Server regex set to:\n{box(regex, 'regex')}")

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()