Fixed bugs in wikipedia.lua, improved chatter.lua.
This commit is contained in:
parent
9cbe4dd3c8
commit
61b9140eca
@ -1,20 +1,25 @@
|
|||||||
-- Put this absolutely at the end, even after greetings.lua.
|
-- Put this absolutely at the end, even after greetings.lua.
|
||||||
|
|
||||||
local triggers = {
|
local triggers = {
|
||||||
''
|
'',
|
||||||
|
'^' .. bot.first_name .. ','
|
||||||
}
|
}
|
||||||
|
|
||||||
local action = function(msg)
|
local action = function(msg)
|
||||||
|
|
||||||
if not msg.reply_to_message then
|
-- This is awkward, but if you have a better way, please share.
|
||||||
return true
|
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.reply_to_message and msg.reply_to_message.from.id == bot.id then
|
||||||
|
elseif msg.from.id == msg.chat.id then
|
||||||
|
else
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
sendChatAction(msg.chat.id, 'typing')
|
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)
|
local jstr, res = HTTP.request(url)
|
||||||
if res ~= 200 then
|
if res ~= 200 then
|
||||||
|
@ -25,11 +25,16 @@ local action = function(msg)
|
|||||||
|
|
||||||
local jstr, res = HTTPS.request(gurl .. URL.escape(input))
|
local jstr, res = HTTPS.request(gurl .. URL.escape(input))
|
||||||
if res ~= 200 then
|
if res ~= 200 then
|
||||||
sendReply(msg, config.error.connection)
|
sendReply(msg, config.errors.connection)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local jdat = JSON.decode(jstr)
|
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 url = jdat.responseData.results[1].url
|
||||||
local title = jdat.responseData.results[1].titleNoFormatting:gsub(' %- Wikipedia, the free encyclopedia', '')
|
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.
|
break -- Seriously, there's probably a way more elegant solution.
|
||||||
end
|
end
|
||||||
if not text then
|
if not text then
|
||||||
sendReply(msg, config.error.connection)
|
sendReply(msg, config.errors.results)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user