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

65 lines
1.5 KiB
Lua
Raw Normal View History

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
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)
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('"', '\\"')
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
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>'
2017-05-24 21:28:05 +02:00
return video, text
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)
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')
end
return instagram