Add birthday reminder script
[SonOfLokstallBot.git] / src / birthdays.php
1 <?php declare(strict_types=1);
2
3 require_once('common.php');
4
5 $birthdays = [
6 'Julia' => ['dayMonth' => '0804', 'year' => 1967, 'pronoun' => 'She'],
7 'Linda' => ['dayMonth' => '0705', 'year' => 1968, 'pronoun' => 'She'],
8 'Fiona' => ['dayMonth' => '0112', 'year' => 1970, 'pronoun' => 'She'],
9 'Nicola' => ['dayMonth' => '1705', 'year' => 1999, 'pronoun' => 'She'],
10 'Jacob' => ['dayMonth' => '0502', 'year' => 2001, 'pronoun' => 'He'],
11 'Michael' => ['dayMonth' => '2504', 'year' => 1999, 'pronoun' => 'He'],
12 'Bryce' => ['dayMonth' => '1412', 'year' => 2000, 'pronoun' => 'He'],
13 'Zoe' => ['dayMonth' => '0411', 'year' => 2003, 'pronoun' => 'She'],
14 'Imogen' => ['dayMonth' => '2303', 'year' => 2006, 'pronoun' => 'She'],
15 'Macy' => ['dayMonth' => '0701', 'year' => 2004, 'pronoun' => 'She'],
16 'Jensen' => ['dayMonth' => '1709', 'year' => 2006, 'pronoun' => 'He']
17 ];
18
19 $today = new DateTimeImmutable('now');
20 $todayDayMonth = $today->format('dm');
21 $todayYear = (int)$today->format('Y');
22
23 $birthdaysToday = filter(function($person) use ($todayDayMonth) {
24 return $person['dayMonth'] === $todayDayMonth;
25 })($birthdays);
26
27 $messages = map(function($personName) use ($birthdaysToday, $todayYear) {
28 return 'Today is ' . $personName . '\'s birthday. ' . $birthdaysToday[$personName]['pronoun'] . ' is ' . ($todayYear - $birthdaysToday[$personName]['year']) . '.';
29 })(array_keys($birthdaysToday));
30
31 if ($messages) {
32 sendToGroupChat(ununlines($messages));
33 }