From 6a02381e895c076bba2b2b256f08e4b1952a282c Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Fri, 1 Mar 2024 22:20:50 -0500 Subject: [PATCH] feat(pterodactyl): add power commands --- pterodactyl/pterodactyl.py | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/pterodactyl/pterodactyl.py b/pterodactyl/pterodactyl.py index 3dd53b4..e049474 100644 --- a/pterodactyl/pterodactyl.py +++ b/pterodactyl/pterodactyl.py @@ -107,6 +107,45 @@ class Pterodactyl(commands.Cog): async def pterodactyl(self, ctx: commands.Context) -> None: """Pterodactyl allows you to manage your Pterodactyl Panel from Discord.""" + @pterodactyl.group(autohelp = True, name = "power") + @commands.admin() + async def pterodactyl_power(self, ctx: commands.Context) -> None: + """Send power actions to the server.""" + + @pterodactyl_power.command(name = "start") + async def pterodactyl_power_start(self, ctx: commands.Context) -> None: + """Start the server.""" + current_status = await config.current_status() + if current_status == "running": + return await ctx.send("Server is already running.") + elif 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...") + + @pterodactyl_power.command(name = "stop") + async def pterodactyl_power_stop(self, ctx: commands.Context) -> None: + """Stop the server.""" + current_status = await config.current_status() + if current_status == "stopped": + return await ctx.send("Server is already stopped.") + elif 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...") + + @pterodactyl_power.command(name = "restart") + async def pterodactyl_power_restart(self, ctx: commands.Context) -> None: + """Restart the server.""" + 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...") + @pterodactyl.group(autohelp = True, name = "config", aliases = ["settings", "set"]) @commands.is_owner() async def pterodactyl_config(self, ctx: commands.Context) -> None: