diff --git a/modules/eval_python.py b/modules/eval_python.py index 3dd4d66d..b16671bc 100644 --- a/modules/eval_python.py +++ b/modules/eval_python.py @@ -1,72 +1,26 @@ #--depends-on commands -import html, json, socket +import urllib.parse from src import ModuleManager, utils -EVAL_TEMPLATE = """ -import io, json, sys +EVAL_URL = "http://dotpy3.herokuapp.com/" -old_stdout = sys.stdout -def fail(s): - old_stdout.write(json.dumps({"success": False, "out": str(e)})) - sys.exit() - -try: - compiled = compile(sys.stdin.read(), "code", "single") -except SyntaxError as e: - fail(str(e)) - -stdout = io.StringIO() -sys.stdout = stdout - -try: - result = eval(compiled) -except Exception as e: - fail(str(e)) - -stdout.write("\\n") -if not result == None: - stdout.write(str(result)+"\\n") -old_stdout.write(json.dumps({"success": True, "out": stdout.getvalue()})) -""" - -EVAL_URL = "https://tpcg.tutorialspoint.com/tpcg.php" class Module(ModuleManager.BaseModule): _name = "Python" - def _eval(self, lang, event): + @utils.hook("received.command.py", alias_of="python") + @utils.hook("received.command.python") + def _eval(self, event): + url = "%s?%s" % (EVAL_URL, urllib.parse.quote(event["args"])) + page = None try: - page = utils.http.request(EVAL_URL, - post_data={ - "lang": lang, - "code": EVAL_TEMPLATE, - "execute": "%s main.py" % lang, - "mainfile": "main.py", - "stdinput": event["args"] - }, - method="POST") + page = utils.http.request(url) except: pass if page and page.data: - out = page.data.split("
", 1)[1] - out = html.unescape(out) - out = json.loads(out) - - event["stdout" if out["success"] else "stderr"].write( - "%s: %s" % (event["user"].nickname, out["out"].strip("\n"))) + event["stdout"].write("%s: %s" % (event["user"].nickname, + page.data.rstrip("\n"))) else: event["stderr"].write("%s: failed to eval" % event["user"].nickname) - - @utils.hook("received.command.py2", alias_of="python2") - @utils.hook("received.command.python2", min_args=1) - def eval(self, event): - self._eval("python", event) - - @utils.hook("received.command.py", alias_of="python") - @utils.hook("received.command.py3", alias_of="python") - @utils.hook("received.command.python", alias_of="python3") - @utils.hook("received.command.python3", min_args=1) - def eval3(self, event): - self._eval("python3", event)