Zitate können nun gelistet werden

This commit is contained in:
Akamaru 2015-11-14 23:48:54 +01:00
parent d0a32f0f1e
commit 7d9e98d9b7
1 changed files with 29 additions and 7 deletions

View File

@ -2,7 +2,7 @@ do
local function save_quote(msg)
if msg.text:sub(11):isempty() then
return "Benutzung: !addquote [Zitat]"
return "Benutzung: /addquote [Zitat]"
end
local quote = msg.text:sub(11)
@ -14,7 +14,7 @@ end
local function delete_quote(msg)
if msg.text:sub(11):isempty() then
return "Benutzung: !delquote [Zitat]"
return "Benutzung: /delquote [Zitat]"
end
local quote = msg.text:sub(11)
@ -34,17 +34,35 @@ local function get_quote(msg)
if hash then
print('Getting quote from redis set '..hash)
quotes_table = redis:smembers(hash)
local quotes_table = redis:smembers(hash)
if not quotes_table[1] then
return 'Es wurden noch keine Zitate gespeichert.\nSpeichere doch welche mit !addquote [Zitat]'
return 'Es wurden noch keine Zitate gespeichert.\nSpeichere doch welche mit /addquote [Zitat]'
else
return quotes_table[math.random(1,#quotes_table)]
end
end
end
local function list_quotes(msg)
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]'
else
return text
end
end
end
local function run(msg, matches)
if string.match(msg.text, "/quote$") then
if matches[1] == "quote" then
return get_quote(msg)
elseif matches[1] == "addquote" then
return save_quote(msg)
@ -54,6 +72,8 @@ local function run(msg, matches)
else
return delete_quote(msg)
end
elseif matches[1] == "listquotes" then
return list_quotes(msg)
end
end
@ -62,12 +82,14 @@ return {
usage = {
"/addquote [Zitat]: Fügt Zitat hinzu.",
"/quote: Gibt zufälliges Zitat aus.",
"/delquote [Zitat]: Löscht das Zitat (nur Superuser)"
"/delquote [Zitat]: Löscht das Zitat (nur Superuser)",
"/listsquotes: Listet alle Zitate auf"
},
patterns = {
"^/(delquote) (.+)$",
"^/(addquote) (.+)$",
"^/quote$"
"^/(quote)$",
"^/(listquotes)$"
},
run = run
}