local konachan = {}
function konachan:init(config)
konachan.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('kc', true):t('konachan', true).table
konachan.doc = [[*
]]..config.cmd_pat..[[kc* _<Tags>_: Sucht auf Konachan mit diesen Tags]]
end
konachan.command = 'kc <Tags>'
function konachan:get_kc(tag)
local url = 'http://konachan.net/post.json?tags='..tag..'%20-rating:explicit'
local res, code = http.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 konachan:action(msg, config)
local input = utilities.input_from_msg(msg)
if not input then
utilities.send_reply(msg, konachan.doc, true)
return
local tag = string.gsub(input, " ", '+' )
local url = konachan:get_kc(tag)
if not url then
utilities.send_reply(msg, config.errors.results)
utilities.send_typing(msg.chat.id, 'upload_photo')
local file = download_to_file(url)
utilities.send_photo(msg.chat.id, file, nil, msg.message_id)
utilities.send_reply(msg, url)
return konachan