local konachan_nsfw = {} function konachan_nsfw:init(config) konachan_nsfw.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('kcn', true):t('konachan_nsfw', true).table konachan_nsfw.doc = [[* ]]..config.cmd_pat..[[kcn* __: Sucht auf Konachan mit diesen Tags (NSFW)]] end konachan_nsfw.command = 'kcn ' function konachan_nsfw:get_kc(tag) local url = 'http://konachan.net/post.json?tags='..tag 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 end function konachan_nsfw:action(msg, config) local input = utilities.input_from_msg(msg) if not input then utilities.send_reply(msg, konachan_nsfw.doc, true) return end local tag = string.gsub(input, " ", '+' ) local url = konachan_nsfw:get_kc(tag) if not url then utilities.send_reply(msg, config.errors.results) return end 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) end return konachan_nsfw