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/miku/plugins/cleverbot.lua
Akamaru 41cb630710 Weitere Anpassungen
Patterns angepasst
Ungenutzte Plugins entfernt
Kleine Änderungen & Fixes
Stabilitätsverbesserungen
2016-07-18 18:37:29 +02:00

36 lines
1.1 KiB
Lua

local cleverbot = {}
local https = require('ssl.https')
local URL = require('socket.url')
local utilities = require('miku.utilities')
local json = require('dkjson')
function cleverbot:init(config)
cleverbot.triggers = {
"^/[Cc][Bb][Oo][Tt] (.*)$"
}
cleverbot.doc = [[*
]]..config.cmd_pat..[[cbot* _<Text>_*: Befragt den Cleverbot]]
end
cleverbot.command = 'cbot <Text>'
function cleverbot:action(msg, config)
local text = msg.text
local url = "https://brawlbot.tk/apis/chatter-bot-api/cleverbot.php?text="..URL.escape(text)
local query = https.request(url)
if query == nil then utilities.send_reply(self, msg, 'Ein Fehler ist aufgetreten :(') return end
local decode = json.decode(query)
local answer = string.gsub(decode.clever, "&Auml;", "Ä")
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(self, msg, answer)
end
return cleverbot