From 4f78323db7eaa3ca60738e8396a740234c1aa3cf Mon Sep 17 00:00:00 2001 From: topkecleon Date: Thu, 14 Jan 2016 14:56:30 -0500 Subject: [PATCH] Changes to apod.lua: - Now uses demo key if key is not configured. - Removed newlines in doc. - Removed some unused code. --- config.lua | 2 +- plugins/apod.lua | 39 +++++++++++++++------------------------ 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/config.lua b/config.lua index 93e3886..e706cba 100755 --- a/config.lua +++ b/config.lua @@ -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, diff --git a/plugins/apod.lua b/plugins/apod.lua index 49c69f0..0319ca9 100755 --- a/plugins/apod.lua +++ b/plugins/apod.lua @@ -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 {