From 39ae8b5ea0b15375d93ac6593f60aee175cca95c Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Wed, 28 Feb 2024 13:39:40 -0500 Subject: [PATCH] fix(pterodactyl): do not log during startup/shutdown to avoid the console channel getting flooded and ratelimited --- pterodactyl/pterodactyl.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pterodactyl/pterodactyl.py b/pterodactyl/pterodactyl.py index 86fe5fa..9bfbde9 100644 --- a/pterodactyl/pterodactyl.py +++ b/pterodactyl/pterodactyl.py @@ -65,6 +65,7 @@ class Pterodactyl(commands.Cog): while True: message = await websocket.recv() + current_status = '' if json.loads(message)['event'] in ['token expiring', 'token expired']: self.logger.debug("Received token expiring/expired event. Refreshing token.") websocket_credentials = client.servers.get_websocket(server_id) @@ -76,14 +77,16 @@ class Pterodactyl(commands.Cog): self.logger.debug("Authentication successful") if json.loads(message)['event'] == 'console output' and await self.config.console_channel() is not None: - channel = self.bot.get_channel(await self.config.console_channel()) - if channel is not None: - content = self.remove_ansi_escape_codes(json.loads(message)['args'][0][:1900]) - if content.startswith('['): - await channel.send(content=content) - #TODO - Add pagification for long messages to prevent Discord API errors + if current_status != 'starting' and current_status != 'stopping' and current_status != 'restarting': + channel = self.bot.get_channel(await self.config.console_channel()) + if channel is not None: + content = self.remove_ansi_escape_codes(json.loads(message)['args'][0][:1900]) + if content.startswith('['): + await channel.send(content=content) + #TODO - Add pagification for long messages to prevent Discord API errors if json.loads(message)['event'] == 'status': + current_status = json.loads(message)['args'][0] console = self.bot.get_channel(await self.config.console_channel()) if console is not None: await console.send(f"Server status changed! `{json.loads(message)['args'][0]}`")