05faa356cc
Portiere: - Saved_text - Spam - Special
58 lines
1.4 KiB
Lua
58 lines
1.4 KiB
Lua
local saved_text = {}
|
|
|
|
saved_text.triggers = {
|
|
"^/(deltext) (.+)$",
|
|
"^/(addtext) (.+)$",
|
|
"^/(listtext)$"
|
|
}
|
|
|
|
local text_hash = 'telegram:savedtext'
|
|
|
|
function saved_text:save_text(text)
|
|
print('Saving stille to redis set '..text_hash)
|
|
redis:sadd(text_hash, text)
|
|
return '<b>Gespeichert:</b> <i>'..text..'</i>'
|
|
end
|
|
|
|
function saved_text:delete_text(text)
|
|
print('Deleting text from redis set '..text_hash)
|
|
if redis:sismember(text_hash, text) == true then
|
|
redis:srem(text_hash, text)
|
|
return 'Text erfolgreich gelöscht!'
|
|
else
|
|
return 'Dieser Text existiert nicht.'
|
|
end
|
|
end
|
|
|
|
function saved_text:list_text()
|
|
print('Getting text from redis set '..text_hash)
|
|
local text_table = redis:smembers(text_hash)
|
|
local text = ""
|
|
for num,stille in pairs(text_table) do
|
|
text = text..num..") "..stille..'\n'
|
|
end
|
|
if not text or text == "" then
|
|
return 'Es wurden noch keine Texte gespeichert.\nSpeichere doch welche mit /addtext [Text]'
|
|
else
|
|
return text
|
|
end
|
|
end
|
|
|
|
function saved_text:action(msg, config, matches)
|
|
if not is_sudo(msg, config) then
|
|
return -- Silent Ignore
|
|
end
|
|
|
|
if matches[1] == "addtext" then
|
|
utilities.send_reply(msg, saved_text:save_text(matches[2]), 'HTML')
|
|
return
|
|
elseif matches[1] == "deltext" then
|
|
utilities.send_reply(msg, saved_text:delete_text(matches[2]), 'HTML')
|
|
return
|
|
elseif matches[1] == "listtext" then
|
|
utilities.send_reply(msg, saved_text:list_text())
|
|
return
|
|
end
|
|
end
|
|
|
|
return saved_text |