2018-09-19 12:56:57 +00:00
|
|
|
import socket
|
2018-10-03 12:22:37 +00:00
|
|
|
from src import ModuleManager, utils
|
2018-09-19 12:56:57 +00:00
|
|
|
|
2018-10-12 11:39:01 +00:00
|
|
|
EVAL_TEMPLATE = """
|
|
|
|
import sys
|
2018-10-12 12:23:48 +00:00
|
|
|
compiled = compile(sys.stdin.read(), "code", "single")
|
2018-10-12 12:18:06 +00:00
|
|
|
result = eval(compiled)
|
2018-10-12 11:46:05 +00:00
|
|
|
print("")
|
2018-10-12 11:39:01 +00:00
|
|
|
if not result == None:
|
|
|
|
sys.stdout.write(str(result))
|
|
|
|
"""
|
2018-09-19 12:56:57 +00:00
|
|
|
|
2018-10-12 11:39:01 +00:00
|
|
|
EVAL_URL = "https://tpcg.tutorialspoint.com/tpcg.php"
|
2018-09-26 17:27:17 +00:00
|
|
|
class Module(ModuleManager.BaseModule):
|
2018-10-08 11:47:48 +00:00
|
|
|
_name = "Python"
|
2018-10-12 11:39:01 +00:00
|
|
|
|
|
|
|
def _eval(self, lang, event):
|
2018-09-19 12:56:57 +00:00
|
|
|
try:
|
2018-10-12 11:39:01 +00:00
|
|
|
page = utils.http.get_url(EVAL_URL,
|
|
|
|
post_data={
|
|
|
|
"lang": lang,
|
|
|
|
"code": EVAL_TEMPLATE,
|
|
|
|
"execute": "%s main.py" % lang,
|
|
|
|
"mainfile": "main.py",
|
|
|
|
"stdinput": event["args"]
|
|
|
|
},
|
2018-10-12 10:56:13 +00:00
|
|
|
method="POST")
|
|
|
|
except:
|
|
|
|
pass
|
2018-09-19 12:56:57 +00:00
|
|
|
|
2018-10-12 11:39:01 +00:00
|
|
|
if page:
|
|
|
|
event["stdout"].write("%s: %s" % (event["user"].nickname,
|
2018-10-12 11:46:05 +00:00
|
|
|
page.split("</b></span><br>", 1)[1].strip("\n")))
|
2018-10-12 11:39:01 +00:00
|
|
|
else:
|
|
|
|
event["stderr"].write("%s: failed to eval" % event["user"].nickname)
|
2018-10-12 10:56:13 +00:00
|
|
|
|
2018-10-12 11:39:01 +00:00
|
|
|
@utils.hook("received.command.py2", alias_of="python2")
|
|
|
|
@utils.hook("received.command.python2", min_args=1)
|
|
|
|
def eval(self, event):
|
|
|
|
self._eval("python", event)
|
2018-10-12 10:56:13 +00:00
|
|
|
|
2018-10-12 11:39:01 +00:00
|
|
|
@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)
|