2015-03-08 22:02:19 +01:00
|
|
|
|
do
|
2015-03-06 02:30:44 +01:00
|
|
|
|
|
2015-04-16 21:42:25 +02:00
|
|
|
|
-- Recursive function
|
|
|
|
|
local function getRandomButts(attempt)
|
2015-03-08 22:11:00 +01:00
|
|
|
|
attempt = attempt or 0
|
2015-03-08 22:02:19 +01:00
|
|
|
|
attempt = attempt + 1
|
2015-03-06 02:30:44 +01:00
|
|
|
|
|
2015-03-08 22:02:19 +01:00
|
|
|
|
local res,status = http.request("http://api.obutts.ru/noise/1")
|
2015-03-06 02:30:44 +01:00
|
|
|
|
|
2015-03-08 22:02:19 +01:00
|
|
|
|
if status ~= 200 then return nil end
|
|
|
|
|
local data = json:decode(res)[1]
|
2015-03-06 02:30:44 +01:00
|
|
|
|
|
2015-03-08 22:02:19 +01:00
|
|
|
|
-- The OpenBoobs API sometimes returns an empty array
|
2015-05-28 16:47:30 +02:00
|
|
|
|
if not data and attempt <= 3 then
|
2015-04-14 20:21:23 +02:00
|
|
|
|
print('Keine Butts gefunden!')
|
2015-03-08 22:11:00 +01:00
|
|
|
|
return getRandomButts(attempt)
|
2015-03-08 22:02:19 +01:00
|
|
|
|
end
|
2015-03-06 02:30:44 +01:00
|
|
|
|
|
2015-03-08 22:02:19 +01:00
|
|
|
|
return 'http://media.obutts.ru/' .. data.preview
|
|
|
|
|
end
|
|
|
|
|
|
2015-04-16 21:42:25 +02:00
|
|
|
|
local function getRandomBoobs(attempt)
|
2015-03-08 22:11:00 +01:00
|
|
|
|
attempt = attempt or 0
|
2015-03-08 22:02:19 +01:00
|
|
|
|
attempt = attempt + 1
|
|
|
|
|
|
|
|
|
|
local res,status = http.request("http://api.oboobs.ru/noise/1")
|
|
|
|
|
|
|
|
|
|
if status ~= 200 then return nil end
|
|
|
|
|
local data = json:decode(res)[1]
|
|
|
|
|
|
|
|
|
|
-- The OpenBoobs API sometimes returns an empty array
|
|
|
|
|
if not data and attempt < 10 then
|
2015-04-14 20:21:23 +02:00
|
|
|
|
print('Keine Boobs gefunden!')
|
2015-03-08 22:02:19 +01:00
|
|
|
|
return getRandomBoobs(attempt)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return 'http://media.oboobs.ru/' .. data.preview
|
2015-03-06 02:30:44 +01:00
|
|
|
|
end
|
|
|
|
|
|
2015-04-16 21:42:25 +02:00
|
|
|
|
local function run(msg, matches)
|
2015-03-08 22:02:19 +01:00
|
|
|
|
local url = nil
|
|
|
|
|
|
2015-04-14 20:21:23 +02:00
|
|
|
|
if matches[1] == "/boobs" then
|
2015-03-08 22:02:19 +01:00
|
|
|
|
url = getRandomBoobs()
|
|
|
|
|
end
|
2015-03-06 02:30:44 +01:00
|
|
|
|
|
2015-04-14 20:21:23 +02:00
|
|
|
|
if matches[1] == "/butts" then
|
2015-03-08 22:02:19 +01:00
|
|
|
|
url = getRandomButts()
|
|
|
|
|
end
|
2015-03-06 02:30:44 +01:00
|
|
|
|
|
2015-03-08 22:02:19 +01:00
|
|
|
|
if url ~= nil then
|
|
|
|
|
local receiver = get_receiver(msg)
|
|
|
|
|
send_photo_from_url(receiver, url)
|
2015-05-02 21:25:22 +02:00
|
|
|
|
--return "Source: "..url
|
|
|
|
|
return "Bild wird gesendet!"
|
2015-03-08 22:02:19 +01:00
|
|
|
|
else
|
2015-04-14 20:21:23 +02:00
|
|
|
|
return 'Keine Boobs/Butts gefunden.'
|
2015-03-08 22:02:19 +01:00
|
|
|
|
end
|
2015-03-06 02:30:44 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return {
|
2015-04-14 20:21:23 +02:00
|
|
|
|
description = "Sendet ein zuf<75>lliges Boobs/Butts Bild",
|
2015-04-28 17:49:11 +02:00
|
|
|
|
usage = {"/boobs","/butts"},
|
|
|
|
|
patterns = {"^/boobs$","^/butts$"},
|
2015-03-08 22:02:19 +01:00
|
|
|
|
run = run
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-10 18:21:37 +01:00
|
|
|
|
end
|