diff --git a/.gitignore b/.gitignore index 87ea3b6..15714db 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ miku/plugins/licht.lua Bot-Kommandoliste.txt msg.txt merge.sh -miku/plugins/link_warning.lua \ No newline at end of file +miku/plugins/link_warning.lua +luarocks \ No newline at end of file diff --git a/README.md b/README.md index d7eb4d0..b6579e4 100644 --- a/README.md +++ b/README.md @@ -22,10 +22,12 @@ Mikubot V2 ist freie Software; du darfst ihn modifizieren und weiterverbreiten, # Für User ## Setup ### 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 -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 * luasocket * 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.version` speichert die Bot-Version. \ No newline at end of file +`database.version` speichert die Bot-Version. diff --git a/install-dependencies.sh b/install-dependencies.sh new file mode 100755 index 0000000..2b93546 --- /dev/null +++ b/install-dependencies.sh @@ -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." diff --git a/launch.sh b/launch.sh index 10c027a..53cd1c1 100755 --- a/launch.sh +++ b/launch.sh @@ -1,8 +1,21 @@ #!/bin/sh -# Launch Mikubot -# Restart Mikubot five seconds after halted. -while true; do - lua main.lua - echo 'Mikubot wurde gestoppt. ^C zum beenden.' - sleep 5s -done \ No newline at end of file +# Run Mikubot. +# If none, give an error and a friendly suggestion. +# If Lua was found, restart Mikubot five seconds after halting each time. + +if type lua5.2 >/dev/null 2>/dev/null; then + while true; do + 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 \ No newline at end of file diff --git a/miku/plugins/luarun.lua b/miku/plugins/luarun.lua index d4fb843..fc714b7 100644 --- a/miku/plugins/luarun.lua +++ b/miku/plugins/luarun.lua @@ -17,6 +17,12 @@ function luarun:init(config) return JSON.encode(t, {indent=true}) 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 function luarun:action(msg, config) @@ -35,24 +41,21 @@ function luarun:action(msg, config) input = 'return ' .. input end - local output, success = - load("local bot = require('miku.bot')\n\z + local output, success = luarun.loadstring( + "local bot = require('miku.bot')\n\z local bindings = require('miku.bindings')\n\z local utilities = require('miku.utilities')\n\z local json = require('dkjson')\n\z local URL = require('socket.url')\n\z local http = require('socket.http')\n\z local https = require('ssl.https')\n\z - return function (self, msg, config)\n" .. input .. "\nend") - - local function err_msg(x) - return "Fehler:\n" .. tostring(x) - end + return function (self, msg, config)\n" .. input .. "\nend" + ) if output == nil then output = success else - success, output = xpcall(output(), err_msg, self, msg, config) + success, output = xpcall(output(), luarun.err_msg, self, msg, config) end if output == nil then diff --git a/miku/utilities.lua b/miku/utilities.lua index 8092b83..d534592 100644 --- a/miku/utilities.lua +++ b/miku/utilities.lua @@ -20,7 +20,7 @@ local utilities = {} -utf8 = require 'lua-utf8' +utf8 = require('lua-utf8') ltn12 = require('ltn12') http = require('socket.http') https = require('ssl.https') @@ -1134,7 +1134,8 @@ end -- Converts a gross string back into proper UTF-8. -- Useful for fixing improper encoding caused by bad JSON escaping. function utilities.fix_utf8(str) - return string.char(utf8.codepoint(str, 1, -1)) + return string.char(utf8.codepoint(str, 1, -1)) end -return utilities \ No newline at end of file + +return utilities