From 3ce0a0965d121448713299d8d253da5727208f91 Mon Sep 17 00:00:00 2001 From: "Heitor P. de Bittencourt" Date: Fri, 15 Jan 2016 19:35:09 +0200 Subject: [PATCH 1/5] Improved apod.lua --- plugins/apod.lua | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/plugins/apod.lua b/plugins/apod.lua index ec412be..f8affac 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,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 From bf0a4da83cb0d73609199d547543e45a83cc775e Mon Sep 17 00:00:00 2001 From: Tiago Danin Date: Thu, 21 Jan 2016 16:57:06 -0300 Subject: [PATCH 2/5] New API for Simsimi --- config.lua | 2 ++ plugins/chatter.lua | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) 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/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 From 75daa0742555def4a05e37c4b79c95514c315b1a Mon Sep 17 00:00:00 2001 From: Tiago Danin Date: Fri, 22 Jan 2016 19:20:08 -0300 Subject: [PATCH 3/5] Solved "Connection error." --- plugins/apod.lua | 9 +++++++-- plugins/reddit.lua | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/plugins/apod.lua b/plugins/apod.lua index ec412be..1ed5d17 100755 --- a/plugins/apod.lua +++ b/plugins/apod.lua @@ -23,8 +23,13 @@ local action = function(msg) 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 diff --git a/plugins/reddit.lua b/plugins/reddit.lua index fefea3a..6051f55 100755 --- a/plugins/reddit.lua +++ b/plugins/reddit.lua @@ -26,10 +26,10 @@ local action = function(msg) local source if input then if input:match('^r/.') then - url = 'http://www.reddit.com/' .. input .. '/.json?limit=' .. limit + url = 'http://www.reddit.com/' .. URL.escape(input) .. '/.json?limit=' .. limit source = '*/r/' .. input:match('^r/(.+)') .. '*\n' else - url = 'http://www.reddit.com/search.json?q=' .. input .. '&limit=' .. limit + url = 'http://www.reddit.com/search.json?q=' .. URL.escape(input) .. '&limit=' .. limit source = '*reddit results for* _' .. input .. '_ *:*\n' end else From 1fd25814aaa4149c0b12ba64f60d09f2c9069aad Mon Sep 17 00:00:00 2001 From: Tiago Danin Date: Fri, 5 Feb 2016 20:29:29 -0300 Subject: [PATCH 4/5] FIX Shell --- plugins/shell.lua | 2 ++ 1 file changed, 2 insertions(+) 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 From f65e145bc3204b7eca5d74a07d62ed3bd3262896 Mon Sep 17 00:00:00 2001 From: topkecleon Date: Sun, 14 Feb 2016 03:40:54 -0500 Subject: [PATCH 5/5] Fixed irresponsiveness in gSearch.lua when dealing with CJK characters. Resolved issue #34. Result title truncation was screwing with CJK encoding. Will rely on Telegram's built-in link truncation for now. --- plugins/gSearch.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/gSearch.lua b/plugins/gSearch.lua index a20a14b..23f9c2b 100755 --- a/plugins/gSearch.lua +++ b/plugins/gSearch.lua @@ -57,9 +57,11 @@ local action = function(msg) local output = '*Google results for* _' .. input .. '_ *:*\n' for i,v in ipairs(jdat.responseData.results) do local title = jdat.responseData.results[i].titleNoFormatting:gsub('%[.+%]', ''):gsub('&', '&') +--[[ if title:len() > 48 then title = title:sub(1, 45) .. '...' end +]]-- local url = jdat.responseData.results[i].unescapedUrl if url:find('%)') then output = output .. '• ' .. title .. '\n' .. url:gsub('_', '\\_') .. '\n'