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/plugins/stille.lua

103 lines
2.5 KiB
Lua

do
local function save_stille(msg)
if msg.text:sub(11):isempty() then
return "Benutzung: #addstille [Zitat]"
end
local stille = msg.text:sub(11)
local hash = 'telegram:stille'
print('Saving stille to redis set '..hash)
redis:sadd(hash, stille)
return 'Gespeichert: "'..stille..'"'
end
local function delete_stille(msg)
if msg.text:sub(11):isempty() then
return "Benutzung: #delstille [Zitat]"
end
local stille = msg.text:sub(11)
local hash = 'telegram:stille'
print('Deleting stille from redis set '..hash)
if redis:sismember(hash, stille) == true then
redis:srem(hash, stille)
return 'Zitat erfolgreich gelöscht!'
else
return 'Dieses Zitat existiert nicht.'
end
end
local function get_stille(msg)
local to_id = tostring(msg.to.id)
local hash = 'telegram:stille'
if hash then
print('Getting stille from redis set '..hash)
local stille_table = redis:smembers(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
end
local function list_stilles(msg)
local hash = 'telegram:stille'
if hash then
print('Getting stille from redis set '..hash)
local stille_table = redis:smembers(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
end
local function run(msg, matches)
if string.match(msg.text, '^*?[Ss][Tt][IiUu][Ll][Ll][Ee].?*?$') then
return get_stille(msg)
elseif matches[1] == "addstille" then
if not is_sudo(msg) then
return "Du kannst diesen Befehl nicht benutzen!"
else
return save_stille(msg)
end
elseif matches[1] == "delstille" then
if not is_sudo(msg) then
return "Du kannst diesen Befehl nicht benutzen!"
else
return delete_stille(msg)
end
elseif matches[1] == "liststille" then
if not is_sudo(msg) then
return "Du kannst diesen Befehl nicht benutzen!"
else
return list_stilles(msg)
end
end
end
return {
description = "Es ist so still hier",
usage = {
"stille: Gibt zufälliges Zitat aus."
},
patterns = {
"^#(delstille) (.+)$",
"^#(addstille) (.+)$",
"^*?[Ss][Tt][IiUu][Ll][Ll][Ee].?*?$",
"^#(liststille)$"
},
run = run
}
end
--by Akamaru [https://ponywave.de]