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 Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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