diff options
| author | 2019-05-06 14:54:45 +0100 | |
|---|---|---|
| committer | 2019-05-06 14:54:45 +0100 | |
| commit | 61b7dd33b6761d3f31b07839b54a3ceedce8b640 (patch) | |
| tree | 5acf9a95872620b9f6af1f172991faf115afbd3a | |
| parent | Make birthdays more exciting (diff) | |
| signature | ||
Add !birthdays command to show birthdays today
| -rw-r--r-- | modules/birthday.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/modules/birthday.py b/modules/birthday.py index 226baec2..364bcb4b 100644 --- a/modules/birthday.py +++ b/modules/birthday.py @@ -52,3 +52,24 @@ class Module(ModuleManager.BaseModule): else: event["stderr"].write("No birthday set for %s" % target_user.nickname) + + @utils.hook("received.command.birthdays") + def birthdays(self, event): + birthday_settings = event["server"].get_all_user_settings("birthday") + birthdays = {} + + today = datetime.datetime.utcnow().date() + for nickname, birthday in birthday_settings: + birthday_parsed = _parse(birthday).date() + if birthday_parsed.replace(year=today.year) == today: + birthdays[nickname] = today.year-birthday_parsed.year + if birthdays: + birthdays_str = [] + for nickname, age in birthdays.items(): + nickname = event["server"].get_user(nickname).nickname + birthdays_str.append("%s (%d)" % (nickname, age)) + + event["stdout"].write("Birthdays today: %s" % + ", ".join(birthdays_str)) + else: + event["stdout"].write("There are no birthdays today") |
