forked from cswimr/SeaCogs
feat(pterodactyl): server status will persist through reloads
This commit is contained in:
parent
a4f68d55eb
commit
d39f0ba104
2 changed files with 18 additions and 7 deletions
|
@ -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"}]',
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue