Compare commits

...

2 commits

View file

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