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/otouto/plugins/cats.lua

38 lines
1.1 KiB
Lua
Raw Normal View History

local cats = {}
local HTTP = require('socket.http')
2016-06-07 06:31:34 +02:00
local utilities = require('otouto.utilities')
2016-05-27 02:26:30 +02:00
function cats:init(config)
2016-06-17 16:42:54 +02:00
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
2016-04-12 05:55:46 +02:00
2016-06-17 16:42:54 +02:00
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 [gif]'
2016-06-17 16:42:54 +02:00
local apikey = cred_data.cat_apikey or "" -- apply for one here: http://thecatapi.com/api-key-registration.html
2016-05-27 02:26:30 +02:00
function cats:action(msg, config)
2016-06-17 16:42:54 +02:00
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