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
Raw Normal View History

2015-11-12 17:42:03 +01:00
do
local function send_gfycat_video(name, receiver)
2015-11-12 17:42:03 +01:00
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)
2015-11-12 17:42:03 +01:00
local cb_extra = {file_path=file}
if file == nil then
send_msg(receiver, 'Fehler beim Herunterladen von '..name, ok_cb, false)
2015-11-12 17:42:03 +01:00
else
send_video(receiver, file, rmtmp_cb, cb_extra)
2015-11-12 17:42:03 +01:00
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)
2015-11-12 17:42:03 +01:00
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
2015-11-12 17:42:03 +01:00
end
return {
description = "Postet Gfycat-Video",
usage = "URL zu gfycat-Video (hänge 'NSFW' an, wenn es NSFW ist)",
2015-11-12 17:42:03 +01:00
patterns = {
"gfycat.com/([A-Za-z0-9-_-]+) (NSFW)",
"gfycat.com/([A-Za-z0-9-_-]+)"
2015-11-12 17:42:03 +01:00
},
run = run
}
end