fix(pterodactyl): update pterodactyl for the new version of websockets & fix a few minor bugs
This commit is contained in:
parent
d51e3f17e9
commit
ff9e20be91
3 changed files with 66 additions and 50 deletions
|
@ -22,14 +22,14 @@ class Pterodactyl(commands.Cog):
|
|||
|
||||
__author__ = ["[cswimr](https://www.coastalcommits.com/cswimr)"]
|
||||
__git__ = "https://www.coastalcommits.com/cswimr/SeaCogs"
|
||||
__version__ = "2.0.4"
|
||||
__version__ = "2.0.5"
|
||||
__documentation__ = "https://seacogs.coastalcommits.com/pterodactyl/"
|
||||
|
||||
def __init__(self, bot: Red):
|
||||
self.bot = bot
|
||||
self.client: Optional[PterodactylClient] = None
|
||||
self.task: Optional[asyncio.Task] = None
|
||||
self.websocket: Optional[websockets.WebSocketClientProtocol] = None
|
||||
self.websocket: Optional[websockets.ClientConnection] = None
|
||||
self.retry_counter: int = 0
|
||||
register_config(config)
|
||||
self.task = self.get_task()
|
||||
|
@ -51,15 +51,18 @@ class Pterodactyl(commands.Cog):
|
|||
api_key = pterodactyl_keys.get("api_key")
|
||||
if api_key is None:
|
||||
self.task.cancel()
|
||||
raise ValueError("Pterodactyl API key not set. Please set it using `[p]set api`.")
|
||||
logger.error("Pterodactyl API key not set. Please set it using `[p]set api`.")
|
||||
return
|
||||
base_url = await config.base_url()
|
||||
if base_url is None:
|
||||
self.task.cancel()
|
||||
raise ValueError("Pterodactyl base URL not set. Please set it using `[p]pterodactyl config url`.")
|
||||
logger.error("Pterodactyl base URL not set. Please set it using `[p]pterodactyl config url`.")
|
||||
return
|
||||
server_id = await config.server_id()
|
||||
if server_id is None:
|
||||
self.task.cancel()
|
||||
raise ValueError("Pterodactyl server ID not set. Please set it using `[p]pterodactyl config serverid`.")
|
||||
logger.error("Pterodactyl server ID not set. Please set it using `[p]pterodactyl config serverid`.")
|
||||
return
|
||||
|
||||
self.client = PterodactylClient(base_url, api_key).client
|
||||
|
||||
|
@ -67,7 +70,6 @@ class Pterodactyl(commands.Cog):
|
|||
self.update_topic.cancel()
|
||||
self.task.cancel()
|
||||
self.retry_counter = 0
|
||||
await self.client._session.close() # pylint: disable=protected-access # noqa: SLF001
|
||||
|
||||
def get_task(self) -> asyncio.Task:
|
||||
from pterodactyl.websocket import establish_websocket_connection
|
||||
|
@ -76,7 +78,7 @@ class Pterodactyl(commands.Cog):
|
|||
task.add_done_callback(self.error_callback)
|
||||
return task
|
||||
|
||||
def error_callback(self, fut) -> None: # NOTE - Thanks flame442 and zephyrkul for helping me figure this out
|
||||
def error_callback(self, fut) -> None: # NOTE Thanks flame442 and zephyrkul for helping me figure this out
|
||||
try:
|
||||
fut.result()
|
||||
except asyncio.CancelledError:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue