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/plugins/gfycat.lua

49 lines
1.3 KiB
Lua

do
local function send_gfycat_video(name, receiver)
local BASE_URL = "https://gfycat.com"
local url = BASE_URL..'/cajax/get/'..name
local res,code = https.request(url)
if code ~= 200 then return "HTTP-FEHLER" end
local data = json:decode(res).gfyItem
local file = download_to_file(data.webmUrl)
local cb_extra = {file_path=file}
if file == nil then
send_msg(receiver, 'Fehler beim Herunterladen von '..name, ok_cb, false)
else
send_video(receiver, file, rmtmp_cb, cb_extra)
end
end
local function send_gfycat_thumb(name, receiver)
local BASE_URL = "https://thumbs.gfycat.com"
local url = BASE_URL..'/'..name..'-poster.jpg'
local file = download_to_file(url)
local cb_extra = {file_path=file}
if file == nil then
print('Fehler beim Herunterladen des Thumbnails von '..name)
else
send_photo(receiver, file, rmtmp_cb, cb_extra)
end
end
local function run(msg, matches)
local name = matches[1]
local receiver = get_receiver(msg)
send_gfycat_video(name, receiver)
if matches[2] ~= 'NSFW' then
send_gfycat_thumb(name, receiver)
end
end
return {
description = "Postet Gfycat-Video",
usage = "URL zu gfycat-Video (hänge 'NSFW' an, wenn es NSFW ist)",
patterns = {
"gfycat.com/([A-Za-z0-9-_-]+) (NSFW)",
"gfycat.com/([A-Za-z0-9-_-]+)"
},
run = run
}
end