return '';
}
+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')
+ ]);
+ }
+}
+
if ($between = getBetween(reveal($message ?? ''), '[billid]')) {
$messages = array_values(array_filter(
getMessagesFromInbox(
$completedTasksFile = getFilePathForWeek($currentYear, $currentMonth, $currentWeekOfMonth);
$completedTasks = file_exists($completedTasksFile) ? lines(trim(file_get_contents($completedTasksFile))) : [];
+ if (!array_diff($tasksForTheWeek, $completedTasks)) {
+ $this->replyWithMessage([
+ 'text' => getString('tasksAllCompleted')
+ ]);
+ return;
+ }
+
$this->replyWithMessage([
'text' => ununlines([
getString('tasksForTheWeek'),
$completedTasks = file_exists($completedTasksFile) ? lines(trim(file_get_contents($completedTasksFile))) : [];
- if (!is_dir(dirname($completedTasksFile))) {
- mkdir(dirname($completedTasksFile), 0777, true);
- }
-
- if (in_array($arguments, $completedTasks)) {
- $this->replyWithMessage(['text' => getString('taskAlreadyCompleted')]);
+ if (!array_diff($completedTasks, $tasksForTheWeek)) {
+ $this->replyWithMessage([
+ 'text' => getString('tasksAllCompleted')
+ ]);
return;
}
- if (!in_array($arguments, $tasksForTheWeek)) {
- $this->replyWithMessage(['text' => getString('unknownTask')]);
- return;
- }
+ $tasks = array_values(map(function($task) {
+ return sprintf('%s%s', hide('[taskid]' . $task . '[taskid]'), getString($task));
+ })(array_diff($tasksForTheWeek, $completedTasks)));
+ $buttons = partition((int)ceil(count($tasks)/3), $tasks);
+ $reply_markup = getTelegram()->replyKeyboardMarkup([
+ 'keyboard' => $buttons,
+ 'resize_keyboard' => true,
+ 'one_time_keyboard' => true,
+ 'selective' => true
+ ]);
- file_put_contents(
- $completedTasksFile,
- "$arguments\n",
- FILE_APPEND
+ $this->replyWithMessage(
+ [
+ 'text' => '[' . getMessageSenderDisplayName($this->getUpdate()) . '](tg://user?id=' . getMessageSenderId($this->getUpdate()) . '), which task did you finish?',
+ 'parse_mode' => 'markdown',
+ 'reply_markup' => $reply_markup
+ ]
);
-
- $this->replyWithMessage(['text' => getString('taskCompleted')]);
}
}
);
'thisMonthThereAre' => 'This month there are %d tasks that need completing (as well as the regular tasks). I\'ll try my best to space them out over the coming weeks. As a heads up, here they are:',
'tasksForTheWeek' => 'Here are the incomplete tasks for this week...',
'taskAlreadyCompleted' => 'Hmm... It looks as though that task was already done this week.',
- 'taskCompleted' => 'Marked as completed, nice one!',
+ 'taskCompleted' => 'Marked as completed!',
'unknownTask' => 'That doesn\'t look like a task I asked you to do this week... Use the listtasks command to see all the tasks.',
+ 'tasksAllCompleted' => 'I have nothing to show you, you\'ve completed all the tasks for this week! Epic.',
+ 'heyTasksAllCompleted' => 'Hey! That was the last task for this week. Good going!',
'rangehoodfilters' => 'Clean the rangehood filters in the kitchen',
'poolwater' => 'Check the level of the pool, and fill if needed',