# Type: Input # Category: Task # Description: Shows list of projects # Author: Andriy Lesyuk new Orangutan::Context( response => [ '^(?:Show|list)(?: me)? activities(?: (?:for|on|of) ["\']?(.+?)["\']?)?!*\.*$', '^What are activities(?: (?:for|on|of) ["\']?(.+?)["\']?)?\?*!*\.*$' ], handler => sub { my ($context, $user, $item, $name) = @_; my $projectid; if (defined($name)) { my $project = $main::query->ProjectExists($name); if ($project) { $projectid = $project->{'id'}; } } else { my $task = $user->GetTask; if ($task) { $projectid = $task->GetProject('id'); if (defined($projectid)) { $user->SendMessage([ 'Assuming you want me to show activities for the project of the current task...', 'You did not specify the project so taking the project of the current task...', 'If talking about the project of the current task...' ]); } } else { $projectid = $user->GetProjectID; } } if (defined($projectid)) { if ($main::query->GetActivities($projectid)) { my $message = Orangutan::Context::Random( 'The project has the following activities', 'The activities of the project are', 'Here they go' ); $message .= ":\n"; my $count = 1; while (defined(my $activity = $main::query->Next)) { $message .= $count.') '; $message .= $activity->{'name'}; $message .= "\n"; $count++; } $user->SendMessage($message); } else { $user->SendMessage([ 'Hm... I cannot find activities for this project.', 'Not a single activity for this project. Weird...', 'No activities for the project' ]); } } else { if (defined($name)) { $user->SendMessage([ "I don't know anything about this project...", 'I have no information about this project.', 'No such project. Sorry.' ]); } else { $user->SendMessage([ 'I do not know for what project you want me to show activities...', 'Please specify the project when asking me to show activities...', 'You must specify the project name...' ]); } } }, help => { title => 'How can I list activities?', question => '^(?:How )?(?:(?:can|do) I |to )(?:list|know) activit(?:y name|ie)?s(?: of (?:(?:the|some) )?project)?\?*!*\.*$', answer => "If you are not sure what is the correct activity name you can ask Orangutan to list activities. ". "If no project name is specified in the request the default one is used.\n". "Samples:\n". " o What are activities of Kayako?\n". " o Show activities for oDesk\n". " o List activities", weight => 850 } ); # kate: syntax perl