This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot-2/plugins/chatter.lua

53 lines
1.1 KiB
Lua
Raw Normal View History

-- shout-out to @luksireiku for showing me this site
2015-07-05 18:14:41 +02:00
2015-07-05 04:51:12 +02:00
local PLUGIN = {}
PLUGIN.typing = true
2015-07-05 04:51:12 +02:00
PLUGIN.triggers = {
'^@' .. bot.username .. ', ',
'^' .. bot.first_name .. ', '
}
function PLUGIN.action(msg)
local input = get_input(msg.text)
2015-07-05 18:14:41 +02:00
local url = 'http://www.simsimi.com/requestChat?lc=en&ft=1.0&req=' .. URL.escape(input)
2015-07-05 04:51:12 +02:00
local jstr, res = HTTP.request(url)
if res ~= 200 then
return send_message(msg.chat.id, "I don't feel like talking right now.")
end
local jdat = JSON.decode(jstr)
if string.match(jdat.res.msg, '^I HAVE NO RESPONSE.') or not jdat then
jdat.res.msg = "I don't know what to say to that."
2015-07-05 04:51:12 +02:00
end
local message = jdat.res.msg
2015-07-08 04:24:12 +02:00
2015-07-05 18:14:41 +02:00
-- Let's clean up the response a little. Capitalization & punctuation.
2015-07-08 04:24:12 +02:00
filter = {
['%aimi?%aimi?'] = bot.first_name,
2015-07-08 04:24:12 +02:00
['^%s*(.-)%s*$'] = '%1',
['^%l'] = string.upper,
['USER'] = msg.from.first_name
2015-07-08 04:24:12 +02:00
}
for k,v in pairs(filter) do
message = string.gsub(message, k, v)
end
2015-07-05 18:14:41 +02:00
if not string.match(message, '%p$') then
message = message .. '.'
end
2015-07-08 04:24:12 +02:00
send_message(msg.chat.id, message)
2015-07-05 04:51:12 +02:00
end
return PLUGIN