From d72b58ee3f1a86304b00edc211bbc7d0a0950271 Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Sun, 25 Sep 2016 20:54:57 +0200 Subject: [PATCH 1/7] Twitter-User: Ersetze URLs auf "richtige" Art --- otouto/plugins/twitter_user.lua | 34 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/otouto/plugins/twitter_user.lua b/otouto/plugins/twitter_user.lua index c145f8c..af23591 100644 --- a/otouto/plugins/twitter_user.lua +++ b/otouto/plugins/twitter_user.lua @@ -38,29 +38,11 @@ local client = OAuth.new(consumer_key, consumer_secret, { OAuthTokenSecret = access_token_secret }) -function twitter_user:resolve_url(url) - local response_body = {} - local request_constructor = { - url = url, - method = "HEAD", - sink = ltn12.sink.table(response_body), - headers = {}, - redirect = false - } - - local ok, response_code, response_headers, response_status_line = http.request(request_constructor) - if ok and response_headers.location then - return response_headers.location - else - return url - end -end - function twitter_user:action(msg, config, matches) local twitter_url = "https://api.twitter.com/1.1/users/show/"..matches[1]..".json" local response_code, response_headers, response_status_line, response_body = client:PerformRequest("GET", twitter_url) - local response = json.decode(response_body) if response_code ~= 200 then return end + local response = json.decode(response_body) local full_name = response.name local user_name = response.screen_name @@ -79,12 +61,22 @@ function twitter_user:action(msg, config, matches) location = '' end if response.url and response.location ~= '' then - url = ' | '..twitter_user:resolve_url(response.url)..'\n' + url = ' | '..response.url..'\n' elseif response.url and response.location == '' then - url = twitter_user:resolve_url(response.url)..'\n' + url = response.url..'\n' else url = '\n' end + + -- replace short url + if response.entities.url then + for k, v in pairs(response.entities.url.urls) do + local short = v.url + local long = v.expanded_url + local long = long:gsub('%%', '%%%%') + url = url:gsub(short, long) + end + end local body = description..'\n'..location..url From f94b936c173fefa3cdbbf817f56d0009bb73f73b Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Tue, 27 Sep 2016 23:31:16 +0200 Subject: [PATCH 2/7] Quotes: Listquotes per Callback --- otouto/plugins/quotes.lua | 46 +++++++++++++++++++++++++++++--------- otouto/plugins/twitter.lua | 1 - 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/otouto/plugins/quotes.lua b/otouto/plugins/quotes.lua index d56c75d..e02835e 100644 --- a/otouto/plugins/quotes.lua +++ b/otouto/plugins/quotes.lua @@ -54,27 +54,56 @@ function quotes:get_quote(msg) end end -function quotes:list_quotes(msg) +function quotes:callback(callback, msg, self, config) local hash = get_redis_hash(msg, 'quotes') if hash then print('Getting quotes from redis set '..hash) local quotes_table = redis:smembers(hash) local text = "" + for num,quote in pairs(quotes_table) do text = text..num..") "..quote..'\n' end + if not text or text == "" then - return '*Es wurden noch keine Zitate gespeichert.*\nSpeichere doch welche mit `/addquote [Zitat]`', true + utilities.answer_callback_query(callback, 'Es wurden noch keine Zitate gespeichert.', true) else - return upload(text) - end + -- In case the quote list is > 4096 chars + local text_len = string.len(text) + + while text_len > 4096 do + to_send_text = string.sub(text, 1, 4096) + text = string.sub(text, 4096, text_len) + local res = utilities.send_message(callback.from.id, to_send_text) + + if not res then + utilities.answer_callback_query(callback, 'Bitte starte den Bot zuerst privat!', true) + return + end + text_len = string.len(text) + end + + local res = utilities.send_message(callback.from.id, text) + if not res then + utilities.answer_callback_query(callback, 'Bitte starte den Bot zuerst privat!', true) + return + end + utilities.answer_callback_query(callback, 'Zitatliste per PN verschickt') + end + else + utilities.answer_callback_query(callback, 'Es wurden noch keine Zitate gespeichert.', true) end end function quotes:action(msg, config, matches) + if msg.chat.type == 'private' then + utilities.send_reply(msg, 'Dieses Plugin kann nur in Gruppen verwendet werden!') + return + end + if matches[1] == "quote" then - utilities.send_message(msg.chat.id, quotes:get_quote(msg), true) + utilities.send_message(msg.chat.id, quotes:get_quote(msg), true, nil, false) return elseif matches[1] == "addquote" and matches[2] then utilities.send_reply(msg, quotes:save_quote(msg), true) @@ -97,12 +126,7 @@ function quotes:action(msg, config, matches) return end elseif matches[1] == "listquotes" then - local link, iserror = quotes:list_quotes(msg) - if iserror then - utilities.send_reply(msg, link, true) - return - end - utilities.send_reply(msg, 'Ich habe eine Liste aller Zitate hochgeladen.', false, '{"inline_keyboard":[[{"text":"Alle Zitate abrufen","url":"'..link..'"}]]}') + utilities.send_reply(msg, 'Bitte klicke hier unten auf diese attraktive Schaltfläche.', false, '{"inline_keyboard":[[{"text":"Alle Zitate per PN","callback_data":"quotes:"}]]}') return end utilities.send_reply(msg, quotes.doc, true) diff --git a/otouto/plugins/twitter.lua b/otouto/plugins/twitter.lua index d388615..4f52d30 100644 --- a/otouto/plugins/twitter.lua +++ b/otouto/plugins/twitter.lua @@ -41,7 +41,6 @@ local client = OAuth.new(consumer_key, consumer_secret, { }) function twitter:action(msg, config, matches) - if not matches[2] then id = matches[1] else From c629d07bcbaf9f3d4509a36605787046eba93db4 Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Tue, 27 Sep 2016 23:39:20 +0200 Subject: [PATCH 3/7] =?UTF-8?q?-=20Quotes:=20HTML=20bei=20Liste=20-=20Post?= =?UTF-8?q?-Photo:=20Ignorieren,=20wenn=20Caption=20"#ignore"=20enth=C3=A4?= =?UTF-8?q?lt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- otouto/plugins/post_photo.lua | 1 + otouto/plugins/quotes.lua | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/otouto/plugins/post_photo.lua b/otouto/plugins/post_photo.lua index 6d04cbb..bbf704c 100644 --- a/otouto/plugins/post_photo.lua +++ b/otouto/plugins/post_photo.lua @@ -9,6 +9,7 @@ post_photo.triggers = { function post_photo:pre_process(msg, config) if not msg.document then return msg end -- Ignore + if msg.caption:match("#ignore") then return msg end -- Ignore, when Caption contains "#ignore" local mime_type = msg.document.mime_type local valid_mimetypes = {['image/jpeg'] = true, ['image/png'] = true, ['image/bmp'] = true} if not valid_mimetypes[mime_type] then return msg end diff --git a/otouto/plugins/quotes.lua b/otouto/plugins/quotes.lua index e02835e..b8dfccc 100644 --- a/otouto/plugins/quotes.lua +++ b/otouto/plugins/quotes.lua @@ -63,7 +63,7 @@ function quotes:callback(callback, msg, self, config) local text = "" for num,quote in pairs(quotes_table) do - text = text..num..") "..quote..'\n' + text = text..''..num..") "..quote..'\n' end if not text or text == "" then @@ -75,7 +75,7 @@ function quotes:callback(callback, msg, self, config) while text_len > 4096 do to_send_text = string.sub(text, 1, 4096) text = string.sub(text, 4096, text_len) - local res = utilities.send_message(callback.from.id, to_send_text) + local res = utilities.send_message(callback.from.id, to_send_text, true, nil, 'HTML') if not res then utilities.answer_callback_query(callback, 'Bitte starte den Bot zuerst privat!', true) @@ -84,7 +84,7 @@ function quotes:callback(callback, msg, self, config) text_len = string.len(text) end - local res = utilities.send_message(callback.from.id, text) + local res = utilities.send_message(callback.from.id, to_send_text, true, nil, 'HTML') if not res then utilities.answer_callback_query(callback, 'Bitte starte den Bot zuerst privat!', true) return From 8fa8b99b3eee038ccbaee498bc2436918adad8d9 Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Tue, 27 Sep 2016 23:40:38 +0200 Subject: [PATCH 4/7] Meh --- otouto/plugins/quotes.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/otouto/plugins/quotes.lua b/otouto/plugins/quotes.lua index b8dfccc..4a875a9 100644 --- a/otouto/plugins/quotes.lua +++ b/otouto/plugins/quotes.lua @@ -63,7 +63,7 @@ function quotes:callback(callback, msg, self, config) local text = "" for num,quote in pairs(quotes_table) do - text = text..''..num..") "..quote..'\n' + text = text..num..") "..quote..'\n' end if not text or text == "" then @@ -75,7 +75,7 @@ function quotes:callback(callback, msg, self, config) while text_len > 4096 do to_send_text = string.sub(text, 1, 4096) text = string.sub(text, 4096, text_len) - local res = utilities.send_message(callback.from.id, to_send_text, true, nil, 'HTML') + local res = utilities.send_message(callback.from.id, to_send_text, true) if not res then utilities.answer_callback_query(callback, 'Bitte starte den Bot zuerst privat!', true) @@ -84,7 +84,7 @@ function quotes:callback(callback, msg, self, config) text_len = string.len(text) end - local res = utilities.send_message(callback.from.id, to_send_text, true, nil, 'HTML') + local res = utilities.send_message(callback.from.id, text, true) if not res then utilities.answer_callback_query(callback, 'Bitte starte den Bot zuerst privat!', true) return From 3007e6b80f8abd1439bb66040531afab7337f491 Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Tue, 27 Sep 2016 23:42:04 +0200 Subject: [PATCH 5/7] *rage* --- otouto/plugins/post_photo.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/otouto/plugins/post_photo.lua b/otouto/plugins/post_photo.lua index bbf704c..55eb0e0 100644 --- a/otouto/plugins/post_photo.lua +++ b/otouto/plugins/post_photo.lua @@ -9,7 +9,9 @@ post_photo.triggers = { function post_photo:pre_process(msg, config) if not msg.document then return msg end -- Ignore - if msg.caption:match("#ignore") then return msg end -- Ignore, when Caption contains "#ignore" + if msg.caption then + if msg.caption:match("#ignore") then return msg end -- Ignore, when Caption contains "#ignore" + end local mime_type = msg.document.mime_type local valid_mimetypes = {['image/jpeg'] = true, ['image/png'] = true, ['image/bmp'] = true} if not valid_mimetypes[mime_type] then return msg end From e828e6235fcb2a841d108df86ffed2e145ddbfdd Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Wed, 28 Sep 2016 23:04:35 +0200 Subject: [PATCH 6/7] Tagesschau-EIL-Fix --- otouto/plugins/tagesschau_eil.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/otouto/plugins/tagesschau_eil.lua b/otouto/plugins/tagesschau_eil.lua index 1347bcc..4a4197c 100644 --- a/otouto/plugins/tagesschau_eil.lua +++ b/otouto/plugins/tagesschau_eil.lua @@ -81,6 +81,7 @@ function tagesschau_eil:cron() if code ~= 200 then return end local data = json.decode(res) if not data then return end + if data.error then return end if data.breakingnews[1] then if data.breakingnews[1].date ~= last_eil then local title = '#EIL: '..data.breakingnews[1].headline..'' From f70bae058083f2dd46106fd5e405b5f1ca57b42f Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Wed, 28 Sep 2016 23:07:59 +0200 Subject: [PATCH 7/7] Tagesschau-EIL: Richtiger Fix --- otouto/plugins/tagesschau_eil.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/otouto/plugins/tagesschau_eil.lua b/otouto/plugins/tagesschau_eil.lua index 4a4197c..bd38f00 100644 --- a/otouto/plugins/tagesschau_eil.lua +++ b/otouto/plugins/tagesschau_eil.lua @@ -81,6 +81,7 @@ function tagesschau_eil:cron() if code ~= 200 then return end local data = json.decode(res) if not data then return end + if data == "error" then return end if data.error then return end if data.breakingnews[1] then if data.breakingnews[1].date ~= last_eil then