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/otouto/plugins/cleverbot.lua

39 lines
1.1 KiB
Lua
Raw Normal View History

2016-06-17 16:42:54 +02:00
local cleverbot = {}
function cleverbot:init(config)
cleverbot.triggers = {
"^/cbot (.+)$",
"^[Bb]rawlbot, (.+)$",
2016-09-04 15:41:51 +02:00
"^[Bb]ot, (.+)$"
2016-06-17 16:42:54 +02:00
}
cleverbot.url = config.cleverbot.cleverbot_api
2016-06-17 16:42:54 +02:00
end
cleverbot.command = 'cbot <Text>'
2016-08-14 16:30:06 +02:00
function cleverbot:action(msg, config, matches)
utilities.send_typing(msg.chat.id, 'typing')
2016-08-14 16:30:06 +02:00
local text = matches[1]
local query, code = https.request(cleverbot.url..URL.escape(text))
if code ~= 200 then
utilities.send_reply(msg, config.cleverbot.connection)
2016-08-14 16:30:06 +02:00
return
end
local data = json.decode(query)
if not data.clever then
utilities.send_reply(msg, config.cleverbot.response)
2016-08-14 16:30:06 +02:00
return
end
local answer = string.gsub(data.clever, "&Auml;", "Ä")
2016-06-17 16:42:54 +02:00
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)
2016-06-17 16:42:54 +02:00
end
2016-08-14 16:30:06 +02:00
return cleverbot