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/plugins/cats.lua
topkecleon 725261fcf7 Version 3.8
Relicense to AGPLv3, with consent of contributors.
bindings.lua completely rewritten. Shift to multipart-post.
Updated readme.
New plugins: bing.lua, channel.lua.
Removed plugins: floodcontrol.lua, librefm.lua.
luarun.lua: Will now serialize returned tables. Aliased "/return" to "/lua return".
2016-05-29 13:08:39 -04:00

39 lines
899 B
Lua
Executable File

local cats = {}
local HTTP = require('socket.http')
local utilities = require('utilities')
function cats:init()
if not self.config.thecatapi_key then
print('Missing config value: thecatapi_key.')
print('cats.lua will be enabled, but there are more features with a key.')
end
cats.triggers = utilities.triggers(self.info.username):t('cat').table
end
cats.command = 'cat'
cats.doc = '`Returns a cat!`'
function cats:action(msg)
local url = 'http://thecatapi.com/api/images/get?format=html&type=jpg'
if self.config.thecatapi_key then
url = url .. '&api_key=' .. self.config.thecatapi_key
end
local str, res = HTTP.request(url)
if res ~= 200 then
utilities.send_reply(msg, self.config.errors.connection)
return
end
str = str:match('<img src="(.-)">')
local output = '[Cat!]('..str..')'
utilities.send_message(self, msg.chat.id, output, false, nil, true)
end
return cats