Compare commits

..

No commits in common. "f2d54ce23b38c647d23945378396bace9d58d6a5" and "684f2559e2c0445e89ce26d5354a27a5993c63e5" have entirely different histories.

2 changed files with 2 additions and 16 deletions

View file

@ -21,16 +21,13 @@ class Pterodactyl(commands.Cog):
self.client: Optional[PterodactylClient] = None
self.task: Optional[asyncio.Task] = None
self.websocket: Optional[websockets.WebSocketClientProtocol] = None
self.retry_counter: int = 0
register_config(config)
async def cog_load(self) -> None:
self.retry_counter = 0
self.task = self.get_task()
async def cog_unload(self) -> None:
self.task.cancel()
self.retry_counter = 0
await self.client._session.close() # pylint: disable=protected-access
def get_task(self) -> asyncio.Task:
@ -47,12 +44,7 @@ class Pterodactyl(commands.Cog):
except Exception as e: # pylint: disable=broad-exception-caught
logger.error("WebSocket task has failed: %s", e, exc_info=e)
self.task.cancel()
if self.retry_counter < 5:
self.retry_counter += 1
asyncio.sleep(5 * self.retry_counter)
self.task = self.get_task()
else:
logger.info("Retry limit reached. Stopping task.")
self.task = self.get_task()
@commands.Cog.listener()
async def on_message_without_command(self, message: discord.Message) -> None:
@ -64,7 +56,6 @@ class Pterodactyl(commands.Cog):
except websockets.exceptions.ConnectionClosed as e:
logger.error("WebSocket connection closed: %s", e)
self.task.cancel()
self.retry_counter = 0
self.task = self.get_task()
if message.channel.id == await config.chat_channel() and message.author.bot is False:
logger.debug("Received chat message from %s: %s", message.author.id, message.content)
@ -78,7 +69,6 @@ class Pterodactyl(commands.Cog):
except websockets.exceptions.ConnectionClosed as e:
logger.error("WebSocket connection closed: %s", e)
self.task.cancel()
self.retry_counter = 0
self.task = self.get_task()
async def get_chat_command(self, username: str, message: str, color: discord.Color) -> str:
@ -91,7 +81,6 @@ class Pterodactyl(commands.Cog):
if service_name == "pterodactyl":
logger.info("Configuration value set: api_key\nRestarting task...")
self.task.cancel()
self.retry_counter = 0
self.task = self.get_task()
@commands.group(autohelp = True, name = "pterodactyl", aliases = ["ptero"])
@ -116,7 +105,6 @@ class Pterodactyl(commands.Cog):
await ctx.send(f"Base URL set to {base_url}")
logger.info("Configuration value set: base_url = %s\nRestarting task...", base_url)
self.task.cancel()
self.retry_counter = 0
self.task = self.get_task()
@pterodactyl_config.command(name = "serverid")
@ -126,7 +114,6 @@ class Pterodactyl(commands.Cog):
await ctx.send(f"Server ID set to {server_id}")
logger.info("Configuration value set: server_id = %s\nRestarting task...", server_id)
self.task.cancel()
self.retry_counter = 0
self.task = self.get_task()
@pterodactyl_config.command(name = "consolechannel")

View file

@ -4,6 +4,7 @@ import re
from logging import getLogger
from typing import Optional, Union
import aiohttp
import discord
import websockets
@ -21,8 +22,6 @@ async def establish_websocket_connection(coginstance: Pterodactyl) -> None:
logger.info("Establishing WebSocket connection")
websocket_credentials = await retrieve_websocket_credentials(coginstance)
if not websocket_credentials:
return logger.error("Failed to retrieve WebSocket credentials. WebSocket connection not established")
async with websockets.connect(websocket_credentials['data']['socket'], origin=base_url, ping_timeout=60, logger=getLogger("red.sea.pterodactyl.websocket")) as websocket:
logger.info("WebSocket connection established")