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