Changes to apod.lua:

- Now uses demo key if key is not configured.
 - Removed newlines in doc.
 - Removed some unused code.
This commit is contained in:
topkecleon 2016-01-14 14:56:30 -05:00
parent 16b3d10762
commit 4f78323db7
2 changed files with 16 additions and 25 deletions

View File

@ -6,7 +6,7 @@ return {
owm_api_key = '',
biblia_api_key = '',
thecatapi_key = '',
nasaapi_key = '',
nasa_api_key = '',
time_offset = 0,
lang = 'en',
antisquig = false,

View File

@ -1,20 +1,9 @@
-- TODO:
-- inline bot stuff
if not config.nasaapi_key then
print('Missing config value: nasaapi_key.')
print('You can use the simple key DEMO_KEY, but it is very limited.')
print('apod.lua will not be enabled.')
return
end
local command = 'apod [query]'
local doc = [[```
/apod [query]
Returns the Astronomy Picture of the Day.
If the query is a date, in the format YYYY-MM-DD,
the APOD of that day is returned.
If the query is a date, in the format YYYY-MM-DD, the APOD of that day is returned.
Source: nasa.gov
```]]
local triggers = {
@ -23,19 +12,20 @@ local triggers = {
local action = function(msg)
local input = msg.text:input()
local caption = ''
local date = '*'
--local date_url = ''
if not config.nasa_api_key then
config.nasa_api_key = 'DEMO_KEY'
end
local url = 'https://api.nasa.gov/planetary/apod?api_key=' .. config.nasaapi_key
local input = msg.text:input()
local caption = ''
local date = '*'
local url = 'https://api.nasa.gov/planetary/apod?api_key=' .. config.nasa_api_key
if input then
url = url .. '&date=' .. URL.escape(input)
-- date_url = string.sub(date,3,4) .. string.sub(date,6,7) .. string.sub(date,9,10)
date = date .. input
else
-- date_url = os.date("%y%m%d")
date = date .. os.date("%Y-%m-%d")
end
@ -55,14 +45,15 @@ local action = function(msg)
end
--local weburl = 'http://apod.nasa.gov/apod/ap' .. date_url .. '.html'
--caption = date .. '[' .. jdat.title .. '](' .. weburl .. ')\n'
caption = date .. '[' .. jdat.title .. '](' .. jdat.url .. ')\n'
--output = date .. '[' .. jdat.title .. '](' .. weburl .. ')\n'
output = date .. '[' .. jdat.title .. '](' .. jdat.url .. ')\n'
if jdat.copyright then
caption = caption .. 'Copyright: ' .. jdat.copyright
output = output .. 'Copyright: ' .. jdat.copyright
end
sendMessage(msg.chat.id, caption, false, nil, true)
sendMessage(msg.chat.id, output, false, nil, true)
end
return {