From 0f8e32742e7e4dffe6f13103c2873932b7cae1ad Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Fri, 15 Jul 2016 14:42:40 +0200 Subject: [PATCH] =?UTF-8?q?Adfly=20per=20Inline-Query=20entk=C3=BCrzen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- otouto/plugins/adfly.lua | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/otouto/plugins/adfly.lua b/otouto/plugins/adfly.lua index 190fef6..4a1d170 100644 --- a/otouto/plugins/adfly.lua +++ b/otouto/plugins/adfly.lua @@ -8,6 +8,7 @@ function adfly:init(config) adfly.triggers = { 'adf.ly/([A-Za-z0-9-_-]+)' } + adfly.inline_triggers = adfly.triggers adfly.doc = [[*adf.ly-Link*: Postet vollen Link]] end @@ -21,13 +22,24 @@ function adfly:expand_adfly_link(adfly_code) return res end -function adfly:action(msg) - local input = msg.text - if not input:match('adf.ly/([A-Za-z0-9-_-]+)') then - return +function adfly:inline_callback(inline_query, config, matches) + local adfly_code = matches[1] + local hash = 'telegram:cache:adfly:'..adfly_code + if redis:exists(hash) == false then + url = adfly:expand_adfly_link(adfly_code) + else + url = redis:get(hash) end - local adfly_code = input:match('adf.ly/([A-Za-z0-9-_-]+)') + if not url then return end + if url == 'NOTFOUND' then return end + + local results = '[{"type":"article","id":"'..math.random(100000000000000000)..'","title":"Verlängerte URL","description":"'..url..'","url":"'..url..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/generic/internet.jpg","thumb_width":165,"thumb_height":150,"hide_url":true,"input_message_content":{"message_text":"'..url..'"}}]' + utilities.answer_inline_query(self, inline_query, results, 3600) +end + +function adfly:action(msg, config, matches) + local adfly_code = matches[1] local hash = 'telegram:cache:adfly:'..adfly_code if redis:exists(hash) == false then local expanded_url = adfly:expand_adfly_link(adfly_code)