diff --git a/config.lua b/config.lua index 13f0004..14d116c 100755 --- a/config.lua +++ b/config.lua @@ -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, diff --git a/plugins/apod.lua b/plugins/apod.lua index ec412be..5b2230e 100755 --- a/plugins/apod.lua +++ b/plugins/apod.lua @@ -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 diff --git a/plugins/chatter.lua b/plugins/chatter.lua index 08460fd..6f532d9 100755 --- a/plugins/chatter.lua +++ b/plugins/chatter.lua @@ -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 diff --git a/plugins/shell.lua b/plugins/shell.lua index 411f09b..5c218aa 100644 --- a/plugins/shell.lua +++ b/plugins/shell.lua @@ -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