Add function to get message sender ID
[SonOfLokstallBot.git] / tasks.php
1 <?php declare(strict_types=1);
2
3 require_once('common.php');
4
5 $taskMatrix = require 'taskMatrix.php';
6 $mondays = [
7 (int)(new DateTimeImmutable('first monday of this month'))->format('d'),
8 (int)(new DateTimeImmutable('second monday of this month'))->format('d'),
9 (int)(new DateTimeImmutable('third monday of this month'))->format('d'),
10 (int)(new DateTimeImmutable('fourth monday of this month'))->format('d'),
11 ];
12 $currentMonth = (int)(new DateTimeImmutable())->format('m');
13 $currentDayOfMonth = closest((new DateTimeImmutable())->format('d'), $mondays);
14 $currentWeekOfMonth = array_search($currentDayOfMonth, $mondays);
15
16 $taskLists = array_merge(
17 isStartOfSeason($currentMonth, $currentDayOfMonth) ? [unlines(map(getStringAndCode)(getTasksForTheSeason(getSeason($currentMonth), $taskMatrix)))] : [],
18 isStartOfMonth($currentDayOfMonth) ? [unlines(map(getStringAndCode)(getTasksForTheMonth($currentMonth, $taskMatrix)))] : [],
19 [unlines(map(getStringAndCode)(getTasksForTheWeek($currentWeekOfMonth, $currentMonth, $taskMatrix)))]
20 );
21
22 $taskMessages = [
23 [getString('happyMonday')],
24 [
25 [getString('beginningOf'. ucfirst(getMonthName($currentMonth))), getString('thisMonthThereAre', count(getTasksForTheMonth($currentMonth, $taskMatrix)))],
26 getString('anywayHeresTheWeek')
27 ],
28 [
29 getString('beginningOf' . ucfirst(getSeason($currentMonth))),
30 [getString('anywayHeresTheMonth'), getString('thisMonthThereAre', count(getTasksForTheMonth($currentMonth, $taskMatrix)))],
31 getString('finallyHeresTheWeek')
32 ]
33 ];
34
35 $messages = zipWith(
36 function($message, $list) {
37 return ununlines(
38 array_merge(
39 is_array($message) ? $message : [$message],
40 [$list]
41 )
42 );
43 },
44 // Magic. startOfSeason implies startofMonth so we get 2, start of month without start of season gives 1 and
45 // a regular week (not the start of a season or month) gives 0. And this is how the indicies are ordered in the array.
46 $taskMessages[isStartOfSeason($currentMonth, $currentDayOfMonth) + isStartOfMonth($currentDayOfMonth)],
47 $taskLists
48 );
49
50 foreach ($messages as $message) {
51 sendToGroupChat($message);
52 sleep(rand(2,4));
53 }