made some small fixes

This commit is contained in:
Seaswimmer 2023-07-15 17:42:16 -04:00
parent 26872a6efc
commit 8637d74db6
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

@ -40,10 +40,13 @@ class Pterodactyl(commands.Cog):
@app_commands.command() @app_commands.command()
async def update(self, interaction: discord.Interaction): async def update(self, interaction: discord.Interaction):
if await self.config.guild(interaction.guild).api_key() is None: if await self.config.guild(interaction.guild).api_key() is None:
await interaction.response.send_message(f"Something went wrong.\nError: `API Key not set.`", ephemeral=True)
raise LookupError("API Key not set.") raise LookupError("API Key not set.")
elif await self.config.guild(interaction.guild).startup_jar() is None: elif await self.config.guild(interaction.guild).startup_jar() is None:
await interaction.response.send_message(f"Something went wrong.\nError: `Startup jar not set.`", ephemeral=True)
raise LookupError("Startup jar not set.") raise LookupError("Startup jar not set.")
elif await self.config.guild(interaction.guild).startup_arguments() is None: elif await self.config.guild(interaction.guild).startup_arguments() is None:
await interaction.response.send_message(f"Something went wrong.\nError: `Startup arguments not set.`", ephemeral=True)
raise LookupError("Startup arguments not set.") raise LookupError("Startup arguments not set.")
else: else:
api_key = await self.config.guild(interaction.guild).api_key() api_key = await self.config.guild(interaction.guild).api_key()
@ -83,20 +86,20 @@ class Pterodactyl(commands.Cog):
} }
] ]
requests.post(await self.get_url(interaction.guild, "power"), headers=headers, json={"signal": "start"}) requests.post(await self.get_url(interaction.guild, "power"), headers=headers, json={"signal": "start"})
await interaction.response.send_message("Packwiz installer started...", ephemeral=True) interaction_response = await interaction.response.send_message(content="Packwiz installer started...", ephemeral=True)
while True: while True:
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
async with session.get(await self.get_url(interaction.guild, "resources"), headers=headers) as response: async with session.get(await self.get_url(interaction.guild, "resources"), headers=headers) as response:
response_dict = await response.json() response_dict = await response.json()
if response_dict['attributes']['current_state'] == "offline": if response_dict['attributes']['current_state'] == "offline":
await interaction.original_response.edit("Packwiz installer finished!") await interaction_response.edit("Packwiz installer finished!")
break break
else: else:
await asyncio.sleep(1) await asyncio.sleep(1)
continue continue
for data in new_put_data: for data in new_put_data:
await self.put(await self.get_url(interaction.guild, "startup/variable"), headers, data) await self.put(await self.get_url(interaction.guild, "startup/variable"), headers, data)
elif response_dict['attributes']['current_state'] == "running": elif response_dict['attributes']['current_state'] == "running" or response_dict['attributes']['current_state'] == "starting":
passed_info = [old_startup_args[0], old_startup_args[1], headers, put_data, new_put_data] passed_info = [old_startup_args[0], old_startup_args[1], headers, put_data, new_put_data]
await interaction.response.send_message("Server is already running! Are you sure you'd like to stop the server for updates?", ephemeral=True, view=self.UpdateButtons(timeout=180, passed_info=passed_info)) await interaction.response.send_message("Server is already running! Are you sure you'd like to stop the server for updates?", ephemeral=True, view=self.UpdateButtons(timeout=180, passed_info=passed_info))