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

34 lines
836 B
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
}
end
cleverbot.command = 'cbot <Text>'
2017-02-15 14:48:04 +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-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]
2017-02-15 14:48:04 +01:00
local query, code = https.request(BASE_URL..'?key='..apikey..'&input='..URL.escape(text))
2016-08-14 16:30:06 +02:00
if code ~= 200 then
2017-02-15 14:48:04 +01:00
utilities.send_reply(msg, config.errors.connection)
2016-08-14 16:30:06 +02:00
return
end
local data = json.decode(query)
2017-02-15 14:48:04 +01:00
if not data.output then
utilities.send_reply(msg, 'Ich möchte jetzt nicht reden...')
2016-08-14 16:30:06 +02:00
return
end
2017-02-15 14:48:04 +01:00
utilities.send_reply(msg, data.output)
2016-06-17 16:42:54 +02:00
end
2016-08-14 16:30:06 +02:00
return cleverbot