Add birthday reminder script
authorCameron Ball <cameron@cameron1729.xyz>
Sun, 19 Jan 2020 13:25:08 +0000 (21:25 +0800)
committerCameron Ball <cameron@cameron1729.xyz>
Sun, 19 Jan 2020 13:26:19 +0000 (21:26 +0800)
src/birthdays.php [new file with mode: 0644]

diff --git a/src/birthdays.php b/src/birthdays.php
new file mode 100644 (file)
index 0000000..58e6716
--- /dev/null
@@ -0,0 +1,33 @@
+<?php declare(strict_types=1);
+
+require_once('common.php');
+
+$birthdays = [
+    'Julia' => ['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));
+}