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/otouto/plugins/gfycat.lua
Andreas Bielawski c484023791 - Portierung folgender Plugins:
+ Games
+ GDrive
+ Gfycat
+ Googl
+ GPS
+ Hackernews
+ Hello
+ Instagram
+ IP_info
+ GMaps so angepasst, dass es wie Location funktioniert
- Bugfixes, Pattern-Fixes, etc.
2016-06-19 19:25:24 +02:00

37 lines
956 B
Lua

-- Thanks to Akamaru for the API entrypoints and the initial idea
local gfycat = {}
local https = require('ssl.https')
local json = require('dkjson')
local utilities = require('otouto.utilities')
gfycat.triggers = {
"gfycat.com/([A-Za-z0-9-_-]+)"
}
function gfycat:send_gfycat_video(name, self, msg)
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
utilities.send_typing(self, msg.chat.id, 'upload_video')
local file = download_to_file(data.webmUrl)
if file == nil then
send_reply(self, msg, 'Fehler beim Herunterladen von '..name)
return
else
utilities.send_video(self, msg.chat.id, file, nil, msg.message_id)
return
end
end
function gfycat:action(msg, config, matches)
local name = matches[1]
gfycat:send_gfycat_video(name, self, msg)
return
end
return gfycat