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/miku/plugins/webshot.lua
Akamaru 5856804891 Seeeeehr großes Update
Meiste Änderungen von Brawl345/Brawlbot-v2
Einige Pattern angepasst
Einiges übersetzt
Und noch einiges mehr
Stabilitätsverbesserungen
2016-08-01 21:07:27 +02:00

76 lines
2.2 KiB
Lua

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* _<URL>_: Fertigt Bild mit Größe 1024x768 (X) an
*]]..config.cmd_pat..[[scrot* _[T|S|E|N|M|L|X|F]_ _<URL>_: Fertigt Bild mit bestimmter Größe an (T = tiny, F = full)]]
end
webshot.command = 'scrot [T|S|E|N|M|L|X|F] <URL>'
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='(.-)'")
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
utilities.send_typing(self, 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)
if size == "F" then
utilities.send_document(self, msg.chat.id, file, nil, msg.message_id)
return
else
utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id)
end
else
utilities.send_reply(self, msg, config.errors.connection)
end
end
return webshot