05faa356cc
Portiere: - Saved_text - Spam - Special
74 lines
2.0 KiB
Lua
74 lines
2.0 KiB
Lua
local stille = {}
|
|
|
|
stille.triggers = {
|
|
"^/(delstille) (.+)$",
|
|
"^/(addstille) (.+)$",
|
|
"^*?[Ss][Tt][IiUu][Ll][Ll][Ee].?*?$",
|
|
"^/(liststille)$"
|
|
}
|
|
|
|
local stille_hash = 'telegram:stille'
|
|
|
|
function stille:save_stille(text)
|
|
print('Saving stille to redis set '..stille_hash)
|
|
redis:sadd(stille_hash, text)
|
|
return '<b>Gespeichert:</b> <i>'..text..'</i>'
|
|
end
|
|
|
|
function stille:delete_stille(text)
|
|
print('Deleting stille from redis set '..stille_hash)
|
|
if redis:sismember(stille_hash, text) == true then
|
|
redis:srem(stille_hash, text)
|
|
return 'Zitat erfolgreich gelöscht!'
|
|
else
|
|
return 'Dieses Zitat existiert nicht.'
|
|
end
|
|
end
|
|
|
|
function stille:get_stille()
|
|
print('Getting stille from redis set '..stille_hash)
|
|
local stille_table = redis:smembers(stille_hash)
|
|
if not stille_table[1] then
|
|
return 'Es wurden noch keine Zitate gespeichert.\nSpeichere doch welche mit /addstille [Zitat]'
|
|
else
|
|
return stille_table[math.random(1,#stille_table)]
|
|
end
|
|
end
|
|
|
|
function stille:list_stilles()
|
|
print('Getting stille from redis set '..stille_hash)
|
|
local stille_table = redis:smembers(stille_hash)
|
|
local text = ""
|
|
for num,stille in pairs(stille_table) do
|
|
text = text..num..") "..stille..'\n'
|
|
end
|
|
if not text or text == "" then
|
|
return 'Es wurden noch keine Zitate gespeichert.\nSpeichere doch welche mit /addstille [Zitat]'
|
|
else
|
|
return text
|
|
end
|
|
end
|
|
|
|
function stille:action(msg, config, matches)
|
|
if msg.text:match('^*?[Ss][Tt][IiUu][Ll][Ll][Ee].?*?$') then
|
|
utilities.send_message(msg.chat.id, stille:get_stille(), true)
|
|
return
|
|
end
|
|
|
|
if not is_sudo(msg, config) then
|
|
return -- Silent Ignore
|
|
end
|
|
|
|
if matches[1] == "addstille" then
|
|
utilities.send_reply(msg, stille:save_stille(matches[2]), 'HTML')
|
|
return
|
|
elseif matches[1] == "delstille" then
|
|
utilities.send_reply(msg, stille:delete_stille(matches[2]), 'HTML')
|
|
return
|
|
elseif matches[1] == "liststille" then
|
|
utilities.send_reply(msg, stille:list_stilles())
|
|
return
|
|
end
|
|
end
|
|
|
|
return stille |