aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorGravatar jesopo2018-10-12 12:39:01 +0100
committerGravatar jesopo2018-10-12 12:39:01 +0100
commitb884b0e170b36e394e21d8804655a5ed13352aa5 (patch)
tree35ec1f64e5d486f586300892072a00e64f95dc78 /modules
parentUse a more reliable API for evaling python (diff)
signature
Support py2 and py3 in eval_python
Diffstat (limited to 'modules')
-rw-r--r--modules/eval_python.py57
1 files changed, 32 insertions, 25 deletions
diff --git a/modules/eval_python.py b/modules/eval_python.py
index f6765134..e762a167 100644
--- a/modules/eval_python.py
+++ b/modules/eval_python.py
@@ -1,38 +1,45 @@
import socket
from src import ModuleManager, utils
-EVAL_URL = "https://pyeval.appspot.com/exec"
+EVAL_TEMPLATE = """
+import sys
+result = eval(sys.stdin.read())
+if not result == None:
+ sys.stdout.write(str(result))
+"""
+EVAL_URL = "https://tpcg.tutorialspoint.com/tpcg.php"
class Module(ModuleManager.BaseModule):
_name = "Python"
- @utils.hook("received.command.py", alias_of="python")
- @utils.hook("received.command.python", min_args=1)
- def eval(self, event):
- """
- :help: Evaluate a python statement
- :usage: <statement>
- """
- id = None
+
+ def _eval(self, lang, event):
try:
- id = utils.http.get_url(EVAL_URL,
- post_data={"input": event["args"]},
+ 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"]
+ },
method="POST")
except:
pass
- if not id == None:
- try:
- page = utils.http.get_url(EVAL_URL,
- get_params={"id": id},
- json=True)
- except socket.timeout:
- event["stderr"].write("%s: eval timed out" %
- event["user"].nickname)
- return
+ if page:
+ event["stdout"].write("%s: %s" % (event["user"].nickname,
+ page.split("</b></span><br>", 1)[1]))
+ else:
+ event["stderr"].write("%s: failed to eval" % event["user"].nickname)
- if page:
- event["stdout"].write("%s: %s" % (event["user"].nickname,
- page["output"].strip("\n")))
- return
+ @utils.hook("received.command.py2", alias_of="python2")
+ @utils.hook("received.command.python2", min_args=1)
+ def eval(self, event):
+ self._eval("python", event)
- event["stderr"].write("%s: failed to eval" % event["user"].nickname)
+ @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)