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