From 50dd5c64b45fb02f580b8f33778aaafab68e70f8 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Thu, 29 Feb 2024 20:59:47 -0500 Subject: [PATCH] fix(pterodactyl): added error messages for if the websocket connection is closed --- pterodactyl/pterodactyl.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pterodactyl/pterodactyl.py b/pterodactyl/pterodactyl.py index aab394d..64690ab 100644 --- a/pterodactyl/pterodactyl.py +++ b/pterodactyl/pterodactyl.py @@ -177,7 +177,12 @@ class Pterodactyl(commands.Cog): if message.channel.id == await self.config.console_channel() and not message.author.bot: self.logger.debug("Received console command from %s: %s", message.author.id, message.content) await message.channel.send(f"Received console command from {message.author.id}: {message.content[:1900]}") - await self.websocket.send(json.dumps({"event": "send command", "args": [message.content]})) + try: + await self.websocket.send(json.dumps({"event": "send command", "args": [message.content]})) + except websockets.exceptions.ConnectionClosed as e: + self.logger.error("WebSocket connection closed: %s", e) + self.task.cancel() + self.task = self.get_task() if message.channel.id == await self.config.chat_channel() and not message.author.bot: self.logger.debug("Received chat message from %s: %s", message.author.id, message.content) channel = self.bot.get_channel(await self.config.console_channel()) @@ -185,7 +190,12 @@ class Pterodactyl(commands.Cog): await channel.send(f"Received chat message from {message.author.id}: {message.content[:1900]}") msg = json.dumps({"event": "send command", "args": [await self.get_tellraw_string(message.author.display_name, message.content, message.author.color)]}) self.logger.debug("Sending chat message to server:\n%s", msg) - await self.websocket.send(msg) + try: + await self.websocket.send(msg) + except websockets.exceptions.ConnectionClosed as e: + self.logger.error("WebSocket connection closed: %s", e) + self.task.cancel() + self.task = self.get_task() @commands.group(autohelp = True, name = "pterodactyl", aliases = ["ptero"]) async def pterodactyl(self, ctx: commands.Context):