From f89c3fae5e1ab76bccf9c59ad10c338d16befbcc Mon Sep 17 00:00:00 2001 From: topkecleon Date: Sat, 5 Dec 2015 10:03:43 -0500 Subject: [PATCH] Added Google API/CSE key vars to config, minor changes to gImages.lua --- config.lua | 2 ++ plugins/gImages.lua | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/config.lua b/config.lua index 221a7d8..7172973 100755 --- a/config.lua +++ b/config.lua @@ -1,5 +1,7 @@ return { bot_api_key = '', + google_api_key = '', + google_cse_key = '', lastfm_api_key = '', owm_api_key = '', biblia_api_key = '', diff --git a/plugins/gImages.lua b/plugins/gImages.lua index 4fd9c08..4ae0eed 100755 --- a/plugins/gImages.lua +++ b/plugins/gImages.lua @@ -1,3 +1,16 @@ + -- You need a Google API key and a Google Custom Search Engine set up to use this, in config.google_api_key and config.google_cse_key, respectively. + -- You must also sign up for the CSE in the Google Developer Concsole, and enable image results. + +if not config.google_api_key then + print('Missing config value: google_api_key.') + print('gImages.lua will not be enabled.') + return +elseif not config.google_cse_key then + print('Missing config value: google_cse_key.') + print('gImages.lua will not be enabled.') + return +end + local doc = [[ /image Returns a randomized top result from Google Images. Safe search is enabled by default; use "/insfw" to disable it. NSFW results will not display an image preview. @@ -20,9 +33,7 @@ local action = function(msg) end end - 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 + local url = 'https://www.googleapis.com/customsearch/v1?&searchType=image&imgSize=xlarge&alt=json&num=8&start=1&key=' .. config.google_api_key .. '&cx=' .. config.google_cse_key if not string.match(msg.text, '^/i[mage]*nsfw') then url = url .. '&safe=high'