Add Pterodactyl cog #19

Merged
cswimr merged 139 commits from pterodactyl into main 2024-03-02 00:07:42 -05:00
2 changed files with 18 additions and 7 deletions
Showing only changes of commit d39f0ba104 - Show all commits

View file

@ -10,7 +10,7 @@ def register_config(config_obj: Config) -> None:
console_channel=None, console_channel=None,
startup_jar=None, startup_jar=None,
startup_arguments=None, startup_arguments=None,
power_action_in_progress=False, current_status='',
chat_regex=r"\[(\d{2}:\d{2}:\d{2})\sINFO\]:\s<(\w+)>\s(.*)", 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\] \[.*\] (.*)", 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"}]', chat_command='tellraw @a ["",{"text":".$U ","color":".$C"},{"text":" (DISCORD): ","color":"blue"},{"text":".$M","color":"white"}]',

View file

@ -29,7 +29,6 @@ async def establish_websocket_connection(coginstance: Pterodactyl) -> None:
logger.debug("Authentication message sent") logger.debug("Authentication message sent")
coginstance.websocket = websocket coginstance.websocket = websocket
current_status = ''
while True: # pylint: disable=too-many-nested-blocks while True: # pylint: disable=too-many-nested-blocks
message = await websocket.recv() message = await websocket.recv()
@ -44,7 +43,7 @@ async def establish_websocket_connection(coginstance: Pterodactyl) -> None:
logger.info("WebSocket authentication successful") logger.info("WebSocket authentication successful")
if json.loads(message)['event'] == 'console output' and await config.console_channel() is not None: if json.loads(message)['event'] == 'console output' and await config.console_channel() is not None:
if current_status in ('running', 'offline', ''): if await config.current_status() in ('running', 'offline', ''):
content = remove_ansi_escape_codes(json.loads(message)['args'][0]) content = remove_ansi_escape_codes(json.loads(message)['args'][0])
channel = coginstance.bot.get_channel(await config.console_channel()) channel = coginstance.bot.get_channel(await config.console_channel())
@ -69,11 +68,23 @@ async def establish_websocket_connection(coginstance: Pterodactyl) -> None:
await channel.send(server_message if len(server_message) < 2000 else server_message[:1997] + '...') await channel.send(server_message if len(server_message) < 2000 else server_message[:1997] + '...')
if json.loads(message)['event'] == 'status': if json.loads(message)['event'] == 'status':
old_status = await config.current_status()
current_status = json.loads(message)['args'][0] current_status = json.loads(message)['args'][0]
if old_status != current_status:
await config.current_status.set(current_status)
if await config.console_channel() is not None: if await config.console_channel() is not None:
console = coginstance.bot.get_channel(await config.console_channel()) console = coginstance.bot.get_channel(await config.console_channel())
if console is not None: if console is not None:
await console.send(f"Server status changed! `{json.loads(message)['args'][0]}`") await console.send(f"Server status changed! `{current_status}`")
if await config.chat_channel() is not None:
if current_status == 'running' and await config.startup_msg() is not None:
chat = coginstance.bot.get_channel(await config.chat_channel())
if chat is not None:
await chat.send(await config.startup_msg())
if current_status == 'stopping' and await config.shutdown_msg() is not None:
chat = coginstance.bot.get_channel(await config.chat_channel())
if chat is not None:
await chat.send(await config.shutdown_msg())
async def retrieve_websocket_credentials(coginstance: Pterodactyl) -> Optional[dict]: async def retrieve_websocket_credentials(coginstance: Pterodactyl) -> Optional[dict]:
base_url = await config.base_url() base_url = await config.base_url()