feat(pterodactyl): server status will persist through reloads
Some checks failed
Actions / Lint Code (Ruff & Pylint) (pull_request) Failing after 18s
Actions / Build Documentation (MkDocs) (pull_request) Successful in 22s

This commit is contained in:
Seaswimmer 2024-03-01 00:02:42 -05:00
parent a4f68d55eb
commit d39f0ba104
Signed by: cswimr
GPG key ID: B8953EC01E5C4063
2 changed files with 18 additions and 7 deletions

View file

@ -10,7 +10,7 @@ def register_config(config_obj: Config) -> None:
console_channel=None,
startup_jar=None,
startup_arguments=None,
power_action_in_progress=False,
current_status='',
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"}]',

View file

@ -29,7 +29,6 @@ async def establish_websocket_connection(coginstance: Pterodactyl) -> None:
logger.debug("Authentication message sent")
coginstance.websocket = websocket
current_status = ''
while True: # pylint: disable=too-many-nested-blocks
message = await websocket.recv()
@ -44,7 +43,7 @@ async def establish_websocket_connection(coginstance: Pterodactyl) -> None:
logger.info("WebSocket authentication successful")
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])
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] + '...')
if json.loads(message)['event'] == 'status':
old_status = await config.current_status()
current_status = json.loads(message)['args'][0]
if await config.console_channel() is not None:
console = coginstance.bot.get_channel(await config.console_channel())
if console is not None:
await console.send(f"Server status changed! `{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:
console = coginstance.bot.get_channel(await config.console_channel())
if console is not None:
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]:
base_url = await config.base_url()