updated minecraft.lua
This commit is contained in:
		| @@ -3,7 +3,7 @@ socket = require("socket") | ||||
| function cron() | ||||
| 	-- Use yours desired web and id | ||||
| 	local addr = "www.boerse.to" | ||||
| 	local dest = "chat#id21091846" | ||||
| 	local dest = "chat#id12345678" | ||||
|     -- Checks a TCP connexion | ||||
|     local connexion = socket.connect(addr, 80) | ||||
|     if not connexion then  | ||||
|   | ||||
| @@ -1,44 +1,5 @@ | ||||
| -- -- Lua 5.1+ base64 v3.0 (c) 2009 by Alex Kloss <alexthkloss@web.de> | ||||
| -- -- 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 usage = "/mine [IP]: Sucht Minecraft-Server und sendet Infos. Standard-Port: 25565, /mine [IP] [Port]: Sucht Minecraft-Server auf Port und sendet Infos." | ||||
| local ltn12 = require "ltn12" | ||||
| local mime = require "mime" | ||||
|  | ||||
| local function mineSearch(ip, port, receiver) --25565 | ||||
|   local responseText = "" | ||||
| @@ -53,51 +14,53 @@ local function mineSearch(ip, port, receiver) --25565 | ||||
|     sink = ltn12.sink.table(respbody) | ||||
|   } | ||||
|   local body = table.concat(respbody) | ||||
|   if (status == nil) then return "ERROR: status = nil" end | ||||
|   if code ~=200 then return "ERROR: "..code..". Status: "..status end | ||||
|   if (status == nil) then return "FEHLER: status = nil" end | ||||
|   if code ~=200 then return "FEHLER: "..code..". Status: "..status end | ||||
|   local jsonData = json:decode(body) | ||||
|   responseText = responseText..ip..":"..port.." ->\n" | ||||
|   if (jsonData.motd ~= nil) then | ||||
|     local tempMotd = "" | ||||
|     tempMotd = jsonData.motd:gsub('%<25>.', '') | ||||
|     if (jsonData.motd ~= nil) then responseText = responseText.." Motd: "..tempMotd.."\n" end | ||||
|     if (jsonData.motd ~= nil) then responseText = responseText.." MOTD: "..tempMotd.."\n" end | ||||
|   end | ||||
|   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 | ||||
|   if (jsonData.players ~= nil) then | ||||
|     if (jsonData.players.max ~= nil) then | ||||
|       responseText = responseText.."  Max Players: "..jsonData.players.max.."\n" | ||||
|       responseText = responseText.."  Slots: "..jsonData.players.max.."\n" | ||||
|     end | ||||
|     if (jsonData.players.now ~= nil) then | ||||
|       responseText = responseText.."  Players online: "..jsonData.players.now.."\n" | ||||
|       responseText = responseText.."  Spieler online: "..jsonData.players.now.."\n" | ||||
|     end | ||||
|     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 | ||||
|   if (jsonData.favicon ~= nil and false) then | ||||
|     file = io.open("/tmp/telegrambot-mineIcon.png","w") | ||||
|       file:write(dec(jsonData.favicon)) | ||||
|     io.close(file) | ||||
|     send_photo(receiver, "/tmp/telegrambot-mineIcon.png") | ||||
|     --send_photo(receiver, jsonData.favicon) --(decode base64 and send) | ||||
|   end | ||||
|   return responseText | ||||
| end | ||||
|  | ||||
| local function parseText(chat, text) | ||||
|   if (text == nil or text == "!mine") then | ||||
|     return "USAGE" | ||||
|   if (text == nil or text == "/mine") then | ||||
|     return usage | ||||
|   end | ||||
|   ip, port = string.match(text, "^!mine (.-) (.*)$") | ||||
|   ip, port = string.match(text, "^/mine (.-) (.*)$") | ||||
|   if (ip ~= nil and port ~= nil) then | ||||
|     return mineSearch(ip, port, chat) | ||||
|   end | ||||
|   local ip = string.match(text, "^!mine (.*)$") | ||||
|   local ip = string.match(text, "^/mine (.*)$") | ||||
|   if (ip ~= nil) then | ||||
|     return mineSearch(ip, "25565", chat) | ||||
|   end | ||||
|   return "ERROR: no input ip?" | ||||
|   return "FEHLER: Keine Input IP??" | ||||
| end | ||||
|  | ||||
|  | ||||
| @@ -108,10 +71,10 @@ local function run(msg, matches) | ||||
| end | ||||
|  | ||||
| return { | ||||
|   description = "Searches Minecraft server and send info", | ||||
|   usage = "!mine <ip> [port]", | ||||
|   description = "Dursucht Minecraft-Server und sendet Infos", | ||||
|   usage = usage, | ||||
|   patterns = { | ||||
|     "^!mine (.*)$" | ||||
|     "^/mine (.*)$" | ||||
|   }, | ||||
|   run = run | ||||
| } | ||||
		Reference in New Issue
	
	Block a user