import json in EVAL_TEMPLATE and json parse response from eval api

This commit is contained in:
jesopo 2018-10-17 15:08:48 +01:00
parent ecb2b1331a
commit cfb9fa1c2e

View file

@ -2,7 +2,7 @@ import html, socket
from src import ModuleManager, utils from src import ModuleManager, utils
EVAL_TEMPLATE = """ EVAL_TEMPLATE = """
import io, sys import io, json, sys
compiled = compile(sys.stdin.read(), "code", "single") compiled = compile(sys.stdin.read(), "code", "single")
@ -43,7 +43,10 @@ class Module(ModuleManager.BaseModule):
if page: if page:
out = page.split("</b></span><br>", 1)[1].strip("\n") out = page.split("</b></span><br>", 1)[1].strip("\n")
out = html.unescape(out) out = html.unescape(out)
event["stdout"].write("%s: %s" % (event["user"].nickname, out)) out = json.loads(out)
event["stdout" if out["success"] else "stderr"].write(
"%s: %s" % (event["user"].nickname, out))
else: else:
event["stderr"].write("%s: failed to eval" % event["user"].nickname) event["stderr"].write("%s: failed to eval" % event["user"].nickname)