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)
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 valid_mimetypes = {['image/jpeg'] = true, ['image/png'] = true, ['image/bmp'] = true}
if not valid_mimetypes[mime_type] then return msg end

View File

@ -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, 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
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)

View File

@ -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

View File

@ -40,29 +40,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
@ -81,12 +63,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