From b2f27f949050870c25b6ddc7015511df8c32bddf Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 5 Mar 2024 02:16:32 -0500 Subject: [PATCH] feat(pterodactyl): added confirmation prompts to the power commands --- pterodactyl/pterodactyl.py | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/pterodactyl/pterodactyl.py b/pterodactyl/pterodactyl.py index 212cbd2..fab4389 100644 --- a/pterodactyl/pterodactyl.py +++ b/pterodactyl/pterodactyl.py @@ -122,9 +122,15 @@ class Pterodactyl(commands.Cog): return await ctx.send("Server is already running.") if current_status in ["starting", "stopping"]: return await ctx.send("Another power action is already in progress.") - message = await ctx.send("Sending websocket command to start server...") - await self.websocket.send(json.dumps({"event": "set state", "args": ["start"]})) - await message.edit(content="Server starting...") + view = ConfirmView(ctx.author, disable_buttons=True) + message = await ctx.send("Are you sure you want to start the server?", view=view) + await view.wait() + if view.result is True: + await ctx.message("Sending websocket command to start server...") + await self.websocket.send(json.dumps({"event": "set state", "args": ["start"]})) + await message.edit(content="Server starting...") + else: + await message.edit(content="Cancelled.") @pterodactyl_power.command(name = "stop") async def pterodactyl_power_stop(self, ctx: commands.Context) -> None: @@ -134,9 +140,15 @@ class Pterodactyl(commands.Cog): return await ctx.send("Server is already stopped.") if current_status in ["starting", "stopping"]: return await ctx.send("Another power action is already in progress.") - message = await ctx.send("Sending websocket command to stop server...") - await self.websocket.send(json.dumps({"event": "set state", "args": ["stop"]})) - await message.edit(content="Server stopping...") + view = ConfirmView(ctx.author, disable_buttons=True) + message = await ctx.send("Are you sure you want to stop the server?", view=view) + await view.wait() + if view.result is True: + await message.edit("Sending websocket command to stop server...") + await self.websocket.send(json.dumps({"event": "set state", "args": ["stop"]})) + await message.edit(content="Server stopping...") + else: + await message.edit(content="Cancelled.") @pterodactyl_power.command(name = "restart") async def pterodactyl_power_restart(self, ctx: commands.Context) -> None: @@ -144,9 +156,15 @@ class Pterodactyl(commands.Cog): current_status = await config.current_status() if current_status in ["starting", "stopping"]: return await ctx.send("Another power action is already in progress.") - message = await ctx.send("Sending websocket command to restart server...") - await self.websocket.send(json.dumps({"event": "set state", "args": ["restart"]})) - await message.edit(content="Server restarting...") + view = ConfirmView(ctx.author, disable_buttons=True) + message = await ctx.send("Are you sure you want to restart the server?", view=view) + await view.wait() + if view.result is True: + await message.edit("Sending websocket command to restart server...") + await self.websocket.send(json.dumps({"event": "set state", "args": ["restart"]})) + await message.edit(content="Server restarting...") + else: + await message.edit(content="Cancelled.") @pterodactyl.group(autohelp = True, name = "config", aliases = ["settings", "set"]) @commands.is_owner()