misc: improved variable naming, made passed_info a dict

This commit is contained in:
Seaswimmer 2023-07-15 21:03:22 -04:00
parent 921adc0fed
commit c24cffcc31
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

@ -65,8 +65,7 @@ class Pterodactyl(commands.Cog):
response_dict = response.json()
list_var = requests.get(await self.get_url(interaction.guild, "startup"), headers=headers)
list_var_response_dict = list_var.json()
old_startup_args = [list_var_response_dict['data'][0]['attributes']['server_value'], list_var_response_dict['data'][4]['attributes']['server_value']]
put_data = [
updater_startup_vars = [
{
"key": "FLAGS",
"value": startup_commands
@ -76,7 +75,7 @@ class Pterodactyl(commands.Cog):
"value": startup_jar
}
]
new_put_data = [
old_startup_vars = [
{
"key": "FLAGS",
"value": list_var_response_dict['data'][4]['attributes']['server_value']
@ -87,7 +86,7 @@ class Pterodactyl(commands.Cog):
}
]
if response_dict['attributes']['current_state'] == "offline":
for data in put_data:
for data in updater_startup_vars:
await self.put(await self.get_url(interaction.guild, "startup/variable"), headers, data)
requests.post(await self.get_url(interaction.guild, "power"), headers=headers, json={"signal": "start"})
await interaction_message.edit(content="Packwiz installer started...")
@ -102,11 +101,16 @@ class Pterodactyl(commands.Cog):
else:
await asyncio.sleep(1)
continue
for data in new_put_data:
for data in old_startup_vars:
await self.put(await self.get_url(interaction.guild, "startup/variable"), headers, data)
await interaction_message.edit(content="Packwiz installer finished.\nUpdate process completed!")
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, interaction_message]
passed_info = {
"headers": headers,
"updater_startup_vars": updater_startup_vars,
"old_startup_vars": old_startup_vars,
"interaction_message": interaction_message
}
await interaction_message.edit(content="The server is already running! Are you sure you'd like to stop the server for updates?", view=self.UpdateButtons(timeout=180, passed_info=passed_info))
class UpdateButtons(ui.View):
@ -116,44 +120,44 @@ class Pterodactyl(commands.Cog):
@ui.button(label="Yes", style=discord.ButtonStyle.success)
async def yes_button(self, button:ui.Button, interaction:discord.Interaction):
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['headers'], json={"signal": "stop"})
await interaction.response.edit_message("Server stopping...", view=None)
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:
async with session.get(await Pterodactyl.get_url(interaction.guild, "resources"), headers=self.passed_info['headers']) as response:
response_dict = await response.json()
if response_dict['attributes']['current_state'] == "offline":
await self.passed_info[5].edit("Server stopped!")
await self.passed_info['interaction_message'].edit("Server stopped!")
break
else:
await asyncio.sleep(2)
continue
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 self.passed_info[5].edit("Packwiz installer started...")
for data in self.passed_info['updater_startup_vars']:
await Pterodactyl.put(await Pterodactyl.get_url(interaction.guild, "startup/variable"), self.passed_info['headers'], data)
requests.post(await Pterodactyl.get_url(interaction.guild, "power"), headers=self.passed_info['headers'], json={"signal": "start"})
await self.passed_info['interaction_message'].edit("Packwiz installer started...")
await asyncio.sleep(1)
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:
async with session.get(await Pterodactyl.get_url(interaction.guild, "resources"), headers=self.passed_info['headers']) as response:
response_dict = await response.json()
if response_dict['attributes']['current_state'] == "offline":
await self.passed_info[5].edit("Packwiz installer finished!")
await self.passed_info['interaction_message'].edit("Packwiz installer finished!")
break
else:
await asyncio.sleep(1)
continue
for data in self.passed_info[4]:
await Pterodactyl.put(Pterodactyl.get_url(interaction.guild, "startup/variable"), self.passed_info[2], data)
for data in self.passed_info['old_startup_vars']:
await Pterodactyl.put(Pterodactyl.get_url(interaction.guild, "startup/variable"), self.passed_info['headers'], data)
asyncio.sleep(1)
requests.post(await Pterodactyl.get_url(interaction.guild, "power"), self.passed_info[2], json={"signal": "start"})
await self.passed_info[5].edit("Server starting...")
requests.post(await Pterodactyl.get_url(interaction.guild, "power"), self.passed_info['headers'], json={"signal": "start"})
await self.passed_info['interaction_message'].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:
async with session.get(await Pterodactyl.get_url(interaction.guild, "resources"), headers=self.passed_info['headers']) as response:
response_dict = await response.json()
if response_dict['attributes']['current_state'] == "running":
await self.passed_info[5].edit("Server started!\nUpdate process completed!")
await self.passed_info['interaction_message'].edit("Server started!\nUpdate process completed!")
break
else:
await asyncio.sleep(1)