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