bitbot-3.11-fork/modules/eval_python.py

27 lines
744 B
Python
Raw Normal View History

#--depends-on commands
2019-11-08 12:46:25 +00:00
import urllib.parse
from src import ModuleManager, utils
2018-09-19 12:56:57 +00:00
2019-11-08 12:46:25 +00:00
EVAL_URL = "http://dotpy3.herokuapp.com/"
class Module(ModuleManager.BaseModule):
_name = "Python"
2018-10-12 11:39:01 +00:00
2019-11-08 12:46:25 +00:00
@utils.hook("received.command.py", alias_of="python")
@utils.hook("received.command.python")
def _eval(self, event):
url = "%s?%s" % (EVAL_URL, urllib.parse.quote(event["args"]))
page = None
2018-09-19 12:56:57 +00:00
try:
2019-11-08 12:46:25 +00:00
page = utils.http.request(url)
except:
pass
2018-09-19 12:56:57 +00:00
if page and page.data:
2019-11-08 12:46:25 +00:00
event["stdout"].write("%s: %s" % (event["user"].nickname,
2019-12-18 19:51:35 +00:00
page.decode("utf8").rstrip("\n")))
2018-10-12 11:39:01 +00:00
else:
event["stderr"].write("%s: failed to eval" % event["user"].nickname)