diff --git a/miku/plugins/tumblr.lua b/miku/plugins/tumblr.lua index 8eb6d21..cb0658e 100644 --- a/miku/plugins/tumblr.lua +++ b/miku/plugins/tumblr.lua @@ -48,17 +48,16 @@ function tumblr:get_tumblr_info(blog, post, msg) -- General blog info, present on every type local blog_name = data.blog.title local created_at = makeOurDate(data.posts[1].date) - local short_url = data.posts[1].short_url local typ = data.posts[1].type local text = ''..blog_name..' am '..created_at..':\n' -- type-specific if typ == 'text' then local title, post = tumblr:get_tumblr_text(data) - text = text..''..title..'\n'..post..'\n'..short_url + text = text..''..title..'\n'..post elseif typ == 'photo' then local caption, image_url = tumblr:get_tumblr_photo(data) - text = text..caption..'\n'..short_url + text = text..caption local file = download_to_file(image_url) utilities.send_typing(msg.chat.id, 'upload_photo') if string.ends(image_url, '.gif') then @@ -68,7 +67,7 @@ function tumblr:get_tumblr_info(blog, post, msg) end elseif typ == 'video' then local caption, video_url = tumblr:get_tumblr_video(data) - text = text..caption..'\n'..video_url..'\n'..short_url + text = text..caption..'\n'..video_url else text = text..'Konnte Format nicht bestimmen (ist: '..typ..')' end diff --git a/miku/plugins/webshot.lua b/miku/plugins/webshot.lua index 11e914f..4aabbb7 100644 --- a/miku/plugins/webshot.lua +++ b/miku/plugins/webshot.lua @@ -1,76 +1,22 @@ local webshot = {} -local base = 'https://screenshotmachine.com/' -local url = base .. 'processor.php' - function webshot:init(config) webshot.triggers = { - "^/webshot ([T|t|S|s|E|e|N|n|M|m|L|l|X|x|F|f]) ([%w-_%.%?%.:,/%+=&#!]+)$", - "^/scrot ([T|t|S|s|E|e|N|n|M|m|L|l|X|x|F|f]) ([%w-_%.%?%.:,/%+=&#!]+)$", "^/webshot ([%w-_%.%?%.:,/%+=&#!]+)$", "^/scrot ([%w-_%.%?%.:,/%+=&#!]+)$" } webshot.doc = [[* -]]..config.cmd_pat..[[scrot* __: Fertigt Bild mit Größe 1024x768 (X) an -*]]..config.cmd_pat..[[scrot* _[T|S|E|N|M|L|X|F]_ __: Fertigt Bild mit bestimmter Größe an (T = tiny, F = full)]] -end - -webshot.command = 'scrot [T|S|E|N|M|L|X|F] ' - -function webshot:get_webshot_url(param, size) - local response_body = {} - local request_constructor = { - url = url, - method = "GET", - sink = ltn12.sink.table(response_body), - headers = { - referer = base, - dnt = "1", - origin = base, - ["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.41 Safari/537.36" - }, - redirect = false - } - - local arguments = { - urlparam = param, - size = size, - cacheLimit = "0" - } - - request_constructor.url = url .. "?" .. helpers.url_encode_arguments(arguments) - - local ok, response_code, response_headers, response_status_line = https.request(request_constructor) - if not ok or response_code ~= 200 then - return nil - end - - local response = table.concat(response_body) - return string.match(response, "href='(.-)'") +]]..config.cmd_pat..[[scrot* __: Fertigt ein Screenshot mit einer Größe von 1024x768px an.]] end function webshot:action(msg, config, matches) - if not matches[2] then - webshot_url = matches[1] - size = "X" - else - webshot_url = matches[2] - size = string.upper(matches[1]) - end + local api_key = cred_data.webshot_key + local cache = '0' --cache=0 : never use cache, always download fresh screenshot || cache=1 : use image from cache only if is not older than 1 day etc... + local url = matches[1] + local img_url = 'http://api.screenshotmachine.com/?key='..api_key..'&dimension=1024x768&cacheLimit='..cache..'&url='..url + utilities.send_typing(msg.chat.id, 'upload_photo') - local find = webshot:get_webshot_url(webshot_url, size) - if find then - local imgurl = base .. find - local file = download_to_file(imgurl, 'webshot.png') - if size == "F" then - utilities.send_document(msg.chat.id, file, nil, msg.message_id) - return - else - utilities.send_photo(msg.chat.id, file, nil, msg.message_id) - end - else - utilities.send_reply(msg, config.errors.connection) - end + utilities.send_photo(msg.chat.id, img_url, nil, msg.message_id) end return webshot \ No newline at end of file