Portiere "Stille"

This commit is contained in:
Andreas Bielawski 2016-08-24 22:58:50 +02:00
parent baff2f35f2
commit 39e2333ecf

76
miku/plugins/stille.lua Normal file
View File

@ -0,0 +1,76 @@
local stille = {}
stille.triggers = {
"^/(delstille) (.+)$",
"^/(addstille) (.+)$",
"^*?[Ss][Tt][IiUu][Ll][Ll][Ee].?*?$",
"^/(liststille)$"
}
local stille_hash = 'telegram:stille'
function stille:save_stille(text)
local stille = text:sub(11)
print('Saving stille to redis set '..stille_hash)
redis:sadd(stille_hash, stille)
return '<b>Gespeichert:</b> <i>'..stille..'</i>'
end
function stille:delete_stille(text)
local stille = text:sub(11)
print('Deleting stille from redis set '..stille_hash)
if redis:sismember(stille_hash, stille) == true then
redis:srem(stille_hash, stille)
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" and matches[2] then
utilities.send_reply(msg, stille:save_stille(msg.text), 'HTML')
return
elseif matches[1] == "delstille" and matches[2] then
utilities.send_reply(msg, stille:delete_stille(msg.text), 'HTML')
return
elseif matches[1] == "liststille" then
utilities.send_reply(msg, stille:list_stilles())
return
end
end
return stille