diff --git a/pterodactyl/ptero.py b/pterodactyl/ptero.py index 1af47de..ef4b167 100644 --- a/pterodactyl/ptero.py +++ b/pterodactyl/ptero.py @@ -39,11 +39,14 @@ class Pterodactyl(commands.Cog): @app_commands.command() async def update(self, interaction: discord.Interaction): + """Updates the server using the arguments provided in the server's configuration.""" + interaction.response.defer(ephemeral=True, thinking=True) + interaction_message = await interaction.original_response() 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) + await interaction_message.edit(f"Something went wrong.\nError: `API Key not set.`", ephemeral=True) raise LookupError("API Key not set.") 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) + await interaction_message.edit(f"Something went wrong.\nError: `Startup jar not set.`", ephemeral=True) raise LookupError("Startup jar not set.") 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) @@ -86,13 +89,13 @@ class Pterodactyl(commands.Cog): } ] requests.post(await self.get_url(interaction.guild, "power"), headers=headers, json={"signal": "start"}) - interaction_response = await interaction.response.send_message(content="Packwiz installer started...", ephemeral=True) + await interaction_message.edit(content="Packwiz installer started...", ephemeral=True) while True: async with aiohttp.ClientSession() as session: async with session.get(await self.get_url(interaction.guild, "resources"), headers=headers) as response: response_dict = await response.json() if response_dict['attributes']['current_state'] == "offline": - await interaction_response.edit("Packwiz installer finished!") + await interaction_message.edit("Packwiz installer finished!") break else: await asyncio.sleep(1) @@ -100,8 +103,8 @@ class Pterodactyl(commands.Cog): for data in new_put_data: await self.put(await self.get_url(interaction.guild, "startup/variable"), headers, data) 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] - 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)) + passed_info = [old_startup_args[0], old_startup_args[1], headers, put_data, new_put_data, interaction_message] + await interaction_message.edit("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)) class UpdateButtons(discord.ui.View): def __init__(self, timeout, passed_info): @@ -110,18 +113,18 @@ class Pterodactyl(commands.Cog): @discord.ui.button(label="Yes", style=discord.ButtonStyle.green, emoji="✅") async def yes_button(self, button:discord.ui.Button, interaction:discord.Interaction): - await interaction.original_response.edit("Server stopping!") + await self.passed_info[5].edit("Server stopping!") requests.post(await Pterodactyl.get_url(interaction.guild, "power"), headers=self.passed_info[2], json={"signal": "stop"}) for data in self.passed_info[3]: await Pterodactyl.put(await Pterodactyl.get_url(interaction.guild, "startup/variable"), self.passed_info[2], data) requests.post(await Pterodactyl.get_url(interaction.guild, "power"), headers=self.passed_info[2], json={"signal": "start"}) - await interaction.original_response.edit("Packwiz installer started...") + await self.passed_info[5].edit("Packwiz installer started...") while True: async with aiohttp.ClientSession() as session: async with session.get(await Pterodactyl.get_url(interaction.guild, "resources"), headers=self.passed_info[2]) as response: response_dict = await response.json() if response_dict['attributes']['current_state'] == "offline": - await interaction.original_response.edit("Packwiz installer finished!") + await self.passed_info[5].edit("Packwiz installer finished!") break else: await asyncio.sleep(1) @@ -130,13 +133,13 @@ class Pterodactyl(commands.Cog): await Pterodactyl.put(Pterodactyl.get_url(interaction.guild, "startup/variable"), self.passed_info[2], data) asyncio.sleep(1) requests.post(await Pterodactyl.get_url(interaction.guild, "power"), self.passed_info[2], json={"signal": "start"}) - await interaction.original_response.edit("Server starting...") + await self.passed_info[5].edit("Server starting...") while True: async with aiohttp.ClientSession() as session: async with session.get(await Pterodactyl.get_url(interaction.guild, "resources"), headers=self.passed_info[2]) as response: response_dict = await response.json() if response_dict['attributes']['current_state'] == "running": - await interaction.original_response.edit("Server started!\nUpdate process completed!!") + await self.passed_info[5].edit("Server started!\nUpdate process completed!!") break else: await asyncio.sleep(1)