This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot/plugins/boobs.lua

69 lines
1.5 KiB
Lua
Raw Normal View History

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
attempt = attempt + 1
2015-03-06 02:30:44 +01:00
local res,status = http.request("http://api.obutts.ru/noise/1")
2015-03-06 02:30:44 +01:00
if status ~= 200 then return nil end
local data = json:decode(res)[1]
2015-03-06 02:30:44 +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)
end
2015-03-06 02:30:44 +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
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!')
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)
local url = nil
2015-04-14 20:21:23 +02:00
if matches[1] == "/boobs" then
url = getRandomBoobs()
end
2015-03-06 02:30:44 +01:00
2015-04-14 20:21:23 +02:00
if matches[1] == "/butts" then
url = getRandomButts()
end
2015-03-06 02:30:44 +01:00
if url ~= nil then
local receiver = get_receiver(msg)
send_photo_from_url(receiver, url)
--return "Source: "..url
return "Bild wird gesendet!"
else
2015-04-14 20:21:23 +02:00
return 'Keine Boobs/Butts gefunden.'
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$"},
run = run
}
2015-03-10 18:21:37 +01:00
end