Merge branch 'master' of http://github.com/topkecleon/otouto
This commit is contained in:
commit
7d23fc240e
@ -7,6 +7,8 @@ return {
|
||||
biblia_api_key = '',
|
||||
thecatapi_key = '',
|
||||
nasa_api_key = '',
|
||||
simsimi_key = '',
|
||||
simsimi_trial = true,
|
||||
time_offset = 0,
|
||||
lang = 'en',
|
||||
antisquig = false,
|
||||
|
@ -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,12 +25,18 @@ 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
|
||||
|
||||
if input then
|
||||
url = url .. '&date=' .. URL.escape(input)
|
||||
date = date .. input
|
||||
if input:match('(%d+)%-(%d+)%-(%d+)$') then
|
||||
url = url .. '&date=' .. URL.escape(input)
|
||||
date = date .. input
|
||||
else
|
||||
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
else
|
||||
date = date .. os.date("%F")
|
||||
end
|
||||
@ -44,14 +56,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
|
||||
|
||||
|
@ -1,5 +1,11 @@
|
||||
-- Put this absolutely at the end, even after greetings.lua.
|
||||
|
||||
if not config.simsimi_key then
|
||||
print('Missing config value: simsimi_key.')
|
||||
print('chatter.lua will not be enabled.')
|
||||
return
|
||||
end
|
||||
|
||||
local triggers = {
|
||||
'',
|
||||
'^' .. bot.first_name .. ',',
|
||||
@ -27,8 +33,14 @@ local action = function(msg)
|
||||
local input = msg.text_lower
|
||||
input = input:gsub(bot.first_name, 'simsimi')
|
||||
input = input:gsub('@'..bot.username, 'simsimi')
|
||||
|
||||
if config.simsimi_trial then
|
||||
sandbox = 'sandbox.'
|
||||
else
|
||||
sandbox = '' -- NO Sandbox
|
||||
end
|
||||
|
||||
local url = 'http://www.simsimi.com/requestChat?lc=en&ft=1.0&req=' .. URL.escape(input)
|
||||
local url = 'http://' ..sandbox.. 'api.simsimi.com/request.p?key=' ..config.simsimi_key.. '&lc=' ..config.lang.. '&ft=1.0&text=' .. URL.escape(input)
|
||||
|
||||
local jstr, res = HTTP.request(url)
|
||||
if res ~= 200 then
|
||||
@ -37,7 +49,11 @@ local action = function(msg)
|
||||
end
|
||||
|
||||
local jdat = JSON.decode(jstr)
|
||||
local message = jdat.res.msg
|
||||
if not jdat.response then
|
||||
sendMessage(msg.chat.id, config.errors.chatter_response)
|
||||
return
|
||||
end
|
||||
local message = jdat.response
|
||||
|
||||
if message:match('^I HAVE NO RESPONSE.') then
|
||||
message = config.errors.chatter_response
|
||||
|
@ -9,6 +9,8 @@ local action = function(msg)
|
||||
end
|
||||
|
||||
local input = msg.text:input()
|
||||
input = input:gsub('—', '--')
|
||||
|
||||
if not input then
|
||||
sendReply(msg, 'Please specify a command to run.')
|
||||
return
|
||||
|
Reference in New Issue
Block a user