+if ($between = getBetween(reveal($message ?? ''), '[taskid]')) {
+ $dt = new DateTimeImmutable();
+ $mondays = [
+ (int)(new DateTimeImmutable('first monday of this month'))->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'),
+ ];
+ $closestMonday = closest($dt->format('d'), $mondays);
+ $completedTasksFile = getFilePathForWeek((int)$dt->format('Y'), (int)$dt->format('n'), array_search($closestMonday, $mondays));
+ $completedTasks = file_exists($completedTasksFile) ? lines(trim(file_get_contents($completedTasksFile))) : [];
+ $currentWeekOfMonth = array_search($closestMonday, $mondays);
+ $tasksForTheWeek = getTasksForTheWeek(
+ $currentWeekOfMonth,
+ (int)$dt->format('m'),
+ require 'taskMatrix.php'
+ );
+
+ $chatid = getTelegram()->getWebhookUpdates()->get('message')->get('chat')->get('id');
+
+ if (!is_dir(dirname($completedTasksFile))) {
+ mkdir(dirname($completedTasksFile), 0777, true);
+ }
+
+ if (in_array($between, $completedTasks)) {
+ getTelegram()->sendMessage([
+ 'chat_id' => $chatid,
+ 'text' => getString('taskAlreadyCompleted')
+ ]);
+ return;
+ }
+
+ if (!in_array($between, $tasksForTheWeek)) {
+ getTelegram()->sendMessage([
+ 'chat_id' => $chatid,
+ 'text' => getString('unknownTask')
+ ]);
+ return;
+ }
+
+ file_put_contents(
+ $completedTasksFile,
+ "$between\n",
+ FILE_APPEND
+ );
+
+ getTelegram()->sendMessage([
+ 'chat_id' => $chatid,
+ 'text' => getString('taskCompleted'),
+ 'reply_markup' => json_encode(['remove_keyboard' => true])
+ ]);
+
+ getTelegram()->sendSticker([
+ 'chat_id' => $chatid,
+ 'sticker' => 'CAADBQADOgAD__7RBxFhadMBV3g5Ag'
+ ]);
+
+ if (!array_diff($completedTasks, $tasksForTheWeek)) {
+ getTelegram()->sendMessage([
+ 'chat_id' => $chatid,
+ 'text' => getString('heyTasksAllCompleted')
+ ]);
+ }
+}
+