65 lines
1.5 KiB
Lua
65 lines
1.5 KiB
Lua
local instagram = {}
|
||
|
||
function instagram:init(config)
|
||
instagram.triggers = {
|
||
"instagram.com/p/(.*)"
|
||
}
|
||
end
|
||
|
||
function instagram:get_instagram(url)
|
||
local api_key = cred_data.iframely_api_key
|
||
local res, code = https.request('https://iframe.ly/api/iframely?url=https://www.instagram.com/p/'..URL.escape(url)..'&api_key='..api_key)
|
||
if code ~= 200 then return end
|
||
local data = json.decode(res)
|
||
|
||
if data.meta.title then
|
||
title = data.meta.title:gsub('"', '\\"')
|
||
else
|
||
title = 'Kein Titel'
|
||
end
|
||
|
||
if data.meta.description then
|
||
description = data.meta.description:gsub('"', '\\"')
|
||
description_in_text = description
|
||
else
|
||
description_in_text = ''
|
||
description = 'Keine Beschreibung verfügbar'
|
||
end
|
||
|
||
if data.links.player then
|
||
video = 'https:'..data.links.player[1].href
|
||
else
|
||
video = 'NOVID'
|
||
end
|
||
|
||
if data.links.image then
|
||
pic = '<a href="'..data.links.image[1].href..'"> </a>'
|
||
else
|
||
pic = '<a href="'..data.links.thumbnail[2].href..'"> </a>'
|
||
end
|
||
|
||
local text = '<b>'..title..'</b> '..pic..'\n<i>'..description_in_text..'</i>'
|
||
|
||
return video, text
|
||
end
|
||
|
||
function instagram:action(msg, config, matches)
|
||
local url = matches[1]
|
||
local video, text = instagram:get_instagram(url)
|
||
|
||
if not url then
|
||
utilities.send_reply(msg, 'Fehler')
|
||
return
|
||
end
|
||
|
||
if video == 'NOVID' then
|
||
return
|
||
else
|
||
utilities.send_typing(msg.chat.id, 'upload_video')
|
||
utilities.send_video(msg.chat.id, video, nil, msg.message_id)
|
||
end
|
||
|
||
utilities.send_message(msg.chat.id, text, false, msg.message_id, 'html')
|
||
end
|
||
|
||
return instagram |