ibSearch.lua: Beschränke max. größe

This commit is contained in:
Akamaru 2016-11-13 23:02:31 +01:00
parent 79e7446eb9
commit 0334188aab

View File

@ -25,10 +25,10 @@ function ibSearch:get_ibSearch_sfw(tag)
local i = math.random(#data) local i = math.random(#data)
local url = 'https://'..data[i].server..'.ibsear.ch/'..data[i].path local url = 'https://'..data[i].server..'.ibsear.ch/'..data[i].path
local resolution = data[i].width..'x'..data[i].height..'px' local resolution = data[i].width..'x'..data[i].height..'px'
local size = ' '..math.ceil(data[i].size/1000)..'kb' local size = ' '..math.ceil(data[i].size/1000)
local source_url = '\nhttps://ibsear.ch/images/'..data[i].id local source_url = '\nhttps://ibsear.ch/images/'..data[i].id
local text = resolution..size..source_url local text = resolution..size..'kb'..source_url
return url, text return url, size, text
end end
function ibSearch:get_ibSearch_nsfw(tag) function ibSearch:get_ibSearch_nsfw(tag)
local url = 'https://ibsearch.xxx/api/v1/images.json?q='..tag..'&limit='..limit..'&shuffle=20' local url = 'https://ibsearch.xxx/api/v1/images.json?q='..tag..'&limit='..limit..'&shuffle=20'
@ -40,10 +40,10 @@ function ibSearch:get_ibSearch_nsfw(tag)
local i = math.random(#data) local i = math.random(#data)
local url = 'https://'..data[i].server..'.ibsearch.xxx/'..data[i].path local url = 'https://'..data[i].server..'.ibsearch.xxx/'..data[i].path
local resolution = data[i].width..'x'..data[i].height..'px' local resolution = data[i].width..'x'..data[i].height..'px'
local size = ' '..math.ceil(data[i].size/1000)..'kb' local size = ' '..math.ceil(data[i].size/1000)
local source_url = '\nhttps://ibsearch.xxx/images/'..data[i].id local source_url = '\nhttps://ibsearch.xxx/images/'..data[i].id
local text = resolution..size..source_url local text = resolution..size..'kb'..source_url
return url, text return url, size, text
end end
function ibSearch:action(msg, config, matches) function ibSearch:action(msg, config, matches)
@ -51,21 +51,36 @@ function ibSearch:action(msg, config, matches)
local tag = string.gsub(tag, ":", '%%3A') local tag = string.gsub(tag, ":", '%%3A')
local tag = string.gsub(tag, "+", '%%20') local tag = string.gsub(tag, "+", '%%20')
if matches[1] == 'ibsearch' then if matches[1] == 'ibsearch' then
url, id = ibSearch:get_ibSearch_sfw(tag) url, size, text = ibSearch:get_ibSearch_sfw(tag)
elseif matches[1] == 'ibnsfw' then elseif matches[1] == 'ibnsfw' then
url, id = ibSearch:get_ibSearch_nsfw(tag) url, size, text = ibSearch:get_ibSearch_nsfw(tag)
end
print('URL: '..url)
-- don't send GIFs when they're bigger than 20 MB
-- don't send photos when they're bigger than 5 MB
if string.ends(url, ".gif") then
if tonumber(size) > 19900 then
utilities.send_reply(msg, 'Sorry, die GIF ist zu groß.\n'..text)
return
end
else
if tonumber(size) > 4900 then
utilities.send_reply(msg, 'Sorry, das Bild ist zu groß.\n'..text)
return
end
end end
if not url then if not url then
utilities.send_reply(msg, 'Nobody here but us chickens!') utilities.send_reply(msg, 'Nobody here but us chickens!')
return return
end end
utilities.send_typing(msg.chat.id, 'upload_photo') utilities.send_typing(msg.chat.id, 'upload_photo')
local file = download_to_file(url)
if string.ends(url, ".gif") then if string.ends(url, ".gif") then
utilities.send_document(msg.chat.id, file, id, msg.message_id) utilities.send_document(msg.chat.id, url, text, msg.message_id)
else else
utilities.send_photo(msg.chat.id, file, id, msg.message_id) utilities.send_photo(msg.chat.id, url, text, msg.message_id)
end end
end end