2015-11-12 17:42:03 +01:00
|
|
|
|
local usage = {
|
2016-06-22 13:59:06 +02:00
|
|
|
|
"#mine [IP]: Sucht Minecraft-Server und sendet Infos. Standard-Port: 25565",
|
|
|
|
|
"#mine [IP] [Port]: Sucht Minecraft-Server auf Port und sendet Infos.",
|
2015-11-12 17:42:03 +01:00
|
|
|
|
}
|
2015-05-07 19:47:06 +02:00
|
|
|
|
|
|
|
|
|
local function mineSearch(ip, port, receiver) --25565
|
|
|
|
|
local responseText = ""
|
2015-11-12 17:42:03 +01:00
|
|
|
|
local api = "https://mcapi.us/server/status"
|
|
|
|
|
local parameters = "?ip="..(URL.escape(ip) or "").."&port="..(URL.escape(port) or "").."&players=true"
|
|
|
|
|
print(api..parameters)
|
2015-05-07 19:47:06 +02:00
|
|
|
|
local respbody = {}
|
|
|
|
|
local body, code, headers, status = http.request{
|
|
|
|
|
url = api..parameters,
|
|
|
|
|
method = "GET",
|
|
|
|
|
redirect = true,
|
|
|
|
|
sink = ltn12.sink.table(respbody)
|
|
|
|
|
}
|
|
|
|
|
local body = table.concat(respbody)
|
2015-05-11 20:04:09 +02:00
|
|
|
|
if (status == nil) then return "FEHLER: status = nil" end
|
|
|
|
|
if code ~=200 then return "FEHLER: "..code..". Status: "..status end
|
2015-05-07 19:47:06 +02:00
|
|
|
|
local jsonData = json:decode(body)
|
2015-11-12 17:42:03 +01:00
|
|
|
|
responseText = responseText..ip..":"..port..":\n"
|
|
|
|
|
if (jsonData.motd ~= nil and jsonData.motd ~= '') then
|
2015-05-07 19:47:06 +02:00
|
|
|
|
local tempMotd = ""
|
|
|
|
|
tempMotd = jsonData.motd:gsub('%<25>.', '')
|
2015-05-11 20:04:09 +02:00
|
|
|
|
if (jsonData.motd ~= nil) then responseText = responseText.." MOTD: "..tempMotd.."\n" end
|
2015-05-07 19:47:06 +02:00
|
|
|
|
end
|
|
|
|
|
if (jsonData.online ~= nil) then
|
2015-05-11 20:04:09 +02:00
|
|
|
|
if jsonData.online == true then
|
|
|
|
|
server_online = "Ja"
|
|
|
|
|
else
|
|
|
|
|
server_online = "Nein"
|
|
|
|
|
end
|
|
|
|
|
responseText = responseText.." Online: "..server_online.."\n"
|
2015-05-07 19:47:06 +02:00
|
|
|
|
end
|
|
|
|
|
if (jsonData.players ~= nil) then
|
2015-11-12 17:42:03 +01:00
|
|
|
|
if (jsonData.players.max ~= nil and jsonData.players.max ~= 0) then
|
2015-05-11 20:04:09 +02:00
|
|
|
|
responseText = responseText.." Slots: "..jsonData.players.max.."\n"
|
2015-05-07 19:47:06 +02:00
|
|
|
|
end
|
2015-11-12 17:42:03 +01:00
|
|
|
|
if (jsonData.players.now ~= nil and jsonData.players.max ~= 0) then
|
2015-05-11 20:04:09 +02:00
|
|
|
|
responseText = responseText.." Spieler online: "..jsonData.players.now.."\n"
|
2015-05-07 19:47:06 +02:00
|
|
|
|
end
|
|
|
|
|
if (jsonData.players.sample ~= nil and jsonData.players.sample ~= false) then
|
2015-05-11 20:04:09 +02:00
|
|
|
|
responseText = responseText.." Spieler: "..table.concat(jsonData.players.sample, ", ").."\n"
|
2015-05-07 19:47:06 +02:00
|
|
|
|
end
|
2015-11-12 17:42:03 +01:00
|
|
|
|
if (jsonData.server.name ~= nil and jsonData.server.name ~= "") then
|
|
|
|
|
responseText = responseText.." Server: "..jsonData.server.name.."\n"
|
|
|
|
|
end
|
2015-05-07 19:47:06 +02:00
|
|
|
|
end
|
|
|
|
|
return responseText
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function parseText(chat, text)
|
2016-06-22 13:59:06 +02:00
|
|
|
|
if (text == nil or text == "#mine") then
|
2015-05-11 20:04:09 +02:00
|
|
|
|
return usage
|
2015-05-07 19:47:06 +02:00
|
|
|
|
end
|
2016-06-22 13:59:06 +02:00
|
|
|
|
ip, port = string.match(text, "^#mine (.-) (.*)$")
|
2015-05-07 19:47:06 +02:00
|
|
|
|
if (ip ~= nil and port ~= nil) then
|
|
|
|
|
return mineSearch(ip, port, chat)
|
|
|
|
|
end
|
2016-06-22 13:59:06 +02:00
|
|
|
|
local ip = string.match(text, "^#mine (.*)$")
|
2015-05-07 19:47:06 +02:00
|
|
|
|
if (ip ~= nil) then
|
|
|
|
|
return mineSearch(ip, "25565", chat)
|
|
|
|
|
end
|
2015-11-12 17:42:03 +01:00
|
|
|
|
return "FEHLER: Keine Input IP??"
|
2015-05-07 19:47:06 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local function run(msg, matches)
|
|
|
|
|
local chat_id = tostring(msg.to.id)
|
|
|
|
|
local result = parseText(chat_id, msg.text)
|
|
|
|
|
return result
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return {
|
2015-05-11 20:04:09 +02:00
|
|
|
|
description = "Dursucht Minecraft-Server und sendet Infos",
|
|
|
|
|
usage = usage,
|
2015-11-12 17:42:03 +01:00
|
|
|
|
patterns = {
|
2016-06-22 13:59:06 +02:00
|
|
|
|
"^#mine (.*)$"
|
2015-11-12 17:42:03 +01:00
|
|
|
|
},
|
2015-05-07 19:47:06 +02:00
|
|
|
|
run = run
|
|
|
|
|
}
|