2016-04-11 06:04:47 +02:00
|
|
|
local luarun = {}
|
2015-12-13 15:25:49 +01:00
|
|
|
|
2016-07-17 13:22:27 +02:00
|
|
|
local utilities = require('miku.utilities')
|
2016-05-29 19:08:39 +02:00
|
|
|
local URL = require('socket.url')
|
|
|
|
local JSON = require('dkjson')
|
2015-12-13 15:25:49 +01:00
|
|
|
|
2016-05-27 05:28:44 +02:00
|
|
|
function luarun:init(config)
|
|
|
|
luarun.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('lua', true):t('return', true).table
|
2016-04-11 06:04:47 +02:00
|
|
|
end
|
|
|
|
|
2016-05-27 02:26:30 +02:00
|
|
|
function luarun:action(msg, config)
|
2016-04-11 06:04:47 +02:00
|
|
|
|
2016-05-27 02:26:30 +02:00
|
|
|
if msg.from.id ~= config.admin then
|
2016-05-29 19:08:39 +02:00
|
|
|
return true
|
2015-12-13 15:25:49 +01:00
|
|
|
end
|
|
|
|
|
2016-04-08 23:12:02 +02:00
|
|
|
local input = utilities.input(msg.text)
|
2015-12-13 15:25:49 +01:00
|
|
|
if not input then
|
2016-05-29 19:08:39 +02:00
|
|
|
utilities.send_reply(self, msg, 'Please enter a string to load.')
|
2015-12-13 15:25:49 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2016-05-27 05:28:44 +02:00
|
|
|
if msg.text_lower:match('^'..config.cmd_pat..'return') then
|
2016-05-29 19:08:39 +02:00
|
|
|
input = 'return ' .. input
|
|
|
|
end
|
|
|
|
|
2016-05-19 08:34:24 +02:00
|
|
|
local output = loadstring( [[
|
2016-07-17 13:22:27 +02:00
|
|
|
local bot = require('miku.bot')
|
|
|
|
local bindings = require('miku.bindings')
|
|
|
|
local utilities = require('miku.utilities')
|
2016-05-19 08:34:24 +02:00
|
|
|
local JSON = require('dkjson')
|
|
|
|
local URL = require('socket.url')
|
|
|
|
local HTTP = require('socket.http')
|
|
|
|
local HTTPS = require('ssl.https')
|
2016-05-27 05:28:44 +02:00
|
|
|
return function (self, msg, config) ]] .. input .. [[ end
|
|
|
|
]] )()(self, msg, config)
|
2016-01-12 11:22:28 +01:00
|
|
|
if output == nil then
|
2015-12-14 20:48:17 +01:00
|
|
|
output = 'Done!'
|
|
|
|
else
|
2016-05-29 19:08:39 +02:00
|
|
|
if type(output) == 'table' then
|
|
|
|
local s = JSON.encode(output, {indent=true})
|
|
|
|
if URL.escape(s):len() < 4000 then
|
|
|
|
output = s
|
|
|
|
end
|
|
|
|
end
|
2016-01-12 11:22:28 +01:00
|
|
|
output = '```\n' .. tostring(output) .. '\n```'
|
2015-12-14 20:48:17 +01:00
|
|
|
end
|
2016-05-29 19:08:39 +02:00
|
|
|
utilities.send_message(self, msg.chat.id, output, true, msg.message_id, true)
|
2015-12-13 15:25:49 +01:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
return luarun
|
2015-12-13 15:25:49 +01:00
|
|
|
|