diff --git a/otouto/plugins/afk.lua b/otouto/plugins/afk.lua index c403340..40ac9be 100644 --- a/otouto/plugins/afk.lua +++ b/otouto/plugins/afk.lua @@ -81,16 +81,7 @@ function afk:pre_process(msg, self) local current_timestamp = msg.date local afk_time = current_timestamp - timestamp local seconds = afk_time % 60 - local minutes = math.floor(afk_time / 60) - local minutes = minutes % 60 - local hours = math.floor(afk_time / 3600) - if minutes == 00 and hours == 00 then - duration = seconds..' Sekunden' - elseif hours == 00 and minutes ~= 00 then - duration = string.format("%02d:%02d", minutes, seconds)..' Minuten' - elseif hours ~= 00 then - duration = string.format("%02d:%02d:%02d", hours, minutes, seconds)..' Stunden' - end + local duration = makeHumanTime(seconds) redis:hset(hash, 'afk', false) if afk_text then diff --git a/otouto/plugins/tagesschau.lua b/otouto/plugins/tagesschau.lua index 66cf306..3806d08 100644 --- a/otouto/plugins/tagesschau.lua +++ b/otouto/plugins/tagesschau.lua @@ -9,6 +9,8 @@ local bindings = require('otouto.bindings') tagesschau.triggers = { "tagesschau.de/([A-Za-z0-9-_-_-/]+).html" } + +tagesschau.inline_triggers = tagesschau.triggers local BASE_URL = 'https://www.tagesschau.de/api' @@ -36,12 +38,33 @@ function tagesschau:get_tagesschau_article(article) local text = '*'..title..'*\n_'..posted_at..'_\n'..news if data.banner[1] then - return text, data.banner[1].variants[1].modPremium + return text, data.banner[1].variants[1].modPremium, data.shortheadline, data.shorttext else - return text + return text, nil, data.shortheadline, data.shorttext end end +function tagesschau:inline_callback(inline_query, config, matches) + local article = matches[1] + local full_url = 'http://www.tagesschau.de/'..article..'.html' + local text, img_url, headline, shorttext = tagesschau:get_tagesschau_article(article) + if text == 'HTTP-Fehler' or text == 'Artikel nicht gefunden!' then return end + + if text:match('"') then + text = text:gsub('"', '\\"') + end + if shorttext:match('"') then + shorttext = shorttext:gsub('"', '\\"') + end + if headline:match('"') then + headline = headline:gsub('"', '\\"') + end + + local text = text:gsub('\n', '\\n') + local results = '[{"type":"article","id":"'..math.random(100000000000000000)..'","title":"'..headline..'","description":"'..shorttext..'","url":"'..full_url..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/tagesschau/tagesschau.jpg","thumb_width":150,"thumb_height":150,"hide_url":true,"reply_markup":{"inline_keyboard":[[{"text":"Artikel aufrufen","url":"'..full_url..'"}]]},"input_message_content":{"message_text":"'..text..'","parse_mode":"Markdown"}}]' + utilities.answer_inline_query(self, inline_query, results, 7200) +end + function tagesschau:action(msg, config, matches) local article = matches[1] local text, image_url = tagesschau:get_tagesschau_article(article)