fix(pterodactyl): added error messages for if the websocket connection is closed

This commit is contained in:
SeaswimmerTheFsh 2024-02-29 20:59:47 -05:00
parent 579855af02
commit 50dd5c64b4
Signed by untrusted user: cswimr
GPG key ID: B8953EC01E5C4063

View file

@ -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):