Random cleanup
[SonOfLokstallBot.git] / src / tasks.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 $taskLists = array_merge(
9 isStartOfSeason($monday->month, $monday->dayNum) ? [unlines(map(getString)(getTasksForTheSeason($monday->season, $taskMatrix)))] : [],
10 isStartOfMonth($monday->dayNum) ? [unlines(map(getString)(getTasksForTheMonth($monday->month, $taskMatrix)))] : [],
11 [unlines(map(getString)(getTasksForTheWeek($monday->year, $monday->month, $monday->weekNum, $taskMatrix)))]
12 );
13
14 $taskMessages = [
15 [getString('happyMonday')],
16 [
17 [getString('beginningOf'. ucfirst(getMonthName($monday->month))), getString('thisMonthThereAre', count(getTasksForTheMonth($monday->month, $taskMatrix)))],
18 getString('anywayHeresTheWeek')
19 ],
20 [
21 getString('beginningOf' . ucfirst($monday->season)),
22 [getString('anywayHeresTheMonth'), getString('thisMonthThereAre', count(getTasksForTheMonth($monday->month, $taskMatrix)))],
23 getString('finallyHeresTheWeek')
24 ]
25 ];
26
27 $messages = zipWith(
28 function($message, $list) {
29 return ununlines(
30 array_merge(
31 is_array($message) ? $message : [$message],
32 [$list]
33 )
34 );
35 },
36 // Magic. startOfSeason implies startofMonth so we get 2, start of month without start of season gives 1 and
37 // a regular week (not the start of a season or month) gives 0. And this is how the indicies are ordered in the array.
38 $taskMessages[(int)isStartOfSeason($monday->month, $monday->dayNum) + (int)isStartOfMonth($monday->dayNum)],
39 $taskLists
40 );
41
42 foreach ($messages as $message) {
43 sendToGroupChat($message);
44 sleep(rand(2,4));
45 }