From 5f6c1d64d4c7d9726c546e209461429df714c52e Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sun, 16 Jul 2023 13:25:41 -0400 Subject: [PATCH] feat: added start command --- pterodactyl/ptero.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pterodactyl/ptero.py b/pterodactyl/ptero.py index 6da9f30..3032edc 100644 --- a/pterodactyl/ptero.py +++ b/pterodactyl/ptero.py @@ -50,6 +50,34 @@ class Pterodactyl(commands.Cog): async with session.put(url, headers=headers, json=data) as response: return response + power = app_commands.Group(name='power', description="Controls the server's power state.") + + @power.command(name='start', description="Starts the server.") + @app_commands.guild_only() + async def start(self, interaction: discord.Interaction): + """Starts the server.""" + await interaction.defer(ephemeral=True, thinking=True) + interaction_message = await interaction.original_response() + headers = await self.get_headers(interaction.guild) + response = requests.get(await self.get_url(interaction.guild, "resources"), headers=headers) + requests_json = response.json() + current_status = requests_json['attributes']['current_state'] + if current_status == "offline": + passed_info = { + "headers": headers, + "interaction": interaction, + "guild": interaction.guild, + "signal": "start", + "target_signal": "running", + "message": "Server starting...", + "completed_message": "Server started!" + } + await interaction_message.edit(content="Are you sure you'd like to start the server?", view=self.PowerButtons(timeout=180, passed_info=passed_info)) + else: + message = await interaction_message.edit(content="The server is already running!") + await message.delete(delay=3) + + @app_commands.command(description="Updates the server.") @app_commands.guild_only() async def update(self, interaction: discord.Interaction):