This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot-2/miku/plugins/stille.lua

74 lines
2.0 KiB
Lua
Raw Normal View History

2016-08-24 22:58:50 +02:00
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>'
2016-08-24 22:58:50 +02:00
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)
2016-08-24 22:58:50 +02:00
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')
2016-08-24 22:58:50 +02:00
return
elseif matches[1] == "delstille" then
utilities.send_reply(msg, stille:delete_stille(matches[2]), 'HTML')
2016-08-24 22:58:50 +02:00
return
elseif matches[1] == "liststille" then
utilities.send_reply(msg, stille:list_stilles())
return
end
end
return stille