add runas command

This commit is contained in:
Nexus 2024-09-08 02:24:11 +01:00
parent 69c166685f
commit 3f8ec459b5

View file

@ -197,3 +197,16 @@ class EvalModule(niobot.Module):
thumb.save("file.webp", "webp")
attachment = await niobot.ImageAttachment.from_file("file.webp", generate_blurhash=True)
await ctx.respond("thumbnail.webp", file=attachment)
@niobot.command()
@niobot.is_owner()
async def runas(self, ctx: niobot.Context, user: str, command: str, *args: str):
"""Run a command as another user."""
event = ctx.event
event.sender = user
event.body = f"{command} {' '.join(args)}"
try:
result = await self.bot.process_event(event)
await ctx.respond(f"Result of runas: `{result!r}`")
except Exception as e:
await ctx.respond(f"Error in runas process: `{e!r}`")