diff --git a/pterodactyl/pterodactyl.py b/pterodactyl/pterodactyl.py index ff78c84..3ade407 100644 --- a/pterodactyl/pterodactyl.py +++ b/pterodactyl/pterodactyl.py @@ -7,7 +7,7 @@ import websockets from pydactyl import PterodactylClient from redbot.core import commands from redbot.core.bot import Red -from redbot.core.utils.chat_formatting import box +from redbot.core.utils.chat_formatting import box, error from redbot.core.utils.views import ConfirmView from pterodactyl.config import config, register_config @@ -109,7 +109,24 @@ 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") + @pterodactyl.hybrid_command(name = "command", aliases = ["cmd", "execute", "exec"]) + @commands.admin() + async def pterodactyl_command(self, ctx: commands.Context, *, command: str) -> None: + """Send a command to the server console.""" + channel = self.bot.get_channel(await config.console_channel()) + if channel: + await channel.send(f"Received console command from {ctx.author.id}: {command[:1900]}") + try: + await self.websocket.send(json.dumps({"event": "send command", "args": [command]})) + await ctx.send(f"Command sent to server. {box(command, 'json')}") + except websockets.exceptions.ConnectionClosed as e: + logger.error("WebSocket connection closed: %s", e) + await ctx.send(error("WebSocket connection closed.")) + self.task.cancel() + self.retry_counter = 0 + self.task = self.get_task() + + @pterodactyl.hybrid_group(autohelp = True, name = "power") @commands.admin() async def pterodactyl_power(self, ctx: commands.Context) -> None: """Send power actions to the server."""