From f3865a22076453cf8c279d71e6908c09c7d596a1 Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Wed, 15 Feb 2017 14:48:04 +0100 Subject: [PATCH] Nutze neue Cleverbot-API --- config.lua.example | 7 ------- otouto/plugins/cleverbot.lua | 21 ++++++++------------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/config.lua.example b/config.lua.example index ce27687..2e69c76 100644 --- a/config.lua.example +++ b/config.lua.example @@ -59,12 +59,5 @@ Sende /hilfe, um zu starten max_duration = 526000, max_reminders_group = 10, 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.' } - } diff --git a/otouto/plugins/cleverbot.lua b/otouto/plugins/cleverbot.lua index 80bc896..276b599 100644 --- a/otouto/plugins/cleverbot.lua +++ b/otouto/plugins/cleverbot.lua @@ -6,34 +6,29 @@ function cleverbot:init(config) "^[Bb]rawlbot, (.+)$", "^[Bb]ot, (.+)$" } - cleverbot.url = config.cleverbot.cleverbot_api end cleverbot.command = 'cbot ' +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) utilities.send_typing(msg.chat.id, 'typing') 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 - utilities.send_reply(msg, config.cleverbot.connection) + utilities.send_reply(msg, config.errors.connection) return end local data = json.decode(query) - if not data.clever then - utilities.send_reply(msg, config.cleverbot.response) + if not data.output then + utilities.send_reply(msg, 'Ich möchte jetzt nicht reden...') return end - local answer = string.gsub(data.clever, "Ä", "Ä") - 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(msg, answer) + utilities.send_reply(msg, data.output) end return cleverbot \ No newline at end of file