hopefully fixed messages? maybe?

This commit is contained in:
Seaswimmer 2023-07-15 17:50:57 -04:00
parent 8637d74db6
commit 1c8f4bdfeb
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

@ -39,11 +39,14 @@ class Pterodactyl(commands.Cog):
@app_commands.command() @app_commands.command()
async def update(self, interaction: discord.Interaction): 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: 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.") 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) await interaction_message.edit(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) 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"}) 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: 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_response.edit("Packwiz installer finished!") await interaction_message.edit("Packwiz installer finished!")
break break
else: else:
await asyncio.sleep(1) await asyncio.sleep(1)
@ -100,8 +103,8 @@ class Pterodactyl(commands.Cog):
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" or response_dict['attributes']['current_state'] == "starting": 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, interaction_message]
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_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): class UpdateButtons(discord.ui.View):
def __init__(self, timeout, passed_info): def __init__(self, timeout, passed_info):
@ -110,18 +113,18 @@ class Pterodactyl(commands.Cog):
@discord.ui.button(label="Yes", style=discord.ButtonStyle.green, emoji="") @discord.ui.button(label="Yes", style=discord.ButtonStyle.green, emoji="")
async def yes_button(self, button:discord.ui.Button, interaction:discord.Interaction): 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"}) requests.post(await Pterodactyl.get_url(interaction.guild, "power"), headers=self.passed_info[2], json={"signal": "stop"})
for data in self.passed_info[3]: for data in self.passed_info[3]:
await Pterodactyl.put(await Pterodactyl.get_url(interaction.guild, "startup/variable"), self.passed_info[2], data) 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"}) 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: while True:
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
async with session.get(await Pterodactyl.get_url(interaction.guild, "resources"), headers=self.passed_info[2]) as response: async with session.get(await Pterodactyl.get_url(interaction.guild, "resources"), headers=self.passed_info[2]) 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 self.passed_info[5].edit("Packwiz installer finished!")
break break
else: else:
await asyncio.sleep(1) 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) await Pterodactyl.put(Pterodactyl.get_url(interaction.guild, "startup/variable"), self.passed_info[2], data)
asyncio.sleep(1) asyncio.sleep(1)
requests.post(await Pterodactyl.get_url(interaction.guild, "power"), self.passed_info[2], json={"signal": "start"}) 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: while True:
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
async with session.get(await Pterodactyl.get_url(interaction.guild, "resources"), headers=self.passed_info[2]) as response: async with session.get(await Pterodactyl.get_url(interaction.guild, "resources"), headers=self.passed_info[2]) as response:
response_dict = await response.json() response_dict = await response.json()
if response_dict['attributes']['current_state'] == "running": 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 break
else: else:
await asyncio.sleep(1) await asyncio.sleep(1)