2020-05-10 22:46:12 +00:00
|
|
|
from typing import *
|
|
|
|
import royalnet.commands as rc
|
|
|
|
import royalnet.backpack.tables as rbt
|
2019-12-30 01:51:55 +00:00
|
|
|
|
|
|
|
|
2020-05-10 22:46:12 +00:00
|
|
|
class EvalCommand(rc.Command):
|
2019-12-30 01:51:55 +00:00
|
|
|
# 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:
|
2020-08-23 21:55:29 +00:00
|
|
|
async with data.session_acm() as session:
|
|
|
|
user: rbt.User = await data.find_author(session=session, required=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?)")
|
2019-12-30 01:51:55 +00:00
|
|
|
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}")
|
2019-12-30 01:51:55 +00:00
|
|
|
await data.reply(repr(result))
|