!butts command 🍑 and indentation in boobs.lua

This commit is contained in:
yago 2015-03-08 22:02:19 +01:00
parent f831cae647
commit 9c2582f627

View File

@ -1,39 +1,68 @@
do
function getBoobs()
local rand = math.random(1, 8315)
local res,status = http.request("http://api.oboobs.ru/boobs/get/"..rand)
function getRandomButts(attempt)
attempt = attempt or 0;
attempt = attempt + 1
if status ~= 200 then return nil end
local res,status = http.request("http://api.obutts.ru/noise/1")
local data = json:decode(res)
if status ~= 200 then return nil end
local data = json:decode(res)[1]
-- The OpenBoobs API sometimes returns an empty array
if not data[1] then
print 'Cannot get that boobs, trying another ones...'
return getBoobs()
end
-- The OpenBoobs API sometimes returns an empty array
if not data and attempt < 10 then
print('Cannot get that boobs, trying another ones...')
return getRandomBoobs(attempt)
end
return 'http://media.oboobs.ru/' .. data[1].preview
return 'http://media.obutts.ru/' .. data.preview
end
function 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('Cannot get that boobs, trying another ones...')
return getRandomBoobs(attempt)
end
return 'http://media.oboobs.ru/' .. data.preview
end
function run(msg, matches)
local url = nil
if matches[1] == "^!boobs" then
url = getRandomBoobs()
end
local boobs = getBoobs()
if matches[1] == "!buts" then
url = getRandomButts()
end
if boobs ~= nil then
file = download_to_file(boobs)
send_photo(get_receiver(msg), file, ok_cb, false)
else
return 'Error getting boobs for you, please try again later.'
end
if url ~= nil then
local receiver = get_receiver(msg)
send_photo_from_url(receiver, url)
else
return 'Error getting boobs for you, please try again later.'
end
end
return {
description = "Gets a random boobs pic",
usage = "!boobs",
patterns = {
"^!boobs$"
},
run = run
}
description = "Gets a random boobs pic",
usage = "!boobs",
patterns = {
"^!boobs",
"^!buts"
},
run = run
}
end