bitbot-3.11-fork/modules/eval_lua.py

26 lines
855 B
Python
Raw Permalink Normal View History

#--depends-on commands
2018-10-09 21:15:27 +00:00
import socket
from src import ModuleManager, utils
EVAL_URL = "https://www.lua.org/cgi-bin/demo"
class Module(ModuleManager.BaseModule):
_name = "Lua"
@utils.hook("received.command.lua", min_args=1)
def eval(self, event):
try:
page = utils.http.request(EVAL_URL, post_data=
{"input": event["args"]}, method="POST")
2018-10-09 21:15:27 +00:00
except socket.timeout:
raise utils.EventError("%s: eval timed out" %
2018-10-09 21:15:27 +00:00
event["user"].nickname)
if page:
textareas = page.soup().find_all("textarea")
2018-10-09 21:15:27 +00:00
if len(textareas) > 1:
out = textareas[1].text.strip("\n")
2018-10-09 21:15:27 +00:00
event["stdout"].write("%s: %s" % (event["user"].nickname, out))
else:
event["stderr"].write("%s: failed to eval" % event["user"].nickname)