From 973f111599bb800c4504353731ffa5dd4635c00d Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Sun, 2 Oct 2016 17:19:06 +0200 Subject: [PATCH 1/3] Notify: Typo-Fix --- otouto/plugins/notify.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/otouto/plugins/notify.lua b/otouto/plugins/notify.lua index 1dff16e..3988c31 100644 --- a/otouto/plugins/notify.lua +++ b/otouto/plugins/notify.lua @@ -74,7 +74,7 @@ function notify:action(msg, config, matches) redis:hset(hash, 'notify', false) print('Removing '..username..' from redis set notify:ls') redis:srem('notify:ls', username) - utilities.send_reply(msg, 'Du erhälst jetzt keine Benachrichtigungen mehr, wenn du angesprochen wirst.') + utilities.send_reply(msg, 'Du erhältst jetzt keine Benachrichtigungen mehr, wenn du angesprochen wirst.') return else if redis:sismember('notify:ls', username) then @@ -87,11 +87,11 @@ function notify:action(msg, config, matches) redis:hset(hash, 'id', msg.from.id) print('Adding '..username..' to redis set notify:ls') redis:sadd('notify:ls', username) - local res = utilities.send_message(msg.from.id, 'Du erhälst jetzt Benachrichtigungen, wenn du angesprochen wirst, nutze `/notify del` zum Deaktivieren.', true, nil, true) + local res = utilities.send_message(msg.from.id, 'Du erhältst jetzt Benachrichtigungen, wenn du angesprochen wirst, nutze `/notify del` zum Deaktivieren.', true, nil, true) if not res then utilities.send_reply(msg, 'Bitte schreibe mir [privat](http://telegram.me/' .. self.info.username .. '?start=notify), um den Vorgang abzuschließen.', true) elseif msg.chat.type ~= 'private' then - utilities.send_reply(msg, 'Du erhälst jetzt Benachrichtigungen, wenn du angesprochen wirst, nutze `/notify del` zum Deaktivieren.', true) + utilities.send_reply(msg, 'Du erhältst jetzt Benachrichtigungen, wenn du angesprochen wirst, nutze `/notify del` zum Deaktivieren.', true) end end end From c573d89cee4b088ca38fcdab416c5b8d2a962330 Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Sun, 2 Oct 2016 18:02:30 +0200 Subject: [PATCH 2/3] Portiere Tweet-Plugin --- otouto/plugins/tweet.lua | 97 ++++++++++++++++++++++++++++++++++++++ otouto/plugins/twitter.lua | 39 +++++++++------ 2 files changed, 122 insertions(+), 14 deletions(-) create mode 100644 otouto/plugins/tweet.lua diff --git a/otouto/plugins/tweet.lua b/otouto/plugins/tweet.lua new file mode 100644 index 0000000..00127fb --- /dev/null +++ b/otouto/plugins/tweet.lua @@ -0,0 +1,97 @@ +local tweet = {} + +require('otouto/plugins/twitter') + +tweet.command = 'tweet ' + +function tweet:init(config) + if not cred_data.tw_consumer_key then + print('Missing config value: tw_consumer_key.') + print('tweet.lua will not be enabled.') + return + elseif not cred_data.tw_consumer_secret then + print('Missing config value: tw_consumer_secret.') + print('tweet.lua will not be enabled.') + return + elseif not cred_data.tw_access_token then + print('Missing config value: tw_access_token.') + print('tweet.lua will not be enabled.') + return + elseif not cred_data.tw_access_token_secret then + print('Missing config value: tw_access_token_secret.') + print('tweet.lua will not be enabled.') + return + end + + tweet.triggers = { + "^/tweet ([%w_%.%-]+)$", + "^/tweet ([%w_%.%-]+) (last)$" + } + tweet.doc = [[* +]]..config.cmd_pat..[[tweet* __: Zufälliger Tweet vom User mit diesem Namen +*]]..config.cmd_pat..[[tweet* __ _[last]_: Aktuellster Tweet vom User mit diesem Namen]] +end + +local twitter_url = "https://api.twitter.com/1.1/statuses/user_timeline.json" + +local consumer_key = cred_data.tw_consumer_key +local consumer_secret = cred_data.tw_consumer_secret +local access_token = cred_data.tw_access_token +local access_token_secret = cred_data.tw_access_token_secret + +local client = OAuth.new(consumer_key, consumer_secret, { + RequestToken = "https://api.twitter.com/oauth/request_token", + AuthorizeUser = {"https://api.twitter.com/oauth/authorize", method = "GET"}, + AccessToken = "https://api.twitter.com/oauth/access_token" +}, { + OAuthToken = access_token, + OAuthTokenSecret = access_token_secret +}) + +function tweet:get_random_tweet(base) + local response_code, response_headers, response_status_line, response_body = client:PerformRequest("GET", twitter_url, base) + if response_code ~= 200 then + return "Konnte nicht verbinden, evtl. existiert der User nicht?" + end + + local response = json.decode(response_body) + if #response == 0 then + return "Konnte keinen Tweet bekommen, sorry" + end + + local i = math.random(#response) + rand_tweet = response[i] + return get_tweet(rand_tweet) +end + +function tweet:action(msg, config, matches) + utilities.send_typing(msg.chat.id, 'typing') + local base = {tweet_mode = 'extended'} + base.screen_name = matches[1] + + local count = 200 + local all = false + if #matches > 1 and matches[2] == 'last' then + count = 1 + end + base.count = count + + local text, images, videos = tweet:get_random_tweet(base) + if not images or not videos then + utilities.send_reply(msg, text) + return + end + + -- send the parts + utilities.send_reply(msg, text, 'HTML') + for k, v in pairs(images) do + local file = download_to_file(v) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) + end + for k, v in pairs(videos) do + local file = download_to_file(v) + utilities.send_video(msg.chat.id, file, nil, msg.message_id) + end +end + +return tweet \ No newline at end of file diff --git a/otouto/plugins/twitter.lua b/otouto/plugins/twitter.lua index 4f52d30..db19ca3 100644 --- a/otouto/plugins/twitter.lua +++ b/otouto/plugins/twitter.lua @@ -40,18 +40,7 @@ local client = OAuth.new(consumer_key, consumer_secret, { OAuthTokenSecret = access_token_secret }) -function twitter:action(msg, config, matches) - if not matches[2] then - id = matches[1] - else - id = matches[2] - end - - local twitter_url = "https://api.twitter.com/1.1/statuses/show/" .. id.. ".json" - local get_params = {tweet_mode = 'extended'} - local response_code, response_headers, response_status_line, response_body = client:PerformRequest("GET", twitter_url, get_params) - local response = json.decode(response_body) - +function get_tweet(response) local full_name = response.user.name local user_name = response.user.screen_name if response.user.verified then @@ -149,8 +138,30 @@ function twitter:action(msg, config, matches) text = text..'\n\n'..quote..'\n' end + return header.."\n"..utilities.trim(text).."\n"..footer, images, videos +end + +function twitter:action(msg, config, matches) + utilities.send_typing(msg.chat.id, 'typing') + if not matches[2] then + id = matches[1] + else + id = matches[2] + end + + local twitter_url = "https://api.twitter.com/1.1/statuses/show/" .. id.. ".json" + local get_params = {tweet_mode = 'extended'} + local response_code, response_headers, response_status_line, response_body = client:PerformRequest("GET", twitter_url, get_params) + if response_code ~= 200 then + utilities.send_repl(msg, 'Twitter nicht erreichbar, Tweet existiert nicht oder User ist privat.') + return + end + local response = json.decode(response_body) + + local text, images, videos = get_tweet(response) + -- send the parts - utilities.send_reply(msg, header .. "\n" .. utilities.trim(text).."\n"..footer, 'HTML') + utilities.send_reply(msg, text, 'HTML') for k, v in pairs(images) do local file = download_to_file(v) utilities.send_photo(msg.chat.id, file, nil, msg.message_id) @@ -161,4 +172,4 @@ function twitter:action(msg, config, matches) end end -return twitter +return twitter \ No newline at end of file From ff7429363a6295a31ce600fe1639404d742f25b0 Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Sun, 2 Oct 2016 18:40:05 +0200 Subject: [PATCH 3/3] - NEU: Amazon-Reflink-Entferner - HEAD-Requests bei Expand und GitHub-Feed ignorieren jetzt den Inhalt --- otouto/plugins/amazon_cleaner.lua | 33 +++++++++++++++++++++++++++++++ otouto/plugins/expand.lua | 6 ++---- otouto/plugins/github_feed.lua | 2 +- 3 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 otouto/plugins/amazon_cleaner.lua diff --git a/otouto/plugins/amazon_cleaner.lua b/otouto/plugins/amazon_cleaner.lua new file mode 100644 index 0000000..52080fb --- /dev/null +++ b/otouto/plugins/amazon_cleaner.lua @@ -0,0 +1,33 @@ +local cln_amzn = {} + +cln_amzn.triggers = { + 'amazon.(%w+)/gp/product/(.+)/(.+)', + 'amazon.(%w+)/gp/product/(.+)%?(.+)', + 'amazon.(%w+)/dp/(.+)/(.+)', + 'amazon.(%w+)/dp/(.+)%?(.+)', + 'amzn.to/(.+)' +} + +function cln_amzn:action(msg, config, matches) + if #matches == 1 then + local request_constructor = { + url = 'http://amzn.to/'..matches[1], + method = "HEAD", + sink = ltn12.sink.null(), + redirect = false + } + + local ok, response_code, response_headers = http.request(request_constructor) + local long_url = response_headers.location + local domain, product_id = long_url:match('amazon.(%w+)/gp/product/(.+)/(.+)') + utilities.send_reply(msg, 'Ohne Ref: https://amazon.'..domain..'/dp/'..product_id) + return + end + + text = msg.text:lower() + if text:match('tag%=.+') or text:match('linkid%=.+') then + utilities.send_reply(msg, 'Ohne Ref: https://amazon.'..matches[1]..'/dp/'..matches[2]) + end +end + +return cln_amzn \ No newline at end of file diff --git a/otouto/plugins/expand.lua b/otouto/plugins/expand.lua index 9ef395d..d5f9ac5 100644 --- a/otouto/plugins/expand.lua +++ b/otouto/plugins/expand.lua @@ -31,16 +31,14 @@ function expand:inline_callback(inline_query, config, matches) end function expand:url(long_url) - local response_body = {} local request_constructor = { url = long_url, method = "HEAD", - sink = ltn12.sink.table(response_body), - headers = {}, + sink = ltn12.sink.null(), redirect = false } - local ok, response_code, response_headers, response_status_line = http.request(request_constructor) + local ok, response_code, response_headers = http.request(request_constructor) return ok, response_headers end diff --git a/otouto/plugins/github_feed.lua b/otouto/plugins/github_feed.lua index 78a2d98..6c33f68 100644 --- a/otouto/plugins/github_feed.lua +++ b/otouto/plugins/github_feed.lua @@ -47,11 +47,11 @@ end function gh_feed_check_modified(repo, cur_etag, last_date) local url = BASE_URL..'/'..repo - local response_body = {} local request_constructor = { url = url, method = "HEAD", redirect = false, + sink = ltn12.sink.null(), headers = { Authorization = 'token '..token, ["If-None-Match"] = cur_etag