Plex: Inline

Upstream-Merge
This commit is contained in:
Andreas Bielawski 2016-09-30 16:13:14 +02:00
commit 1fc4941604
2 changed files with 24 additions and 11 deletions

View File

@ -2,6 +2,9 @@ local plex = {}
function plex:init(config)
plex.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('plex', true).table
plex.inline_triggers = {
"^plex (.+)"
}
plex.doc = '\n*/plex* _<Suchbegriff>_'
end
@ -33,7 +36,7 @@ function plex:get_plex(query)
Accept = "application/json"
}
}
local ok, response_code, response_headers, response_status_line = http.request(request_constructor)
local ok, response_code, response_headers, response_status_line = https.request(request_constructor)
if not ok then return 'NOTOK' end
local data = json.decode(table.concat(response_body))._children[1]
@ -58,7 +61,7 @@ function plex:get_plex(query)
end
if data.parentTitle then
artist = ' von <b>'..data.parentTitle..'</b>'
artist = '<b>'..data.parentTitle..'</b>'
else
artist = ''
end
@ -83,17 +86,14 @@ function plex:get_plex(query)
if data.originallyAvailableAt then
date = makeOurDate(data.originallyAvailableAt)
date1 = '\n<b>Ausstrahlung:</b> '..date
date2 = '\n<b>Veröffentlicht:</b> '..date
elseif data.year then
date = data.year
date1 = '\n<b>Ausstrahlung:</b> '..date
date2 = '\n<b>Veröffentlicht:</b> '..date
else
date = ''
date1 = date
date2 = date
end
local date1 = '\n<b>Ausstrahlung:</b> '..date
local date2 = '\n<b>Veröffentlicht:</b> '..date
if data.leafCount then
if data.leafCount > 1 then
@ -149,7 +149,7 @@ function plex:get_plex(query)
elseif data.librarySectionTitle == 'Filme' then
text = title..tag..origtitle..studio..date2..fsk..duration..rating..desc
elseif data.librarySectionTitle == 'Musik' then
text = title..artist..date2..desc
text = title..' von '..artist..date2
elseif data.librarySectionTitle == 'Serien' then
text = title..from..studio..date1..episodes..fsk..duration..rating..desc
elseif data.librarySectionTitle == 'YouTube Serien' then
@ -159,11 +159,20 @@ function plex:get_plex(query)
if string.match(title, 'Local Network') then
return 'Nichts gefunden!'
else
return text, pic
return text, pic, data.title
end
end
function plex:inline_callback(inline_query, config, matches)
local input = string.gsub(URL.escape(matches[1]), '&', '+')
local text, _, title = plex:get_plex(input)
if not text or not title then abort_inline_query(inline_query) return end
local text = text:gsub('"', '\\"')
local results = '[{"type":"article","id":"PLEX","title":"'..title..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/plex/plex.jpg","thumb_width":150,"thumb_height":150,"input_message_content":{"message_text":"'..text..'","parse_mode":"HTML"}}]'
utilities.answer_inline_query(inline_query, results, 3600)
end
function plex:action(msg, config)
local input = utilities.input_from_msg(msg)
if not input then

View File

@ -42,13 +42,17 @@ function preview:inline_callback(inline_query, config, matches)
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 = '<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":"'..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}}]'
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