preview.lua: wechsel zur iframely API
+ etwas encoding
This commit is contained in:
parent
ae033a3788
commit
1e74b18bad
@ -451,6 +451,7 @@ function create_cred()
|
|||||||
google_cse_id = "",
|
google_cse_id = "",
|
||||||
gitlab_private_token = "",
|
gitlab_private_token = "",
|
||||||
gitlab_project_id = "",
|
gitlab_project_id = "",
|
||||||
|
iframely_api_key = "",
|
||||||
instagram_access_token = "",
|
instagram_access_token = "",
|
||||||
lyricsnmusic_apikey = "",
|
lyricsnmusic_apikey = "",
|
||||||
mal_username = "",
|
mal_username = "",
|
||||||
|
@ -106,6 +106,10 @@ function unescape(str)
|
|||||||
str = string.gsub(str, '×', '×') -- multiplication sign
|
str = string.gsub(str, '×', '×') -- multiplication sign
|
||||||
str = string.gsub(str, '÷', '÷') -- division sign
|
str = string.gsub(str, '÷', '÷') -- division sign
|
||||||
str = string.gsub(str, '÷', '÷') -- division sign
|
str = string.gsub(str, '÷', '÷') -- division sign
|
||||||
|
str = string.gsub(str, '‎', '') -- left-to-right mark
|
||||||
|
str = string.gsub(str, '‎', '') -- left-to-right mark
|
||||||
|
str = string.gsub(str, '‏', '') -- right-to-left mark
|
||||||
|
str = string.gsub(str, '‏', '') -- right-to-left mark
|
||||||
str = string.gsub(str, '–', '–') -- en dash
|
str = string.gsub(str, '–', '–') -- en dash
|
||||||
str = string.gsub(str, '–', '–') -- en dash
|
str = string.gsub(str, '–', '–') -- en dash
|
||||||
str = string.gsub(str, '—', '—') -- em dash
|
str = string.gsub(str, '—', '—') -- em dash
|
||||||
|
@ -12,36 +12,43 @@ function preview:init(config)
|
|||||||
Erstellt einen Preview-Link]]
|
Erstellt einen Preview-Link]]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local api_key = cred_data.iframely_api_key
|
||||||
|
|
||||||
function preview:inline_callback(inline_query, config, matches)
|
function preview:inline_callback(inline_query, config, matches)
|
||||||
local preview_url = matches[1]
|
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 = http.request('http://iframe.ly/api/oembed?url='..URL.escape(preview_url)..'&api_key='..api_key)
|
||||||
if code ~= 200 then abort_inline_query(inline_query) return end
|
if code ~= 200 then abort_inline_query(inline_query) return end
|
||||||
local data = json.decode(res)
|
local data = json.decode(res)
|
||||||
if data.remote_code >= 400 then abort_inline_query(inline_query) return end
|
|
||||||
|
|
||||||
if data.title then
|
if data.title then
|
||||||
title = data.title
|
title = data.title:gsub('"', '\\"')
|
||||||
else
|
else
|
||||||
title = 'Kein Titel'
|
title = 'Kein Titel'
|
||||||
end
|
end
|
||||||
|
|
||||||
if data.description then
|
if data.description then
|
||||||
description = data.description
|
description = data.description:gsub('"', '\\"')
|
||||||
description_in_text = '\n'..description
|
description_in_text = '\n'..description
|
||||||
else
|
else
|
||||||
description_in_text = ''
|
description_in_text = ''
|
||||||
description = 'Keine Beschreibung verfügbar'
|
description = 'Keine Beschreibung verfügbar'
|
||||||
end
|
end
|
||||||
|
|
||||||
if data.only_name then
|
if data.provider_name then
|
||||||
only_name = data.only_name
|
provider_name = data.provider_name:gsub('"', '\\"')
|
||||||
else
|
else
|
||||||
only_name = preview_url:match('^%w+://([^/]+)') -- we only need the domain
|
provider_name = preview_url:match('^%w+://([^/]+)') -- we only need the domain
|
||||||
end
|
end
|
||||||
|
|
||||||
local message_text = '<b>'..title..'</b>'..description_in_text..'\n- '..only_name
|
if data.thumbnail_url then
|
||||||
|
thumb = data.thumbnail_url
|
||||||
|
else
|
||||||
|
thumb = 'https://anditest.perseus.uberspace.de/inlineQuerys/generic/internet.jpg'
|
||||||
|
end
|
||||||
|
|
||||||
|
local message_text = '<b>'..title..'</b>'..description_in_text..'\n<i>- '..provider_name..'</i>'
|
||||||
|
|
||||||
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}}]'
|
local results = '[{"type":"article","id":"77","title":"'..title..'","description":"'..description..'","url":"'..preview_url..'","thumb_url":"'..thumb..'","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)
|
utilities.answer_inline_query(inline_query, results, 3600, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user