Merge Upstream, aber aktualisiere nicht auf LUA 5.3

This commit is contained in:
Andreas Bielawski 2016-09-04 13:19:52 +02:00
commit 56142c9a11
4 changed files with 63 additions and 47 deletions

View File

@ -184,4 +184,4 @@ Das ist die Datenbank-Struktur:
`database.userdata` speichert Daten von verschiedenen Plugins, hierzu wird aber für Brawlbot-Plugins Redis verwendet. `database.userdata` speichert Daten von verschiedenen Plugins, hierzu wird aber für Brawlbot-Plugins Redis verwendet.
`database.version` speichert die Bot-Version. `database.version` speichert die Bot-Version

View File

@ -1,5 +1,6 @@
#!/bin/sh #!/bin/sh
# Launch Brawlbot
# Restart Brawlbot five seconds after halted.
while true; do while true; do
lua main.lua lua main.lua
echo 'otouto has stopped. ^C to exit.' echo 'otouto has stopped. ^C to exit.'

View File

@ -23,6 +23,7 @@ local bot = {}
bot.version = '2.2.7' bot.version = '2.2.7'
function bot:init(config) -- The function run when the bot is started or reloaded. function bot:init(config) -- The function run when the bot is started or reloaded.
assert(config.bot_api_key, 'Dein Bot-Token ist nicht in der Config gesetzt!')
bindings = require('otouto.bindings').init(config.bot_api_key) bindings = require('otouto.bindings').init(config.bot_api_key)
utilities = require('otouto.utilities') utilities = require('otouto.utilities')
cred_data = load_cred() cred_data = load_cred()

View File

@ -1,5 +1,9 @@
local luarun = {} local luarun = {}
local utilities = require('otouto.utilities')
local URL = require('socket.url')
local JSON, serpent
function luarun:init(config) function luarun:init(config)
luarun.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('lua', true):t('return', true).table luarun.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('lua', true):t('return', true).table
if config.luarun_serpent then if config.luarun_serpent then
@ -17,13 +21,13 @@ end
function luarun:action(msg, config) function luarun:action(msg, config)
if not is_sudo(msg, config) then if msg.from.id ~= config.admin then
return true return true
end end
local input = utilities.input(msg.text) local input = utilities.input(msg.text)
if not input then if not input then
utilities.send_reply(msg, 'Bitte gebe einen Befehl ein.') utilities.send_reply(msg, 'Bitte tätige eine Eingabe.')
return return
end end
@ -31,18 +35,28 @@ function luarun:action(msg, config)
input = 'return ' .. input input = 'return ' .. input
end end
local output = loadstring( [[ local output, success =
local bot = require('otouto.bot') load("local bot = require('otouto.bot')\n\z
local bindings = require('otouto.bindings') local bindings = require('otouto.bindings')\n\z
local utilities = require('otouto.utilities') local utilities = require('otouto.utilities')\n\z
local json = require('dkjson') local json = require('dkjson')\n\z
local URL = require('socket.url') local URL = require('socket.url')\n\z
local http = require('socket.http') local http = require('socket.http')\n\z
local https = require('ssl.https') local https = require('ssl.https')\n\z
return function (msg, config) ]] .. input .. [[ end return function (self, msg, config)\n" .. input .. "\nend")
]] )()(msg, config)
local function err_msg(x)
return "Fehler:\n" .. tostring(x)
end
if output == nil then if output == nil then
output = 'Ausgeführt!' output = success
else
success, output = xpcall(output(), err_msg, self, msg, config)
end
if output == nil then
output = 'Fertig!'
else else
if type(output) == 'table' then if type(output) == 'table' then
local s = luarun.serialize(output) local s = luarun.serialize(output)
@ -50,9 +64,9 @@ function luarun:action(msg, config)
output = s output = s
end end
end end
output = '```\n' .. tostring(output) .. '\n```' output = '<code>' .. utilities.html_escape(tostring(output)) .. '</code>'
end end
utilities.send_message(msg.chat.id, output, true, msg.message_id, true) utilities.send_message(msg.chat.id, output, true, msg.message_id, 'html')
end end