2019-05-25 20:40:06 +00:00
|
|
|
#--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:
|
2018-12-11 22:26:38 +00:00
|
|
|
page = utils.http.request(EVAL_URL,
|
2018-10-10 12:41:58 +00:00
|
|
|
post_data={"input": event["args"]},
|
2018-10-09 21:15:27 +00:00
|
|
|
method="POST",
|
|
|
|
soup=True)
|
|
|
|
except socket.timeout:
|
2018-10-16 14:09:58 +00:00
|
|
|
raise utils.EventError("%s: eval timed out" %
|
2018-10-09 21:15:27 +00:00
|
|
|
event["user"].nickname)
|
|
|
|
|
|
|
|
if page:
|
2018-12-11 22:26:38 +00:00
|
|
|
textareas = page.data.find_all("textarea")
|
2018-10-09 21:15:27 +00:00
|
|
|
if len(textareas) > 1:
|
2018-10-10 11:03:09 +00:00
|
|
|
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)
|