local e621 = {}
function e621:init(config)
e621.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('e621', true).table
e621.doc = [[*
]]..config.cmd_pat..[[e621* _<Tags>_: Sucht auf e621 mit diesen Tags]]
end
e621.command = 'e621 <Tags>'
function e621:get_e621(tag)
local BASE_URL = 'https://e621.net'
local url = BASE_URL..'/post/index.json?tags='..tag
local res, code = https.request(url)
if code ~= 200 then return nil end
local data = json.decode(res)
if not data[1] then return nil end
local i = math.random(#data)
local link_image = data[i].file_url
return link_image
function e621:action(msg, config)
local input = utilities.input_from_msg(msg)
if not input then
utilities.send_reply(self, msg, e621.doc, true)
return
local url = e621:get_e621(input)
if not url then
utilities.send_reply(self, msg, config.errors.results)
utilities.send_typing(self, msg.chat.id, 'upload_photo')
local file = download_to_file(url)
utilities.send_photo(self, msg.chat.id, file, url, msg.message_id)
return e621