36 lines
1.1 KiB
Lua
36 lines
1.1 KiB
Lua
local cleverbot = {}
|
|
|
|
local https = require('ssl.https')
|
|
local URL = require('socket.url')
|
|
local utilities = require('otouto.utilities')
|
|
local json = require('dkjson')
|
|
|
|
function cleverbot:init(config)
|
|
cleverbot.triggers = {
|
|
"^/cbot (.*)$"
|
|
}
|
|
|
|
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, "Ä", "Ä")
|
|
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(self, msg, answer)
|
|
end
|
|
|
|
return cleverbot
|