2015-05-13 20:20:56 +02:00
|
|
|
do
|
|
|
|
|
|
|
|
function getGay(text)
|
|
|
|
local text = URL.escape(text)
|
|
|
|
local api = "https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=8&q=gay+porn"
|
|
|
|
local res, code = http.request(api..text)
|
|
|
|
if code ~= 200 then return nil end
|
|
|
|
local google = json:decode(res)
|
|
|
|
|
|
|
|
if google.responseStatus ~= 200 then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
local data = google.responseData
|
|
|
|
|
|
|
|
if not data or not data.results then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
if #data.results == 0 then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Random image from table
|
2015-11-12 17:42:03 +01:00
|
|
|
-- local i = math.random(#data.results)
|
|
|
|
-- return data.results[i].url
|
|
|
|
return data.results
|
2015-05-13 20:20:56 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function run(msg, matches)
|
|
|
|
local receiver = get_receiver(msg)
|
|
|
|
local text = matches[1]
|
|
|
|
|
2015-11-12 17:42:03 +01:00
|
|
|
local results = getGay(text)
|
|
|
|
if not results then
|
2015-05-13 20:20:56 +02:00
|
|
|
return "Kein Bild gefunden."
|
|
|
|
end
|
2015-11-12 17:42:03 +01:00
|
|
|
local i = math.random(#results)
|
|
|
|
local url = nil;
|
2015-06-24 02:32:35 +02:00
|
|
|
|
2015-11-12 17:42:03 +01:00
|
|
|
local failed = true
|
|
|
|
local nofTries = 0
|
|
|
|
while failed and nofTries < #results do
|
|
|
|
url = results[i].url;
|
|
|
|
print("Bilder-URL: ", url)
|
|
|
|
|
|
|
|
if string.ends(url, ".gif") then
|
|
|
|
failed = not send_document_from_url(receiver, url, nil, nil, true)
|
|
|
|
elseif string.ends(url, ".jpg") or string.ends(url, ".jpeg") or string.ends(url, ".png") then
|
|
|
|
failed = not send_photo_from_url(receiver, url, nil, nil, true)
|
|
|
|
end
|
|
|
|
|
|
|
|
nofTries = nofTries + 1
|
|
|
|
i = i+1
|
|
|
|
if i > #results then
|
|
|
|
i = 1
|
|
|
|
end
|
2015-06-24 02:32:35 +02:00
|
|
|
end
|
2015-11-12 17:42:03 +01:00
|
|
|
|
|
|
|
if failed then
|
|
|
|
return "Fehler beim Laden des Bildes."
|
2015-06-24 02:32:35 +02:00
|
|
|
else
|
2015-11-12 17:42:03 +01:00
|
|
|
return "Source: "..url
|
2015-06-24 02:32:35 +02:00
|
|
|
end
|
2015-05-13 20:20:56 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return {
|
|
|
|
description = "Sucht Bild mit Google-API und versendet es [NSFW]",
|
|
|
|
usage = {"/gay"},
|
|
|
|
patterns = {"^/gay$"},
|
|
|
|
run = run
|
|
|
|
}
|
|
|
|
end
|
2015-05-22 17:01:33 +02:00
|
|
|
--Modified by Akamaru [https://ponywave.de]
|