Portiere Cats- und Cleverbot-Plugins
This commit is contained in:
parent
515f994ae1
commit
bbeb1883c3
@ -4,35 +4,34 @@ local HTTP = require('socket.http')
|
|||||||
local utilities = require('otouto.utilities')
|
local utilities = require('otouto.utilities')
|
||||||
|
|
||||||
function cats:init(config)
|
function cats:init(config)
|
||||||
if not config.thecatapi_key then
|
if not cred_data.cat_apikey then
|
||||||
print('Missing config value: thecatapi_key.')
|
print('Missing config value: cat_apikey.')
|
||||||
print('cats.lua will be enabled, but there are more features with a key.')
|
print('cats.lua will be enabled, but there are more features with a key.')
|
||||||
end
|
end
|
||||||
|
|
||||||
cats.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('cat').table
|
cats.triggers = {
|
||||||
|
"^/cat$",
|
||||||
|
"^/cat (gif)$"
|
||||||
|
}
|
||||||
|
|
||||||
|
cats.doc = [[*
|
||||||
|
]]..config.cmd_pat..[[cat*: Postet eine zufällige Katze
|
||||||
|
*]]..config.cmd_pat..[[cat* _gif_: Postet eine zufällige, animierte Katze]]
|
||||||
end
|
end
|
||||||
|
|
||||||
cats.command = 'cat'
|
cats.command = 'cat'
|
||||||
cats.doc = '`Returns a cat!`'
|
local apikey = cred_data.cat_apikey or "" -- apply for one here: http://thecatapi.com/api-key-registration.html
|
||||||
|
|
||||||
function cats:action(msg, config)
|
function cats:action(msg, config)
|
||||||
|
if matches[1] == 'gif' then
|
||||||
local url = 'http://thecatapi.com/api/images/get?format=html&type=jpg'
|
local url = 'http://thecatapi.com/api/images/get?type=gif&apikey='..apikey
|
||||||
if config.thecatapi_key then
|
local file = download_to_file(url)
|
||||||
url = url .. '&api_key=' .. config.thecatapi_key
|
utilities.send_document(self, msg.chat.id, file, nil, msg.message_id)
|
||||||
end
|
else
|
||||||
|
local url = 'http://thecatapi.com/api/images/get?type=jpg,png&apikey='..apikey
|
||||||
local str, res = HTTP.request(url)
|
local file = download_to_file(url)
|
||||||
if res ~= 200 then
|
utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id)
|
||||||
utilities.send_reply(self, msg, config.errors.connection)
|
end
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
str = str:match('<img src="(.-)">')
|
|
||||||
local output = '[Cat!]('..str..')'
|
|
||||||
|
|
||||||
utilities.send_message(self, msg.chat.id, output, false, nil, true)
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return cats
|
return cats
|
||||||
|
35
otouto/plugins/cleverbot.lua
Normal file
35
otouto/plugins/cleverbot.lua
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
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
|
Reference in New Issue
Block a user