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
topkecleon 9f760114bd otouto 3.14
All help messages and many other things moved from markdown to html.
Eventually, I'd like only things made from user input to use markdown.

cats.lua, rmspic.lua, and dilbert.lua moved to sendPhoto with URL.
xkcd.lua and apod.lua not moved to retain formatting.

Probably a lot of other stuff that I forget about. I should commit more often.
2016-10-04 10:07:15 -04:00

38 lines
971 B
Lua

local cats = {}
local HTTP = require('socket.http')
local utilities = require('otouto.utilities')
local bindings = require('otouto.bindings')
function cats:init(config)
if not 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, config.cmd_pat):t('cat').table
end
cats.command = 'cat'
cats.doc = 'Returns a cat!'
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(msg, config.errors.connection)
return
end
str = str:match('<img src="(.-)">')
bindings.sendPhoto{chat_id = msg.chat.id, photo = str}
end
return cats