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-08-26 18:17:45 +02:00
|
|
|
"^[Mm][Ii][Kk][Uu], (.+)$"
|
2016-07-17 13:22:27 +02:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
cleverbot.command = 'cbot <Text>'
|
|
|
|
|
2017-02-15 16:49:23 +01:00
|
|
|
local BASE_URL = 'https://www.cleverbot.com/getreply'
|
|
|
|
local apikey = cred_data.cleverbot_apikey -- get your key here: https://www.cleverbot.com/api/
|
|
|
|
|
2016-08-15 23:14:28 +02:00
|
|
|
function cleverbot:action(msg, config, matches)
|
2016-08-24 15:38:29 +02:00
|
|
|
utilities.send_typing(msg.chat.id, 'typing')
|
2016-08-15 23:14:28 +02:00
|
|
|
local text = matches[1]
|
2017-02-15 16:49:23 +01:00
|
|
|
local query, code = https.request(BASE_URL..'?key='..apikey..'&input='..URL.escape(text))
|
2016-08-15 23:14:28 +02:00
|
|
|
if code ~= 200 then
|
2017-02-15 16:49:23 +01:00
|
|
|
utilities.send_reply(msg, config.errors.connection)
|
2016-08-15 23:14:28 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local data = json.decode(query)
|
2017-02-15 16:49:23 +01:00
|
|
|
if not data.output then
|
|
|
|
utilities.send_reply(msg, 'Ich möchte jetzt nicht reden...')
|
2016-08-15 23:14:28 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2017-02-15 16:49:23 +01:00
|
|
|
utilities.send_reply(msg, data.output)
|
2016-07-17 13:22:27 +02:00
|
|
|
end
|
|
|
|
|
2016-08-15 23:14:28 +02:00
|
|
|
return cleverbot
|