2016-11-22 15:45:46 +01:00
|
|
|
|
local instagram = {}
|
|
|
|
|
|
|
|
|
|
function instagram:init(config)
|
|
|
|
|
instagram.triggers = {
|
2016-12-24 23:52:30 +01:00
|
|
|
|
"instagram.com/p/(.*)"
|
2016-11-22 15:45:46 +01:00
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function instagram:get_instagram(url)
|
|
|
|
|
local api_key = cred_data.iframely_api_key
|
2017-05-24 21:28:05 +02:00
|
|
|
|
local res, code = https.request('https://iframe.ly/api/iframely?url=https://www.instagram.com/p/'..URL.escape(url)..'&api_key='..api_key)
|
2016-11-22 15:45:46 +01:00
|
|
|
|
if code ~= 200 then return end
|
|
|
|
|
local data = json.decode(res)
|
|
|
|
|
|
2017-05-24 21:28:05 +02:00
|
|
|
|
if data.meta.title then
|
|
|
|
|
title = data.meta.title:gsub('"', '\\"')
|
2016-11-22 15:45:46 +01:00
|
|
|
|
else
|
|
|
|
|
title = 'Kein Titel'
|
|
|
|
|
end
|
|
|
|
|
|
2017-05-24 21:28:05 +02:00
|
|
|
|
if data.meta.description then
|
|
|
|
|
description = data.meta.description:gsub('"', '\\"')
|
|
|
|
|
description_in_text = description
|
2016-11-22 15:45:46 +01:00
|
|
|
|
else
|
|
|
|
|
description_in_text = ''
|
|
|
|
|
description = 'Keine Beschreibung verfügbar'
|
|
|
|
|
end
|
|
|
|
|
|
2017-05-24 21:28:05 +02:00
|
|
|
|
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>'
|
2016-11-22 15:45:46 +01:00
|
|
|
|
|
2017-05-24 21:28:05 +02:00
|
|
|
|
return video, text
|
2016-11-22 15:45:46 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function instagram:action(msg, config, matches)
|
|
|
|
|
local url = matches[1]
|
2017-05-24 21:28:05 +02:00
|
|
|
|
local video, text = instagram:get_instagram(url)
|
2016-11-22 15:45:46 +01:00
|
|
|
|
|
|
|
|
|
if not url then
|
|
|
|
|
utilities.send_reply(msg, 'Fehler')
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
2017-05-24 21:28:05 +02:00
|
|
|
|
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')
|
2016-11-22 15:45:46 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return instagram
|