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/birthday_set.lua

53 lines
1.2 KiB
Lua
Raw Permalink Normal View History

2016-07-07 21:34:32 +02:00
do
2015-11-12 17:42:03 +01:00
local function save_value(msg, name, value)
if (not name or not value) then
return "Benutzung: #setbd [Name] [Tag. Monat]"
2015-11-12 17:42:03 +01:00
end
local hash = 'telegram:birthdays'
if hash then
2016-07-07 21:34:32 +02:00
print('Speicher Geburtstag in '..hash)
2015-11-12 17:42:03 +01:00
redis:hset(hash, name, value)
return "Geburtstag von "..name.." am "..value.." gespeichert!"
end
end
local function delete_value(msg, name)
local hash = 'telegram:birthdays'
if redis:hexists(hash, name) == true then
2016-07-07 21:34:32 +02:00
print('Lösche Geburtstag aus '..hash)
2015-11-12 17:42:03 +01:00
redis:hdel(hash, name)
return 'Geburtstag von "'..name..'" erfolgreich gelöscht!'
else
2016-07-07 21:34:32 +02:00
return 'Du kannst keinen Geburtstag löschen, der nicht existiert.'
2015-11-12 17:42:03 +01:00
end
end
local function run(msg, matches)
local name = string.sub(matches[1], 1, 50)
local value = string.sub(matches[2], 1, 1000)
if value == "nil" then
text = delete_value(msg, name, value)
else
text = save_value(msg, name, value)
end
return text
end
return {
description = "Speichert Geburtstage.",
usage = {
"#setbd [Name] [Tag. Monat]: Speichert ein Geburtstag.",
"#setbd (Name) nil: Löscht Geburtstag"
2015-11-12 17:42:03 +01:00
},
patterns = {
2016-07-07 21:34:32 +02:00
"^#[Ss][Ee][Tt][Bb][Dd] ([^%s]+) (.+)$"
2015-11-12 17:42:03 +01:00
},
run = run
2016-07-07 21:34:32 +02:00
}
--by Akamaru [https://ponywave.de]
end