From 61b7dd33b6761d3f31b07839b54a3ceedce8b640 Mon Sep 17 00:00:00 2001 From: jesopo Date: Mon, 6 May 2019 14:54:45 +0100 Subject: [PATCH] Add !birthdays command to show birthdays today --- modules/birthday.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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")