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/miku/plugins/cleverbot.lua
2016-09-05 16:24:17 +02:00

45 lines
1.3 KiB
Lua

local cleverbot = {}
function cleverbot:init(config)
cleverbot.triggers = {
<<<<<<< HEAD:miku/plugins/cleverbot.lua
"^/[Cc][Bb][Oo][Tt] (.*)$",
"^[Mm][Ii][Kk][Uu][Bb][Oo][Tt], (.+)$",
"^[Mm][Ii][Kk][Uu], (.+)$"
=======
"^/cbot (.+)$",
"^[Bb]rawlbot, (.+)$",
"^[Bb]ot, (.+)$"
>>>>>>> upstream/master:otouto/plugins/cleverbot.lua
}
cleverbot.url = config.chatter.cleverbot_api
end
cleverbot.command = 'cbot <Text>'
function cleverbot:action(msg, config, matches)
utilities.send_typing(msg.chat.id, 'typing')
local text = matches[1]
local query, code = https.request(cleverbot.url..URL.escape(text))
if code ~= 200 then
utilities.send_reply(msg, 'Ich möchte jetzt nicht reden...')
return
end
local data = json.decode(query)
if not data.clever then
utilities.send_reply(msg, 'Ich möchte jetzt nicht reden...')
return
end
local answer = string.gsub(data.clever, "&Auml;", "Ä")
local answer = string.gsub(answer, "&auml;", "ä")
local answer = string.gsub(answer, "&Ouml;", "Ö")
local answer = string.gsub(answer, "&ouml;", "ö")
local answer = string.gsub(answer, "&Uuml;", "Ü")
local answer = string.gsub(answer, "&uuml;", "ü")
local answer = string.gsub(answer, "&szlig;", "ß")
utilities.send_reply(msg, answer)
end
return cleverbot