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
|
|
|
|
|
|
|
EVAL_URL = "https://eval.appspot.com/eval"
|
|
|
|
|
2018-09-26 17:27:17 +00:00
|
|
|
class Module(ModuleManager.BaseModule):
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("received.command.eval", min_args=1)
|
2018-09-19 12:56:57 +00:00
|
|
|
def eval(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-30 16:29:09 +00:00
|
|
|
:help: Evaluate a python statement
|
|
|
|
:usage: <statement>
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-19 12:56:57 +00:00
|
|
|
try:
|
2018-10-03 12:22:37 +00:00
|
|
|
code, page = utils.http.get_url(EVAL_URL, get_params={
|
2018-09-19 12:56:57 +00:00
|
|
|
"statement": event["args"]}, code=True)
|
|
|
|
except socket.timeout:
|
|
|
|
event["stderr"].write("%s: eval timed out" %
|
|
|
|
event["user"].nickname)
|
|
|
|
return
|
|
|
|
|
|
|
|
if not page == None and code == 200:
|
|
|
|
event["stdout"].write("%s: %s" % (event["user"].nickname,
|
|
|
|
page))
|
|
|
|
else:
|
|
|
|
event["stderr"].write("%s: failed to eval" %
|
|
|
|
event["user"].nickname)
|