Improved apod.lua
This commit is contained in:
parent
f2b243a47c
commit
3ce0a0965d
@ -3,11 +3,17 @@ 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.
|
||||
/apodhd [query]
|
||||
Returns the image in HD, if available.
|
||||
/apodtext [query]
|
||||
Returns the explanation of the APOD.
|
||||
Source: nasa.gov
|
||||
```]]
|
||||
|
||||
local triggers = {
|
||||
'^/apod[@'..bot.username..']*'
|
||||
'^/apod[@'..bot.username..']*',
|
||||
'^/apodhd[@'..bot.username..']*',
|
||||
'^/apodtext[@'..bot.username..']*'
|
||||
}
|
||||
|
||||
local action = function(msg)
|
||||
@ -19,6 +25,7 @@ local action = function(msg)
|
||||
local input = msg.text:input()
|
||||
local caption = ''
|
||||
local date = '*'
|
||||
local disable_page_preview = false
|
||||
|
||||
local url = 'https://api.nasa.gov/planetary/apod?api_key=' .. config.nasa_api_key
|
||||
|
||||
@ -44,14 +51,24 @@ local action = function(msg)
|
||||
return
|
||||
end
|
||||
|
||||
local img_url = jdat.hdurl or jdat.url
|
||||
output = date .. '[' .. jdat.title .. '](' .. img_url .. ')\n'
|
||||
local img_url = jdat.url
|
||||
|
||||
if jdat.copyright then
|
||||
output = output .. 'Copyright: ' .. jdat.copyright
|
||||
if string.match(msg.text, '^/apodhd*') then
|
||||
img_url = jdat.hdurl or jdat.url
|
||||
end
|
||||
|
||||
sendMessage(msg.chat.id, output, false, nil, true)
|
||||
output = date .. '[' .. jdat.title .. '](' .. img_url .. ')'
|
||||
|
||||
if string.match(msg.text, '^/apodtext*') then
|
||||
output = output .. '\n' .. jdat.explanation
|
||||
disable_page_preview = true
|
||||
end
|
||||
|
||||
if jdat.copyright then
|
||||
output = output .. '\nCopyright: ' .. jdat.copyright
|
||||
end
|
||||
|
||||
sendMessage(msg.chat.id, output, disable_page_preview, nil, true)
|
||||
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user