From bda76a729d3bf5279367b6afcd7ab365dccc898d Mon Sep 17 00:00:00 2001 From: Tiago Danin Date: Sat, 5 Dec 2015 11:23:32 -0300 Subject: [PATCH] Fix Google Search Images --- plugins/gImages.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/gImages.lua b/plugins/gImages.lua index 1ce9c70..4fd9c08 100755 --- a/plugins/gImages.lua +++ b/plugins/gImages.lua @@ -20,10 +20,12 @@ local action = function(msg) 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 - url = url .. '&safe=active' + url = url .. '&safe=high' end url = url .. '&q=' .. URL.escape(input) @@ -35,13 +37,13 @@ local action = function(msg) end local jdat = JSON.decode(jstr) - if #jdat.responseData.results < 1 then + if jdat.searchInformation.totalResults == '0' then sendReply(msg, config.errors.results) return end - local i = math.random(#jdat.responseData.results) - local result = jdat.responseData.results[i].url + local i = math.random(jdat.queries.request[1].count) + local result = jdat.items[i].link if string.match(msg.text, '^/i[mage]*nsfw') then sendReply(msg, result)