Merge branch 'dev'

This commit is contained in:
Andreas Bielawski 2017-02-15 14:50:13 +01:00
commit e132de6191
2 changed files with 8 additions and 20 deletions

View File

@ -59,12 +59,5 @@ Sende /hilfe, um zu starten
max_duration = 526000, max_duration = 526000,
max_reminders_group = 10, max_reminders_group = 10,
max_reminders_private = 50 max_reminders_private = 50
},
cleverbot = {
cleverbot_api = 'https://brawlbot.tk/apis/chatter-bot-api/cleverbot.php?text=',
connection = 'Ich möchte jetzt nicht reden.',
response = 'Ich weiß nicht, wie ich darauf reagieren soll.'
} }
} }

View File

@ -6,34 +6,29 @@ function cleverbot:init(config)
"^[Bb]rawlbot, (.+)$", "^[Bb]rawlbot, (.+)$",
"^[Bb]ot, (.+)$" "^[Bb]ot, (.+)$"
} }
cleverbot.url = config.cleverbot.cleverbot_api
end end
cleverbot.command = 'cbot <Text>' cleverbot.command = 'cbot <Text>'
local BASE_URL = 'https://www.cleverbot.com/getreply'
local apikey = cred_data.cleverbot_apikey -- get your key here: https://www.cleverbot.com/api/
function cleverbot:action(msg, config, matches) function cleverbot:action(msg, config, matches)
utilities.send_typing(msg.chat.id, 'typing') utilities.send_typing(msg.chat.id, 'typing')
local text = matches[1] local text = matches[1]
local query, code = https.request(cleverbot.url..URL.escape(text)) local query, code = https.request(BASE_URL..'?key='..apikey..'&input='..URL.escape(text))
if code ~= 200 then if code ~= 200 then
utilities.send_reply(msg, config.cleverbot.connection) utilities.send_reply(msg, config.errors.connection)
return return
end end
local data = json.decode(query) local data = json.decode(query)
if not data.clever then if not data.output then
utilities.send_reply(msg, config.cleverbot.response) utilities.send_reply(msg, 'Ich möchte jetzt nicht reden...')
return return
end end
local answer = string.gsub(data.clever, "&Auml;", "Ä") utilities.send_reply(msg, data.output)
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 end
return cleverbot return cleverbot