forked from cswimr/SeaCogs
fix(pterodactyl): fixed the cog load process being blocked by the establish_websocket_connection method
This commit is contained in:
parent
5e3ab08d6d
commit
2d4e372784
1 changed files with 12 additions and 4 deletions
|
@ -23,6 +23,7 @@ class Pterodactyl(commands.Cog):
|
|||
)
|
||||
self.logger = logging.getLogger('red.sea.pterodactyl')
|
||||
self.client = None
|
||||
self.task = None
|
||||
self.websocket = None
|
||||
|
||||
async def establish_websocket_connection(self):
|
||||
|
@ -67,10 +68,14 @@ class Pterodactyl(commands.Cog):
|
|||
self.logger.debug("Authentication successful")
|
||||
self.logger.debug("Received message: %s", message)
|
||||
|
||||
def get_task(self):
|
||||
return self.bot.loop.create_task(self.establish_websocket_connection(), name="Pterodactyl Websocket Connection")
|
||||
|
||||
async def cog_load(self):
|
||||
await self.establish_websocket_connection()
|
||||
self.task = self.get_task()
|
||||
|
||||
async def cog_unload(self):
|
||||
self.task.cancel()
|
||||
await self.client._session.close()
|
||||
|
||||
@commands.group(autohelp = True, name = "pterodactyl", aliases = ["ptero"])
|
||||
|
@ -88,18 +93,21 @@ class Pterodactyl(commands.Cog):
|
|||
"""Set the base URL of your Pterodactyl Panel. Please include the protocol (http/https)."""
|
||||
await self.config.base_url.set(base_url)
|
||||
await ctx.send(f"Base URL set to {base_url}")
|
||||
await self.establish_websocket_connection()
|
||||
await self.task.cancel()
|
||||
self.task = self.get_task()
|
||||
|
||||
@pterodactyl_config.command(name = "apikey")
|
||||
async def pterodactyl_config_api_key(self, ctx: commands.Context, api_key: str):
|
||||
"""Set the API key for your Pterodactyl Panel."""
|
||||
await self.config.api_key.set(api_key)
|
||||
await ctx.send(f"API key set to `{api_key[:5]}...{api_key[-4:]}`")
|
||||
await self.establish_websocket_connection()
|
||||
await self.task.cancel()
|
||||
self.task = self.get_task()
|
||||
|
||||
@pterodactyl_config.command(name = "serverid")
|
||||
async def pterodactyl_config_server_id(self, ctx: commands.Context, server_id: str):
|
||||
"""Set the server ID for your Pterodactyl Panel."""
|
||||
await self.config.server_id.set(server_id)
|
||||
await ctx.send(f"Server ID set to {server_id}")
|
||||
await self.establish_websocket_connection()
|
||||
await self.task.cancel()
|
||||
self.task = self.get_task()
|
||||
|
|
Loading…
Reference in a new issue