updated minecraft.lua

This commit is contained in:
Akamaru 2015-05-11 20:04:09 +02:00
parent 2c3297f834
commit 01098fb4e8
2 changed files with 23 additions and 60 deletions

View File

@ -3,7 +3,7 @@ socket = require("socket")
function cron() function cron()
-- Use yours desired web and id -- Use yours desired web and id
local addr = "www.boerse.to" local addr = "www.boerse.to"
local dest = "chat#id21091846" local dest = "chat#id12345678"
-- Checks a TCP connexion -- Checks a TCP connexion
local connexion = socket.connect(addr, 80) local connexion = socket.connect(addr, 80)
if not connexion then if not connexion then

View File

@ -1,44 +1,5 @@
-- -- Lua 5.1+ base64 v3.0 (c) 2009 by Alex Kloss <alexthkloss@web.de> local usage = "/mine [IP]: Sucht Minecraft-Server und sendet Infos. Standard-Port: 25565, /mine [IP] [Port]: Sucht Minecraft-Server auf Port und sendet Infos."
-- -- licensed under the terms of the LGPL2
-- -- character table string
local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
-- -- encoding
-- local function enc(data)
-- return ((data:gsub('.', function(x)
-- local r,b='',x:byte()
-- for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end
-- return r;
-- end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x)
-- if (#x < 6) then return '' end
-- local c=0
-- for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end
-- return b:sub(c+1,c+1)
-- end)..({ '', '==', '=' })[#data%3+1])
-- end
-- decoding
function dec(data)
data = string.gsub(data, '[^'..b..'=]', '')
return (data:gsub('.', function(x)
if (x == '=') then return '' end
local r,f='',(b:find(x)-1)
for i=6,1,-1 do r=r..(f%2^i-f%2^(i-1)>0 and '1' or '0') end
return r;
end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x)
if (#x ~= 8) then return '' end
local c=0
for i=1,8 do c=c+(x:sub(i,i)=='1' and 2^(8-i) or 0) end
return string.char(c)
end))
end
----------------------------------------------
local ltn12 = require "ltn12" local ltn12 = require "ltn12"
local mime = require "mime"
local function mineSearch(ip, port, receiver) --25565 local function mineSearch(ip, port, receiver) --25565
local responseText = "" local responseText = ""
@ -53,51 +14,53 @@ local function mineSearch(ip, port, receiver) --25565
sink = ltn12.sink.table(respbody) sink = ltn12.sink.table(respbody)
} }
local body = table.concat(respbody) local body = table.concat(respbody)
if (status == nil) then return "ERROR: status = nil" end if (status == nil) then return "FEHLER: status = nil" end
if code ~=200 then return "ERROR: "..code..". Status: "..status end if code ~=200 then return "FEHLER: "..code..". Status: "..status end
local jsonData = json:decode(body) local jsonData = json:decode(body)
responseText = responseText..ip..":"..port.." ->\n" responseText = responseText..ip..":"..port.." ->\n"
if (jsonData.motd ~= nil) then if (jsonData.motd ~= nil) then
local tempMotd = "" local tempMotd = ""
tempMotd = jsonData.motd:gsub('%§.', '') tempMotd = jsonData.motd:gsub('%§.', '')
if (jsonData.motd ~= nil) then responseText = responseText.." Motd: "..tempMotd.."\n" end if (jsonData.motd ~= nil) then responseText = responseText.." MOTD: "..tempMotd.."\n" end
end end
if (jsonData.online ~= nil) then if (jsonData.online ~= nil) then
responseText = responseText.." Online: "..tostring(jsonData.online).."\n" if jsonData.online == true then
server_online = "Ja"
else
server_online = "Nein"
end
responseText = responseText.." Online: "..server_online.."\n"
end end
if (jsonData.players ~= nil) then if (jsonData.players ~= nil) then
if (jsonData.players.max ~= nil) then if (jsonData.players.max ~= nil) then
responseText = responseText.." Max Players: "..jsonData.players.max.."\n" responseText = responseText.." Slots: "..jsonData.players.max.."\n"
end end
if (jsonData.players.now ~= nil) then if (jsonData.players.now ~= nil) then
responseText = responseText.." Players online: "..jsonData.players.now.."\n" responseText = responseText.." Spieler online: "..jsonData.players.now.."\n"
end end
if (jsonData.players.sample ~= nil and jsonData.players.sample ~= false) then if (jsonData.players.sample ~= nil and jsonData.players.sample ~= false) then
responseText = responseText.." Players: "..table.concat(jsonData.players.sample, ", ").."\n" responseText = responseText.." Spieler: "..table.concat(jsonData.players.sample, ", ").."\n"
end end
end end
if (jsonData.favicon ~= nil and false) then if (jsonData.favicon ~= nil and false) then
file = io.open("/tmp/telegrambot-mineIcon.png","w") --send_photo(receiver, jsonData.favicon) --(decode base64 and send)
file:write(dec(jsonData.favicon))
io.close(file)
send_photo(receiver, "/tmp/telegrambot-mineIcon.png")
end end
return responseText return responseText
end end
local function parseText(chat, text) local function parseText(chat, text)
if (text == nil or text == "!mine") then if (text == nil or text == "/mine") then
return "USAGE" return usage
end end
ip, port = string.match(text, "^!mine (.-) (.*)$") ip, port = string.match(text, "^/mine (.-) (.*)$")
if (ip ~= nil and port ~= nil) then if (ip ~= nil and port ~= nil) then
return mineSearch(ip, port, chat) return mineSearch(ip, port, chat)
end end
local ip = string.match(text, "^!mine (.*)$") local ip = string.match(text, "^/mine (.*)$")
if (ip ~= nil) then if (ip ~= nil) then
return mineSearch(ip, "25565", chat) return mineSearch(ip, "25565", chat)
end end
return "ERROR: no input ip?" return "FEHLER: Keine Input IP??"
end end
@ -108,10 +71,10 @@ local function run(msg, matches)
end end
return { return {
description = "Searches Minecraft server and send info", description = "Dursucht Minecraft-Server und sendet Infos",
usage = "!mine <ip> [port]", usage = usage,
patterns = { patterns = {
"^!mine (.*)$" "^/mine (.*)$"
}, },
run = run run = run
} }