Add function to get message sender ID
[SonOfLokstallBot.git] / unfinished.php
1 <?php declare(strict_types=1);
2
3 require_once('common.php');
4
5 $taskMatrix = require 'taskMatrix.php';
6
7 $mondays = [
8 (int)(new DateTimeImmutable('first monday of this month'))->format('d'),
9 (int)(new DateTimeImmutable('second monday of this month'))->format('d'),
10 (int)(new DateTimeImmutable('third monday of this month'))->format('d'),
11 (int)(new DateTimeImmutable('fourth monday of this month'))->format('d'),
12 ];
13
14 $currentMonth = (int)(new DateTimeImmutable())->format('n');
15 $currentDayOfMonth = closest((new DateTimeImmutable())->format('d'), $mondays);
16 $currentSeason = getSeason($currentMonth);
17 $currentYear = (int)(new DateTimeImmutable())->format('Y');
18 $currentWeekOfMonth = array_search($currentDayOfMonth, $mondays);
19
20 $extractTasks = function($tasks, $path) {
21 return array_merge($tasks, file_exists($path) ? lines(trim(file_get_contents($path))) : []);
22 };
23
24 $unfinishedForYear = array_diff(
25 array_merge(...map(
26 function($season) use ($taskMatrix) {
27 return getTasksForTheSeason($season, $taskMatrix);
28 }
29 )(['summer', 'autumn', 'winter', 'spring'])),
30 array_reduce(getFilePathsForYear($currentYear), $extractTasks, [])
31 );
32
33 $unfinishedForSeason = array_diff(
34 getTasksForTheSeason($currentSeason, $taskMatrix),
35 array_reduce(getFilePathsForSeason($currentYear, $currentSeason), $extractTasks, [])
36 );
37
38 $unfinishedForMonth = array_diff(
39 getTasksForTheMonth($currentMonth, $taskMatrix),
40 array_reduce(getFilePathsForMonth($currentYear, $currentMonth), $extractTasks, [])
41 );
42
43 $filePathForWeek = getFilePathForWeek($currentYear, $currentMonth, $currentWeekOfMonth);
44 $unfinishedForWeek = array_diff(
45 getTasksForTheWeek($currentWeekOfMonth, $currentMonth, $taskMatrix),
46 file_exists($filePathForWeek) ? lines(trim(file_get_contents($filePathForWeek))) : []
47 );
48
49 //EOY => (EOM & EOW) & !EOS
50 //EOS => (EOM & EOW) & !EOY
51 $taskLists = array_merge(
52 isEndOfYear($currentYear, $currentMonth, $currentDayOfMonth) ? [unlines(map(getStringAndCode)($unfinishedForYear))] : [],
53 isEndOfSeason($currentYear, $currentMonth, $currentDayOfMonth) ? [unlines(map(getStringAndCode)($unfinishedForSeason))] : [],
54 isEndOfMonth($currentYear, $currentMonth, $currentDayOfMonth) ? [unlines(map(getStringAndCode)($unfinishedForMonth))] : [],
55 [unlines(map(getStringAndCode)($unfinishedForWeek))]
56 );
57
58 $seasonName = ucfirst($currentSeason);
59 $goodOrBad = function($string, $goodOrBad) {
60 return getString($string . ($goodOrBad ? '' : 'Good'));
61 };
62
63 $taskMessages = [
64 [$goodOrBad('endOfWeek', $unfinishedForWeek)],
65 [
66 $goodOrBad('endOfMonth', $unfinishedForMonth),
67 $goodOrBad('andAlsoEndOfWeek', $unfinishedForWeek)
68 ],
69 [
70 $goodOrBad('endOf' . $seasonName, $unfinishedForSeason),
71 $goodOrBad('andAlsoEndOfMonth', $unfinishedForMonth),
72 $goodOrBad('finallyEndOfWeek', $unfinishedForWeek)
73 ],
74 [
75 $goodOrBad('endOfYear', $unfinishedForYear),
76 $goodOrBad('andAlsoEndOfMonth', $unfinishedForMonth),
77 $goodOrBad('finallyEndOfWeek', $unfinishedForWeek)
78 ]
79 ];
80
81 $messages = zipWith(
82 function($message, $list) {
83 return ununlines(
84 array_merge(
85 is_array($message) ? $message : [$message],
86 [$list]
87 )
88 );
89 },
90 // Similar magic to tasks.php
91 $taskMessages[
92 isEndOfMonth($currentYear, $currentMonth, $currentDayOfMonth) +
93 isEndOfSeason($currentYear, $currentMonth, $currentDayOfMonth) +
94 (isEndOfYear($currentYear, $currentMonth, $currentDayOfMonth) ? 2 : 0) // EOY is independant of EOS, to get the right index need to add 2 instead of 1.
95 ],
96 $taskLists
97 );
98
99 foreach ($messages as $message) {
100 sendToGroupChat($message);
101 sleep(rand(2,4));
102 }