Add !birthdays command to show birthdays today
This commit is contained in:
parent
6f9383666f
commit
61b7dd33b6
1 changed files with 21 additions and 0 deletions
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue