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* __: Gibt spezifischen Geburtstag aus *]]..config.cmd_pat..[[setbd* __ __: Speichert Geburtstag ein *]]..config.cmd_pat..[[setbd* __ _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 = 'Geburtstagsliste:\n'..birthday:list_variables(msg) end end utilities.send_reply(msg, text, 'HTML') end return birthday