# Type: Input # Category: Task # Description: Allows to continue working on the previous task # Copied: No # Author: Andriy Lesyuk new Orangutan::Context( response => [ '^(?:Continue|resume|reopen)(?: (?:(?:my|the) )?(?:(?:previous|last) )?task)?'. '(?: (?:at|on|from|since) ([0-9]{1,2}(?:[:-][0-9]{2})? *(?:(?:a\.?|p\.?)m\.?)?))?!*\.*$', '^(?:I )?start(?:ed)?(?:(?: (?:to )?work(?:ing)? on)? (?:(?:my|the) )?(?:(?:previous|last) )?task)?'. '(?: (?:at|on|from|since) ([0-9]{1,2}(?:[:-][0-9]{2})? *(?:(?:a\.?|p\.?)m\.?)?))?!*\.*$' ], handler => sub { my ($context, $user, $item, $time) = @_; my $task = $user->GetTask; if ($task) { my $unfinished = $user->GetResponse('UnfinishedTask'); if ($unfinished) { $user->SendMessage([ 'Just answer "Break" on my previous question... You will achieve the same effect.', 'To achieve the same effect you can answer "Break" on my previous question...', 'You must make a decision about your current task first... You can break it.' ]); } else { $user->SendMessage([ 'I would need to replace the current task to do this...', 'But you are working on another task right now...', 'You are already working on some task!' ]); } return; } my $last = $user->GetLast; if ($last) { $task = new Orangutan::Task($last); if ($time) { my $date = new Orangutan::Date($time); if ($date) { if ($date->Date < $last->GetEnd->Date) { $user->SendMessage([ "Sorry, but you want it to start before the previous task ends!.. I can't do this!", 'The time you specified conflicts with your previous task.', 'The time you specified is incorrect! Please fix it!' ]); return; } if ((time - $date->Date) > 72000) { my $format = Orangutan::Context::Random( 'As I understand the time is %s, %s %d %02d:%02d...', 'Getting time as %s, %s %d %02d:%02d...' ); my ($min, $hour, $mday, $mon, $year, $wday) = (localtime($date->Date))[1..6]; $user->SendMessage(sprintf($format, $Orangutan::Date::weekdays[$wday], $Orangutan::Date::months[$mon], $mday, $hour, $min)); } my $elapsed = int($date->Elapsed / 3600); if ($elapsed > 9) { $format = Orangutan::Context::Random( 'You work %d hours... I hope you will have a rest soon...', 'Hm... I believe you should get a rest...', 'Cool! You work %d hours...' ); $user->SendMessage(sprintf($format, $elapsed)); } $task->SetStart($date); } else { $user->SendMessage([ 'Time specified is incorrect - please fix it!', 'I believe you have made a mistake in time...', "Can't understand the time you specified..." ]); return; } } else { my $date = new Orangutan::Date; if ($date->Date < $last->GetEnd->Date) { $date->Set($last->GetEnd->Date); } if (($date->Date - time) > 86400) { $user->SendMessage([ 'There is some mess with tasks... Cannot add new one.', "Can't add the task - some internal error...", "I'm not able to add this task..." ]); return; } $task->SetStart($date); } $task->UnsetEnd; $user->SetTask($task); $user->FireEvent('task', 'start', $task); my $message = Orangutan::Context::Random('Ok...', 'Got it!..', 'I see...').' '; $message .= Orangutan::Context::Random( 'Reopening task', 'Resuming task', 'Starting task' ).' "'; $message .= $task->GetName; $message .= '"'; if (defined($time)) { $message .= sprintf(" (start time is %02d:%02d)", $task->GetStart->GetTime); } $message .= '.'; if ($task->GetIssue) { $message .= ' '.Orangutan::Context::Random( 'Issue of the task is', "It's issue is", 'Issue is' ); $message .= ' #'.$task->GetIssue; if (defined($task->GetActivity)) { $message .= ', project is "'; $message .= $task->GetProject; $message .= '"'; $message .= ' and activity is "'; $message .= $task->GetActivity; $message .= '"'; } else { $message .= ' and project is "'; $message .= $task->GetProject; $message .= '"'; } $message .= '.'; } else { $message .= ' '.Orangutan::Context::Random( 'Project of the task is', "It's project is", 'Project is' ).' "'; $message .= $task->GetProject; $message .= '"'; if (defined($task->GetActivity)) { $message .= ' and activity is "'; $message .= $task->GetActivity; $message .= '"'; } $message .= '.'; } $user->SendMessage($message); } else { $user->SendMessage([ "I don't have any information about your previous task.", "Hm... You don't have any previous tasks!", "I can't find any previous task!.. :S" ]); } }, help => { title => 'How can I resume my previous task?', question => '^(?:How )?(?:(?:can|do) I |to )(?:continue|resume|reopen) (?:(?:my|the|a) )?(?:last|previous) task?\?*!*\.*$', answer => "You can reopen your last task if you continue working on it. ". "The reopened task will have the same project, issue and activity. ". "You can optionally specify start time. ". "If no start time is specified the current one will be used.\n". "Samples:\n". " o Resume my last task since 10:00\n". " o Started working on my last task\n". " o Continue the previous task\n". " o Reopen my task\n". " o Continue\n". " o Resume", weight => 650 } ); # kate: syntax perl