From fd6fca640cc121774817aaaa828972216a880da6 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sun, 16 Jul 2023 13:28:18 -0400 Subject: [PATCH] feat: added stop command --- pterodactyl/ptero.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/pterodactyl/ptero.py b/pterodactyl/ptero.py index 07961a8..5b5b802 100644 --- a/pterodactyl/ptero.py +++ b/pterodactyl/ptero.py @@ -105,6 +105,31 @@ class Pterodactyl(commands.Cog): message = await interaction_message.edit(content="The server is already starting!") await message.delete(delay=3) + @power.command(name='stop', description="Stops the server.") + @app_commands.guild_only() + async def stop(self, interaction: discord.Interaction): + """Stops 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 == "running" or current_status == "starting": + passed_info = { + "headers": headers, + "interaction": interaction, + "guild": interaction.guild, + "signal": "stop", + "target_signal": "offline", + "message": "Server stopping...", + "completed_message": "Server stopped!" + } + await interaction_message.edit(content="Are you sure you'd like to stop the server?", view=self.PowerButtons(timeout=180, passed_info=passed_info)) + elif current_status == "offline": + message = await interaction_message.edit(content="The server is already offline!") + await message.delete(delay=3) + @app_commands.command(description="Updates the server.") @app_commands.guild_only()