bitbot-3.11-fork/modules/eval_python.py

29 lines
925 B
Python
Raw Normal View History

2018-09-19 12:56:57 +00:00
import socket
from src import ModuleManager, utils
2018-09-19 12:56:57 +00:00
EVAL_URL = "https://eval.appspot.com/eval"
class Module(ModuleManager.BaseModule):
_name = "Python"
@utils.hook("received.command.py", alias_of="python")
@utils.hook("received.command.python", min_args=1)
2018-09-19 12:56:57 +00:00
def eval(self, event):
"""
:help: Evaluate a python statement
:usage: <statement>
"""
2018-09-19 12:56:57 +00:00
try:
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)