feat(pterodactyl): added a pterodactyl command command to execute commands on the server and made pterodactyl command and pterodactyl power into hybrid commands
Some checks failed
Actions / Lint Code (Ruff & Pylint) (push) Failing after 24s
Actions / Build Documentation (MkDocs) (push) Successful in 30s

This commit is contained in:
Seaswimmer 2024-03-07 00:00:15 -05:00
parent 9d64c15a87
commit 64ab2fbf82
Signed by: cswimr
GPG key ID: B8953EC01E5C4063

View file

@ -7,7 +7,7 @@ import websockets
from pydactyl import PterodactylClient from pydactyl import PterodactylClient
from redbot.core import commands from redbot.core import commands
from redbot.core.bot import Red 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 redbot.core.utils.views import ConfirmView
from pterodactyl.config import config, register_config from pterodactyl.config import config, register_config
@ -109,7 +109,24 @@ class Pterodactyl(commands.Cog):
async def pterodactyl(self, ctx: commands.Context) -> None: async def pterodactyl(self, ctx: commands.Context) -> None:
"""Pterodactyl allows you to manage your Pterodactyl Panel from Discord.""" """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() @commands.admin()
async def pterodactyl_power(self, ctx: commands.Context) -> None: async def pterodactyl_power(self, ctx: commands.Context) -> None:
"""Send power actions to the server.""" """Send power actions to the server."""