From 16b63e2e3709321bda19493441169e8b86fabf26 Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Thu, 29 Sep 2016 18:13:11 +0200 Subject: [PATCH] =?UTF-8?q?iFramely=20f=C3=BCr=20Preview=20von=20@Akamaru?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- otouto/plugins/preview.lua | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/otouto/plugins/preview.lua b/otouto/plugins/preview.lua index 532fca5..c426e15 100644 --- a/otouto/plugins/preview.lua +++ b/otouto/plugins/preview.lua @@ -12,37 +12,48 @@ function preview:init(config) Erstellt einen Preview-Link]] end +local api_key = cred_data.iframely_api_key + function preview:inline_callback(inline_query, config, matches) local preview_url = matches[1] - local res, code = https.request('https://brawlbot.tk/apis/simple_meta_api/?url='..URL.escape(preview_url)) + local res, code = https.request('https://iframe.ly/api/oembed?url='..URL.escape(preview_url)..'&api_key='..api_key) if code ~= 200 then abort_inline_query(inline_query) return end local data = json.decode(res) - if data.remote_code >= 400 then abort_inline_query(inline_query) return end if data.title then - title = data.title + title = data.title:gsub('"', '\\"') else title = 'Kein Titel' end if data.description then - description = data.description + description = data.description:gsub('"', '\\"') description_in_text = '\n'..description else description_in_text = '' description = 'Keine Beschreibung verfügbar' end - if data.only_name then - only_name = data.only_name + if data.provider_name then + provider_name = data.provider_name:gsub('"', '\\"') else - only_name = preview_url:match('^%w+://([^/]+)') -- we only need the domain + provider_name = preview_url:match('^%w+://([^/]+)') -- we only need the domain end - local message_text = ''..title..''..description_in_text..'\n— '..only_name + if data.thumbnail_url then + thumb = data.thumbnail_url + width = data.thumbnail_width + height = data.thumbnail_height + else + thumb = 'https://anditest.perseus.uberspace.de/inlineQuerys/generic/internet.jpg' + width = 150 + height = 150 + end + + local message_text = ''..title..''..description_in_text..'\n- '..provider_name..'' - local results = '[{"type":"article","id":"77","title":"'..title..'","description":"'..description..'","url":"'..preview_url..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/generic/internet.jpg","thumb_width":150,"thumb_height":150,"hide_url":true,"reply_markup":{"inline_keyboard":[[{"text":"Webseite aufrufen","url":"'..preview_url..'"}]]},"input_message_content":{"message_text":"'..message_text..'","parse_mode":"HTML","disable_web_page_preview":true}}]' - utilities.answer_inline_query(inline_query, results, 3600, true) + local results = '[{"type":"article","id":"77","title":"'..title..'","description":"'..description..'","url":"'..preview_url..'","thumb_url":"'..thumb..'","thumb_width":'..width..',"thumb_height":'..height..',"hide_url":true,"reply_markup":{"inline_keyboard":[[{"text":"Webseite aufrufen","url":"'..preview_url..'"}]]},"input_message_content":{"message_text":"'..message_text..'","parse_mode":"HTML","disable_web_page_preview":true}}]' + utilities.answer_inline_query(inline_query, results, data.cache_age) end function preview:action(msg)