diff options
author | 2025-04-15 22:36:45 +0100 | |
---|---|---|
committer | 2025-04-15 22:41:31 +0100 | |
commit | 19b6dc8b91c3b05e1ead994d8a8a499a477d6082 (patch) | |
tree | ba0538edf59ab3fbf395fb7a7bd253c58a4db37d | |
parent | Add helper function to RCE on the netcup server (diff) |
Add a command to run a command on lovelace
-rw-r--r-- | arthur/exts/fun/remote_command_runner.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/arthur/exts/fun/remote_command_runner.py b/arthur/exts/fun/remote_command_runner.py new file mode 100644 index 0000000..cb6bd6d --- /dev/null +++ b/arthur/exts/fun/remote_command_runner.py @@ -0,0 +1,33 @@ +from discord.ext.commands import Cog, Context, command + +from arthur.apis.netcup.ssh import rce_as_a_service +from arthur.bot import KingArthur + + +class RemoteCommands(Cog): + """We love RCE.""" + + def __init__(self, bot: KingArthur) -> None: + self.bot = bot + + @command(name="rce") + async def rce(self, ctx: Context, *, command: str) -> None: + """Ed is the standard text editor.""" + if not ctx.guild: + return + if not ctx.bot.is_owner(ctx.author): + await ctx.message.add_reaction("❌") + return + + response = await rce_as_a_service(command) + + if not response.stderr or not response.stdout: + await ctx.send("Successfully ran with no output!") + return + + await ctx.send(f"```{response.stderr}```\n```{response.stdout}```") + + +async def setup(bot: KingArthur) -> None: + """Add cog to bot.""" + await bot.add_cog(RemoteCommands(bot)) |