diff --git a/pterodactyl/ptero.py b/pterodactyl/ptero.py index 3032edc..07961a8 100644 --- a/pterodactyl/ptero.py +++ b/pterodactyl/ptero.py @@ -77,6 +77,34 @@ class Pterodactyl(commands.Cog): message = await interaction_message.edit(content="The server is already running!") await message.delete(delay=3) + @power.command(name='restart', description="Restarts the server.") + @app_commands.guild_only() + async def restart(self, interaction: discord.Interaction): + """Restarts 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": + passed_info = { + "headers": headers, + "interaction": interaction, + "guild": interaction.guild, + "signal": "restart", + "target_signal": "running", + "message": "Server restarting...", + "completed_message": "Server restarted!" + } + await interaction_message.edit(content="Are you sure you'd like to restart the server?", view=self.PowerButtons(timeout=180, passed_info=passed_info)) + elif current_status == "offline": + message = await interaction_message.edit(content="The server is offline!") + await message.delete(delay=3) + elif current_status == "starting": + message = await interaction_message.edit(content="The server is already starting!") + await message.delete(delay=3) + @app_commands.command(description="Updates the server.") @app_commands.guild_only()