Fixed bugs in wikipedia.lua, improved chatter.lua.

This commit is contained in:
topkecleon 2015-11-26 05:34:16 -05:00
parent 9cbe4dd3c8
commit 61b9140eca
2 changed files with 17 additions and 7 deletions

View File

@ -1,20 +1,25 @@
-- Put this absolutely at the end, even after greetings.lua.
local triggers = {
''
'',
'^' .. bot.first_name .. ','
}
local action = function(msg)
if not msg.reply_to_message then
return true
elseif msg.reply_to_message and msg.reply_to_message.from.id ~= bot.id then
-- This is awkward, but if you have a better way, please share.
if msg.text_lower:match('^' .. bot.first_name .. ',') then
elseif msg.reply_to_message and msg.reply_to_message.from.id == bot.id then
elseif msg.from.id == msg.chat.id then
else
return true
end
sendChatAction(msg.chat.id, 'typing')
local url = 'http://www.simsimi.com/requestChat?lc=en&ft=1.0&req=' .. URL.escape(msg.text_lower)
local input = msg.text_lower:gsub(bot.first_name, 'simsimi')
local url = 'http://www.simsimi.com/requestChat?lc=en&ft=1.0&req=' .. URL.escape(input)
local jstr, res = HTTP.request(url)
if res ~= 200 then

View File

@ -25,11 +25,16 @@ local action = function(msg)
local jstr, res = HTTPS.request(gurl .. URL.escape(input))
if res ~= 200 then
sendReply(msg, config.error.connection)
sendReply(msg, config.errors.connection)
return
end
local jdat = JSON.decode(jstr)
if not jdat.responseData.results[1] then
sendReply(msg, config.errors.results)
return
end
local url = jdat.responseData.results[1].url
local title = jdat.responseData.results[1].titleNoFormatting:gsub(' %- Wikipedia, the free encyclopedia', '')
@ -45,7 +50,7 @@ local action = function(msg)
break -- Seriously, there's probably a way more elegant solution.
end
if not text then
sendReply(msg, config.error.connection)
sendReply(msg, config.errors.results)
return
end