Merge Upstream

This commit is contained in:
Akamaru 2016-09-29 14:03:57 +02:00
commit 86523b5c98
4 changed files with 51 additions and 33 deletions

View File

@ -9,6 +9,9 @@ post_photo.triggers = {
function post_photo:pre_process(msg, config) function post_photo:pre_process(msg, config)
if not msg.document then return msg end -- Ignore if not msg.document then return msg end -- 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 mime_type = msg.document.mime_type
local valid_mimetypes = {['image/jpeg'] = true, ['image/png'] = true, ['image/bmp'] = true} local valid_mimetypes = {['image/jpeg'] = true, ['image/png'] = true, ['image/bmp'] = true}
if not valid_mimetypes[mime_type] then return msg end if not valid_mimetypes[mime_type] then return msg end

View File

@ -54,27 +54,56 @@ function quotes:get_quote(msg)
end end
end end
function quotes:list_quotes(msg) function quotes:callback(callback, msg, self, config)
local hash = get_redis_hash(msg, 'quotes') local hash = get_redis_hash(msg, 'quotes')
if hash then if hash then
print('Getting quotes from redis set '..hash) print('Getting quotes from redis set '..hash)
local quotes_table = redis:smembers(hash) local quotes_table = redis:smembers(hash)
local text = "" local text = ""
for num,quote in pairs(quotes_table) do for num,quote in pairs(quotes_table) do
text = text..num..") "..quote..'\n' text = text..num..") "..quote..'\n'
end end
if not text or text == "" then 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 else
return upload(text) -- In case the quote list is > 4096 chars
end 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, true)
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, true)
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
end end
function quotes:action(msg, config, matches) 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 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 return
elseif matches[1] == "addquote" and matches[2] then elseif matches[1] == "addquote" and matches[2] then
utilities.send_reply(msg, quotes:save_quote(msg), true) utilities.send_reply(msg, quotes:save_quote(msg), true)
@ -97,12 +126,7 @@ function quotes:action(msg, config, matches)
return return
end end
elseif matches[1] == "listquotes" then elseif matches[1] == "listquotes" then
local link, iserror = quotes:list_quotes(msg) utilities.send_reply(msg, 'Bitte klicke hier unten auf diese attraktive Schaltfläche.', false, '{"inline_keyboard":[[{"text":"Alle Zitate per PN","callback_data":"quotes:"}]]}')
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..'"}]]}')
return return
end end
utilities.send_reply(msg, quotes.doc, true) utilities.send_reply(msg, quotes.doc, true)

View File

@ -41,7 +41,6 @@ local client = OAuth.new(consumer_key, consumer_secret, {
}) })
function twitter:action(msg, config, matches) function twitter:action(msg, config, matches)
if not matches[2] then if not matches[2] then
id = matches[1] id = matches[1]
else else

View File

@ -40,29 +40,11 @@ local client = OAuth.new(consumer_key, consumer_secret, {
OAuthTokenSecret = access_token_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) function twitter_user:action(msg, config, matches)
local twitter_url = "https://api.twitter.com/1.1/users/show/"..matches[1]..".json" 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_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 if response_code ~= 200 then return end
local response = json.decode(response_body)
local full_name = response.name local full_name = response.name
local user_name = response.screen_name local user_name = response.screen_name
@ -81,12 +63,22 @@ function twitter_user:action(msg, config, matches)
location = '' location = ''
end end
if response.url and response.location ~= '' then 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 elseif response.url and response.location == '' then
url = twitter_user:resolve_url(response.url)..'\n' url = response.url..'\n'
else else
url = '\n' url = '\n'
end 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 local body = description..'\n'..location..url