1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-24 03:54:20 +00:00
royalnet/royalpack/commands/exec.py
2020-05-11 00:46:12 +02:00

23 lines
865 B
Python

from typing import *
import royalnet.commands as rc
import royalnet.backpack.tables as rbt
class ExecCommand(rc.Command):
# oh god if there is a security vulnerability
name: str = "exec"
description: str = "Esegui uno script Python... se sei Steffo."
syntax: str = "{script}"
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
user: rbt.User = await data.get_author(error_if_none=True)
if "admin" not in user.roles:
raise rc.CommandError("Non sei autorizzato a eseguire codice arbitrario!\n"
"(Sarebbe un po' pericoloso se te lo lasciassi eseguire, non trovi?)")
try:
exec(args.joined(require_at_least=1))
except Exception as e:
raise rc.CommandError(f"Esecuzione fallita: {e}")
await data.reply(f"✅ Fatto!")