format('d'), (int)(new DateTimeImmutable('second monday of this month'))->format('d'), (int)(new DateTimeImmutable('third monday of this month'))->format('d'), (int)(new DateTimeImmutable('fourth monday of this month'))->format('d'), ]; $currentMonth = (new DateTimeImmutable())->format('m'); $currentDayOfMonth = closest((new DateTimeImmutable())->format('d'), $mondays); $currentWeekOfMonth = array_search($currentDayOfMonth, $mondays); $taskLists = array_merge( isStartOfSeason($currentMonth, $currentDayOfMonth) ? [unlines(map(getString)(getTasksForTheSeason(getSeason($currentMonth), $taskMatrix)))] : [], isStartOfMonth($currentDayOfMonth) ? [unlines(map(getString)(getTasksForTheMonth($currentMonth, $taskMatrix)))] : [], [unlines(map(getString)(getTasksForTheWeek($currentWeekOfMonth, $currentMonth, $taskMatrix)))] ); $taskMessages = [ [getString('happyMonday')], [ [getString('beginningOf'. ucfirst(getMonthName($currentMonth))), getString('thisMonthThereAre', count(getTasksForTheMonth($currentMonth, $taskMatrix)))], getString('anywayHeresTheWeek') ], [ getString('beginningOf' . ucfirst(getSeason($currentMonth))), [getString('anywayHeresTheMonth'), getString('thisMonthThereAre', count(getTasksForTheMonth($currentMonth, $taskMatrix)))], getString('finallyHeresTheWeek') ] ]; $messages = zipWith( function($message, $list) { return ununlines( array_merge( is_array($message) ? $message : [$message], [$list] ) ); }, // Magic. startOfSeason implis startofMonth so we get 2, start of month without start of season gives 1 and // a regular week (not the start of a season or month) gives 0. And this is how the indicies are ordered in the array. $taskMessages[isStartOfSeason($currentMonth, $currentDayOfMonth) + isStartOfMonth($currentDayOfMonth)], $taskLists ); foreach ($messages as $message) { sendToGroupChat($message); sleep(rand(2,4)); } $seasonalMemes = [ 'summer' => ['https://www.youtube.com/watch?v=NqktmrKB3ko'] ]; if (isStartOfSeason($currentMonth, $currentDayOfMonth)) { sendToGroupChat(getString('seasonalMeme', $seasonalMemes[getSeason($currentMonth)][array_rand($seasonalMemes[getSeason($currentMonth)])])); }