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-2/miku/plugins/boobs.lua
Andreas Bielawski d9a6836dd5 - Portiere get_data
- Ergänze Antworten da, wo ich es vergessen habe...
2016-08-18 17:38:20 +02:00

69 lines
1.5 KiB
Lua

local boobs = {}
boobs.triggers = {
"^/([Bb][Oo][Oo][Bb][Ss])$",
"^/([Bb][Uu][Tt][Tt][Ss])$"
}
boobs.command = 'boobs, /butts'
-- Recursive function
function boobs:getRandomButts(attempt)
attempt = attempt or 0
attempt = attempt + 1
local res,status = http.request("http://api.obutts.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 <= 3 then
print('Keine Butts gefunden!')
return getRandomButts(attempt)
end
return 'http://media.obutts.ru/' .. data.preview
end
function boobs:getRandomBoobs(attempt)
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
print('Keine Boobs gefunden!')
return getRandomBoobs(attempt)
end
return 'http://media.oboobs.ru/' .. data.preview
end
function boobs:action(msg, config, matches)
local url
if matches[1]:match("[Bb][Oo][Oo][Bb][Ss]") then
url = boobs:getRandomBoobs()
end
if matches[1]:match("[Bb][Uu][Tt][Tt][Ss]") then
url = boobs:getRandomButts()
end
if url ~= nil then
local file = download_to_file(url)
utilities.send_photo(self, msg.chat.id, file, url, msg.message_id)
return
else
utilities.send_reply(self, msg, 'Nichts gefunden :(')
return
end
end
return boobs