1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +00:00
royalnet/royalpack/commands/eval.py

24 lines
880 B
Python
Raw Normal View History

2020-05-10 22:46:12 +00:00
from typing import *
import royalnet.commands as rc
import royalnet.backpack.tables as rbt
2020-05-10 22:46:12 +00:00
class EvalCommand(rc.Command):
# oh god if there is a security vulnerability
name: str = "eval"
description: str = "Esegui una espressione Python... se sei Steffo."
syntax: str = "{espressione}"
2020-05-10 22:46:12 +00:00
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"
2020-08-20 01:20:53 +00:00
"(Sarebbe un po' pericoloso se te lo lasciassi eseguire, non trovi?)")
try:
result = eval(args.joined(require_at_least=1))
except Exception as e:
2020-05-10 22:46:12 +00:00
raise rc.CommandError(f"Eval fallito: {e}")
await data.reply(repr(result))