Birthday-Plugin hinzugefügt
This commit is contained in:
parent
f8899ae43b
commit
91179a52ba
96
miku/plugins/birthday.lua
Normal file
96
miku/plugins/birthday.lua
Normal file
@ -0,0 +1,96 @@
|
||||
local birthday = {}
|
||||
|
||||
function birthday:init(config)
|
||||
birthday.triggers = {
|
||||
"^/([Ss][Ee][Tt][Bb][Dd]) ([^%s]+) (.+)$",
|
||||
"^/([Gg][Ee][Tt][Bb][Dd]) (.+)$",
|
||||
"^/[Gg][Ee][Tt][Bb][Dd]$"
|
||||
}
|
||||
birthday.doc = [[*
|
||||
]]..config.cmd_pat..[[getbd*: Gibt alle Geburtstage aus
|
||||
*]]..config.cmd_pat..[[getbd* _<Name>_: Gibt spezifischen Geburtstag aus
|
||||
*]]..config.cmd_pat..[[setbd* _<Name>_ _<Tag.Monat>_: Speichert Geburtstag ein
|
||||
*]]..config.cmd_pat..[[setbd* _<Name>_ _nil_: Löscht Geburttag
|
||||
]]
|
||||
end
|
||||
|
||||
birthday.command = 'getbd'
|
||||
|
||||
function birthday:save_value(name, value)
|
||||
if (not name or not value) then
|
||||
return "Benutzung: /setbd [Name] [Tag. Monat]"
|
||||
end
|
||||
|
||||
local hash = 'telegram:birthdays'
|
||||
if hash then
|
||||
print('Speichere Geburtstag in '..hash)
|
||||
redis:hset(hash, name, value)
|
||||
return "Geburtstag von "..name.." am "..value.." gespeichert!"
|
||||
end
|
||||
end
|
||||
|
||||
function birthday:delete_value(name, value)
|
||||
local hash = 'telegram:birthdays'
|
||||
if redis:hexists(hash, name) == true then
|
||||
print('Lösche Geburtstag aus '..hash)
|
||||
redis:hdel(hash, name)
|
||||
return 'Geburtstag von "'..name..'" erfolgreich gelöscht!'
|
||||
else
|
||||
return 'Du kannst keinen Geburtstag löschen, der nicht existiert.'
|
||||
end
|
||||
end
|
||||
|
||||
function birthday:get_value(msg, var_name)
|
||||
local hash = 'telegram:birthdays'
|
||||
if hash then
|
||||
local value = redis:hget(hash, var_name)
|
||||
if not value then
|
||||
return'Geburtstag nicht gefunden, benutze /getbd, um alle Geburtstage aufzulisten.'
|
||||
else
|
||||
return var_name..' hat am '..value..' Geburtstag'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function birthday:list_variables(msg)
|
||||
local hash = 'telegram:birthdays'
|
||||
|
||||
if hash then
|
||||
print('Suche nach Geburtstag in '..hash)
|
||||
local names = redis:hkeys(hash)
|
||||
local text = ''
|
||||
for i=1, #names do
|
||||
variables = birthday:get_value(msg, names[i])
|
||||
text = text..variables.."\n"
|
||||
end
|
||||
if text == '' or text == nil then
|
||||
return 'Keine Geburtstage vorhanden!'
|
||||
else
|
||||
return text
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function birthday:action(msg, config, matches)
|
||||
if matches[1]:match('[Ss][Ee][Tt][Bb][Dd]') then
|
||||
local name = string.sub(matches[2], 1, 50)
|
||||
local value = string.sub(matches[3], 1, 1000)
|
||||
|
||||
if value == "nil" then
|
||||
text = birthday:delete_value(name, value)
|
||||
else
|
||||
text = birthday:save_value(name, value)
|
||||
end
|
||||
|
||||
else
|
||||
if matches[2] then
|
||||
text = birthday:get_value(msg, matches[2])
|
||||
else
|
||||
text = '<b>Geburtstagsliste:</b>\n'..birthday:list_variables(msg)
|
||||
end
|
||||
end
|
||||
|
||||
utilities.send_reply(self, msg, text, 'HTML')
|
||||
end
|
||||
|
||||
return birthday
|
Reference in New Issue
Block a user