2016-07-17 13:22:27 +02:00
|
|
|
local cleverbot = {}
|
|
|
|
|
|
|
|
function cleverbot:init(config)
|
|
|
|
cleverbot.triggers = {
|
2016-08-15 23:14:28 +02:00
|
|
|
"^/[Cc][Bb][Oo][Tt] (.*)$",
|
|
|
|
"^[Mm][Ii][Kk][Uu][Bb][Oo][Tt], (.+)$",
|
2016-07-17 13:22:27 +02:00
|
|
|
}
|
2016-08-15 23:14:28 +02:00
|
|
|
cleverbot.url = config.chatter.cleverbot_api
|
2016-07-17 13:22:27 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
cleverbot.command = 'cbot <Text>'
|
|
|
|
|
2016-08-15 23:14:28 +02:00
|
|
|
function cleverbot:action(msg, config, matches)
|
|
|
|
utilities.send_typing(self, 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(self, msg, 'Ich möchte jetzt nicht reden...')
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local data = json.decode(query)
|
|
|
|
if not data.clever then
|
|
|
|
utilities.send_reply(self, msg, 'Ich möchte jetzt nicht reden...')
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local answer = string.gsub(data.clever, "Ä", "Ä")
|
2016-07-17 13:22:27 +02:00
|
|
|
local answer = string.gsub(answer, "ä", "ä")
|
|
|
|
local answer = string.gsub(answer, "Ö", "Ö")
|
|
|
|
local answer = string.gsub(answer, "ö", "ö")
|
|
|
|
local answer = string.gsub(answer, "Ü", "Ü")
|
|
|
|
local answer = string.gsub(answer, "ü", "ü")
|
|
|
|
local answer = string.gsub(answer, "ß", "ß")
|
|
|
|
utilities.send_reply(self, msg, answer)
|
|
|
|
end
|
|
|
|
|
2016-08-15 23:14:28 +02:00
|
|
|
return cleverbot
|