Added Google API/CSE key vars to config, minor changes to gImages.lua

This commit is contained in:
topkecleon 2015-12-05 10:03:43 -05:00
parent 6cc821f7c7
commit f89c3fae5e
2 changed files with 16 additions and 3 deletions

View File

@ -1,5 +1,7 @@
return {
bot_api_key = '',
google_api_key = '',
google_cse_key = '',
lastfm_api_key = '',
owm_api_key = '',
biblia_api_key = '',

View File

@ -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 <query>
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'