# Type: Input # Category: Task # Description: Shows current task # Author: Andriy Lesyuk new Orangutan::Context( response => [ '^(?:What(?:\'s| is)? )?(?:current )?task of ([^ ]+?)(?:(?: right)? now)?\?*!*\.*$', '^What (?:am )?I(?:(?:\'| a)m)? (?:working on|doing)(?:(?: right)? now)?\?*!*\.*$', '^What is ([^ ]+)? (?:working on|doing)(?:(?: right)? now)?\?*!*\.*$', '^Show(?: (?:my|the|([^ ]+?)(?:\'s)?))?(?: current)? task!*\.*$', '^Show(?: current)? task of ([^ ]+?)!*\.*$', '^What(?: do(?:es)?)? (?:I|([^ ]+)?) (?:do|work(?: on)?)(?:(?: right)? now)?\?*!*\.*$', '^(?:What(?:\'s| is)? )?(?:(?:my|the|([^ ]+?)(?:\'s)?) )??(?:current )?task(?:(?: right)? now)?\?*!*\.*$' ], handler => sub { my ($context, $manager, $item, $username) = @_; my $user; if (!defined($username) || ($username eq $manager->GetJID) || ($username eq $manager->GetJabberUserID) || ($username eq $manager->GetLogin)) { $user = $manager; } elsif (!$manager->IsCreator && !$manager->IsManager) { if (defined($user = $main::users->GetUser($username))) { $manager->SendMessage([ 'Yeah... I would do this if I was a very stupid bot... ;)', "Well... I'm not permitted to do this!", 'It is not your business!', 'Dream about!..' ]); } else { $manager->SendMessage([ 'I guess you made a mistake in the request...', "Can't understand your request...", 'I do not get it...' ]); } return; } else { if (!defined($user = $main::users->GetUser($username))) { $manager->SendMessage([ 'I have no information about such user!..', 'I do not know such user...', 'Invalid username!' ]); return; } } my $task = $user->GetTask; if ($task) { my $message; my $name = $task->GetName; if (defined($name)) { if ($user->GetJID eq $manager->GetJID) { $message = Orangutan::Context::Random( 'You are working on "', 'Your task is "' ); } else { $message = Orangutan::Context::Random( 'The user is working on "', "User's task is \"" ); } $message .= $name; $message .= '" since '; } else { if ($user->GetJID eq $manager->GetJID) { $message = 'You are working '; } else { $message = 'The user is working '; } $message .= 'since '; } $message .= sprintf("%02d:%02d", $task->GetStart->GetTime); my $elapsed = $task->GetStart->Elapsed; my $format = ' '.Orangutan::Context::Random( '(that is %d:%02d ago)', '(%d:%02d elapsed)', '(it is %d:%02d)', '(%d:%02d ago)' ); $message .= sprintf($format, int($elapsed / 3600), int(($elapsed % 3600) / 60)); $message .= '.'; my $issue = $task->GetIssue; my $project = $task->GetProject; my $activity = $task->GetActivity; if (defined($issue)) { $message .= ' '.Orangutan::Context::Random( "Task's issue is", 'This task is on', 'It is on issue', 'The issue is' ); $message .= ' #'.$issue; if (defined($activity)) { $message .= ', project is '; $message .= $project; $message .= ' and activity is '; $message .= $activity; } else { $message .= ' and project is '; $message .= $project; } $message .= '.'; } elsif (defined($project)) { $message .= ' '.Orangutan::Context::Random( "Task's project is ", 'The project is ' ); $message .= $project; if (defined($activity)) { $message .= ' and activity is '; $message .= $activity; } $message .= '.'; } $manager->SendMessage($message); } else { if ($user->GetJID eq $manager->GetJID) { $manager->SendMessage([ 'I have no idea what are you working on...', "You don't do anything!..", 'No task!' ]); } else { $manager->SendMessage([ 'I have no idea...', "I don't know...", 'No task!' ]); } } }, help => { title => 'How can I check the current task?', question => [ '^(?:How )?(?:(?:can|do) I |to )(?:check|see|know) what (?:(?:am|do) )?I(?:\'m| am) (?:do|work)(?:ing)?(?: on)?\?*!*\.*$', '^(?:How )?(?:(?:can|do) I |to )(?:check|see|get) (?:(?:my|the) )?(?:current )?task\?*!*\.*$' ], answer => "Just ask Orangutan what you are working on.\n". "Samples:\n". " o What is my current task?\n". " o Show my current task\n". " o What am I doing?\n". " o What do I do?\n". " o Show task", weight => 680 }, weight => 91 ); # kate: syntax perl