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

48 lines
1.1 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/oembed?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.title then
title = data.title:gsub('"', '\\"')
else
title = 'Kein Titel'
end
if data.description then
description = data.description:gsub('"', '\\"')
description_in_text = '\n'..description
else
description_in_text = ''
description = 'Keine Beschreibung verfügbar'
end
local pic = data.thumbnail_url
local text = title..'\n'..description_in_text
return pic, text
end
function instagram:action(msg, config, matches)
local url = matches[1]
local pic, text = instagram:get_instagram(url)
if not url then
utilities.send_reply(msg, 'Fehler')
return
end
utilities.send_typing(msg.chat.id, 'upload_photo')
utilities.send_photo(msg.chat.id, pic, text, msg.message_id)
end
return instagram