diff --git a/plugins/chatter.lua b/plugins/chatter.lua index 904e70f..d0464c0 100755 --- a/plugins/chatter.lua +++ b/plugins/chatter.lua @@ -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 diff --git a/plugins/wikipedia.lua b/plugins/wikipedia.lua index 86063f9..35463a4 100755 --- a/plugins/wikipedia.lua +++ b/plugins/wikipedia.lua @@ -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