diff --git a/otouto/plugins/cats.lua b/otouto/plugins/cats.lua
index 99f6049..dc20fcb 100644
--- a/otouto/plugins/cats.lua
+++ b/otouto/plugins/cats.lua
@@ -4,35 +4,34 @@ local HTTP = require('socket.http')
local utilities = require('otouto.utilities')
function cats:init(config)
- if not config.thecatapi_key then
- print('Missing config value: thecatapi_key.')
+ if not cred_data.cat_apikey then
+ print('Missing config value: cat_apikey.')
print('cats.lua will be enabled, but there are more features with a key.')
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
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)
-
- local url = 'http://thecatapi.com/api/images/get?format=html&type=jpg'
- if config.thecatapi_key then
- url = url .. '&api_key=' .. config.thecatapi_key
- end
-
- local str, res = HTTP.request(url)
- if res ~= 200 then
- utilities.send_reply(self, msg, config.errors.connection)
- return
- end
-
- str = str:match('')
- local output = '[Cat!]('..str..')'
-
- utilities.send_message(self, msg.chat.id, output, false, nil, true)
-
+ if matches[1] == 'gif' then
+ local url = 'http://thecatapi.com/api/images/get?type=gif&apikey='..apikey
+ local file = download_to_file(url)
+ utilities.send_document(self, msg.chat.id, file, nil, msg.message_id)
+ else
+ local url = 'http://thecatapi.com/api/images/get?type=jpg,png&apikey='..apikey
+ local file = download_to_file(url)
+ utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id)
+ end
end
return cats
diff --git a/otouto/plugins/cleverbot.lua b/otouto/plugins/cleverbot.lua
new file mode 100644
index 0000000..5557b4c
--- /dev/null
+++ b/otouto/plugins/cleverbot.lua
@@ -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* __*: Befragt den Cleverbot]]
+end
+
+cleverbot.command = 'cbot '
+
+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