Merge Upstream

This commit is contained in:
Akamaru 2016-09-07 19:46:28 +02:00
commit 0726580eed
6 changed files with 71 additions and 22 deletions

3
.gitignore vendored
View File

@ -6,4 +6,5 @@ miku/plugins/licht.lua
Bot-Kommandoliste.txt Bot-Kommandoliste.txt
msg.txt msg.txt
merge.sh merge.sh
miku/plugins/link_warning.lua miku/plugins/link_warning.lua
luarocks

View File

@ -22,10 +22,12 @@ Mikubot V2 ist freie Software; du darfst ihn modifizieren und weiterverbreiten,
# Für User # Für User
## Setup ## Setup
### Ubuntu und Debian ### Ubuntu und Debian
Ubuntu und Debian liefern Luarocks nur für Lua 5.1 aus. Um Luarocks für Lua 5.2 zu verwenden, folge bitte der [Anleitung auf StackOverflow](http://stackoverflow.com/a/20359102). Falls du Ubuntu oder Debian verwendest, kannst du einfach `./install-dependencies.sh` ausführen, damit alles installiert wird. Ergänze dann noch den `bot_api_key` und die `admin`-ID (Bekommst du in Telegram mit `@Mikubot id`) und kopiere die config.lua.example nach config.lua.
Für eine manuelle Installation musst du LuaRocks für 5.2 [selbst kompilieren](http://stackoverflow.com/a/20359102).
### Setup ### Setup
Du benötigst **Lua 5.2+**, eine aktive **Redis-Instanz** und die folgenden **LuaRocks-Module**: Du benötigst **Lua 5.2** (Lua 5.3 funktioniert NICHT!), eine aktive **Redis-Instanz** und die folgenden **LuaRocks-Module**:
* luautf8 * luautf8
* luasocket * luasocket
* luasec * luasec
@ -176,4 +178,4 @@ Das ist die Datenbank-Struktur:
`database.userdata` speichert Daten von verschiedenen Plugins, hierzu wird aber für Mikubot-Plugins Redis verwendet. `database.userdata` speichert Daten von verschiedenen Plugins, hierzu wird aber für Mikubot-Plugins Redis verwendet.
`database.version` speichert die Bot-Version. `database.version` speichert die Bot-Version.

29
install-dependencies.sh Executable file
View File

@ -0,0 +1,29 @@
#!/bin/sh
# Installiert Lua, Luarocks und andere Abhängigkeiten. Sollte auch auf Debian funktionieren.
rocklist="luasocket luasec multipart-post lpeg dkjson redis-lua fakeredis oauth xml feedparser serpent luautf8"
echo "Dieses Skript ist für Ubuntu, es wird wahrscheinlich auch für Debian funktionieren."
echo "Dieses Skript benötigt Root-Rechte, um folgende Pakete zu installieren:"
echo "lua5.2 liblua5.2-dev git libssl-dev fortune-mod fortunes redis-server unzip make"
echo "Es werden auch Root-Rechte benötigt, um LuaRocks in /usr/local/"
echo "mit den folgenden Rocks zu installieren:"
echo $rocklist
echo "Drücke ENTER, um fortzufahren, oder Strg-C zum Beenden."
read
sudo apt-get update
sudo apt-get install -y lua5.2 liblua5.2-dev git libssl-dev fortune-mod fortunes redis-server unzip make
git clone http://github.com/keplerproject/luarocks
cd luarocks
./configure --lua-version=5.2 --versioned-rocks-dir --lua-suffix=5.2
make build
sudo make install
for rock in $rocklist; do
sudo luarocks-5.2 install $rock
done
sudo -k
cd ..
echo "Vorgang beendet! Nutze ./launch.sh, um den Bot zu starten."
echo "Setze vorher dein Bot-Token in der config.lua.example und kopiere sie nach config.lua."

View File

@ -1,8 +1,21 @@
#!/bin/sh #!/bin/sh
# Launch Mikubot # Run Mikubot.
# Restart Mikubot five seconds after halted. # If none, give an error and a friendly suggestion.
while true; do # If Lua was found, restart Mikubot five seconds after halting each time.
lua main.lua
echo 'Mikubot wurde gestoppt. ^C zum beenden.' if type lua5.2 >/dev/null 2>/dev/null; then
sleep 5s while true; do
done lua5.2 main.lua
echo "Mikubot wurde angehalten. ^C zum Beenden."
sleep 5s
done
elif type lua >/dev/null 2>/dev/null; then
while true; do
lua main.lua
echo "Mikubot wurde angehalten. ^C zum Beenden."
sleep 5s
done
else
echo "Lua nicht gefunden."
echo "Falls du Ubuntu verwendest, führe vorher ./install-dependencies.sh aus."
fi

View File

@ -17,6 +17,12 @@ function luarun:init(config)
return JSON.encode(t, {indent=true}) return JSON.encode(t, {indent=true})
end end
end end
-- Lua 5.2 compatibility.
-- "loadstring" was renamed "load" in 5.3.
luarun.loadstring = load or loadstring
luarun.err_msg = function(x)
return 'Error:\n' .. tostring(x)
end
end end
function luarun:action(msg, config) function luarun:action(msg, config)
@ -35,24 +41,21 @@ function luarun:action(msg, config)
input = 'return ' .. input input = 'return ' .. input
end end
local output, success = local output, success = luarun.loadstring(
load("local bot = require('miku.bot')\n\z "local bot = require('miku.bot')\n\z
local bindings = require('miku.bindings')\n\z local bindings = require('miku.bindings')\n\z
local utilities = require('miku.utilities')\n\z local utilities = require('miku.utilities')\n\z
local json = require('dkjson')\n\z local json = require('dkjson')\n\z
local URL = require('socket.url')\n\z local URL = require('socket.url')\n\z
local http = require('socket.http')\n\z local http = require('socket.http')\n\z
local https = require('ssl.https')\n\z local https = require('ssl.https')\n\z
return function (self, msg, config)\n" .. input .. "\nend") return function (self, msg, config)\n" .. input .. "\nend"
)
local function err_msg(x)
return "Fehler:\n" .. tostring(x)
end
if output == nil then if output == nil then
output = success output = success
else else
success, output = xpcall(output(), err_msg, self, msg, config) success, output = xpcall(output(), luarun.err_msg, self, msg, config)
end end
if output == nil then if output == nil then

View File

@ -20,7 +20,7 @@
local utilities = {} local utilities = {}
utf8 = require 'lua-utf8' utf8 = require('lua-utf8')
ltn12 = require('ltn12') ltn12 = require('ltn12')
http = require('socket.http') http = require('socket.http')
https = require('ssl.https') https = require('ssl.https')
@ -1134,7 +1134,8 @@ end
-- Converts a gross string back into proper UTF-8. -- Converts a gross string back into proper UTF-8.
-- Useful for fixing improper encoding caused by bad JSON escaping. -- Useful for fixing improper encoding caused by bad JSON escaping.
function utilities.fix_utf8(str) function utilities.fix_utf8(str)
return string.char(utf8.codepoint(str, 1, -1)) return string.char(utf8.codepoint(str, 1, -1))
end end
return utilities
return utilities