From 8fda9db16c301c6919d905f3645e3b150d84fb06 Mon Sep 17 00:00:00 2001 From: Cameron Ball Date: Sun, 19 Jan 2020 21:25:08 +0800 Subject: [PATCH] Add birthday reminder script --- src/birthdays.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/birthdays.php diff --git a/src/birthdays.php b/src/birthdays.php new file mode 100644 index 0000000..58e6716 --- /dev/null +++ b/src/birthdays.php @@ -0,0 +1,33 @@ + ['dayMonth' => '0804', 'year' => 1967, 'pronoun' => 'She'], + 'Linda' => ['dayMonth' => '0705', 'year' => 1968, 'pronoun' => 'She'], + 'Fiona' => ['dayMonth' => '0112', 'year' => 1970, 'pronoun' => 'She'], + 'Nicola' => ['dayMonth' => '1705', 'year' => 1999, 'pronoun' => 'She'], + 'Jacob' => ['dayMonth' => '0502', 'year' => 2001, 'pronoun' => 'He'], + 'Michael' => ['dayMonth' => '2504', 'year' => 1999, 'pronoun' => 'He'], + 'Bryce' => ['dayMonth' => '1412', 'year' => 2000, 'pronoun' => 'He'], + 'Zoe' => ['dayMonth' => '0411', 'year' => 2003, 'pronoun' => 'She'], + 'Imogen' => ['dayMonth' => '2303', 'year' => 2006, 'pronoun' => 'She'], + 'Macy' => ['dayMonth' => '0701', 'year' => 2004, 'pronoun' => 'She'], + 'Jensen' => ['dayMonth' => '1709', 'year' => 2006, 'pronoun' => 'He'] +]; + +$today = new DateTimeImmutable('now'); +$todayDayMonth = $today->format('dm'); +$todayYear = (int)$today->format('Y'); + +$birthdaysToday = filter(function($person) use ($todayDayMonth) { + return $person['dayMonth'] === $todayDayMonth; +})($birthdays); + +$messages = map(function($personName) use ($birthdaysToday, $todayYear) { + return 'Today is ' . $personName . '\'s birthday. ' . $birthdaysToday[$personName]['pronoun'] . ' is ' . ($todayYear - $birthdaysToday[$personName]['year']) . '.'; +})(array_keys($birthdaysToday)); + +if ($messages) { + sendToGroupChat(ununlines($messages)); +} -- 2.11.0