Fix Google Search Images

This commit is contained in:
Tiago Danin 2015-12-05 11:23:32 -03:00
parent c5c3660de4
commit bda76a729d

View File

@ -20,10 +20,12 @@ local action = function(msg)
end end
end end
local url = 'https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=8' local url = 'https://www.googleapis.com/customsearch/v1?&searchType=image&imgSize=xlarge&alt=json&num=8&start=1'
url = url .. '&key=0000000' -- KEY Get https://console.developers.google.com/apis/credentials
url = url .. '&cx=ABCD:000' -- CX Get https://cse.google.com/cse
if not string.match(msg.text, '^/i[mage]*nsfw') then if not string.match(msg.text, '^/i[mage]*nsfw') then
url = url .. '&safe=active' url = url .. '&safe=high'
end end
url = url .. '&q=' .. URL.escape(input) url = url .. '&q=' .. URL.escape(input)
@ -35,13 +37,13 @@ local action = function(msg)
end end
local jdat = JSON.decode(jstr) local jdat = JSON.decode(jstr)
if #jdat.responseData.results < 1 then if jdat.searchInformation.totalResults == '0' then
sendReply(msg, config.errors.results) sendReply(msg, config.errors.results)
return return
end end
local i = math.random(#jdat.responseData.results) local i = math.random(jdat.queries.request[1].count)
local result = jdat.responseData.results[i].url local result = jdat.items[i].link
if string.match(msg.text, '^/i[mage]*nsfw') then if string.match(msg.text, '^/i[mage]*nsfw') then
sendReply(msg, result) sendReply(msg, result)