Quotes: Listquotes per Callback

This commit is contained in:
Andreas Bielawski 2016-09-27 23:31:16 +02:00
parent d72b58ee3f
commit f94b936c17
2 changed files with 35 additions and 12 deletions

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