# Type: Input # Category: Task # Description: Shows list of projects # Author: Andriy Lesyuk new Orangutan::Context( response => [ '^(?:Give|show)(?: me)? list of (?:sub)?projects(?: (?:for|on|in|under|of) ["\']?(.+?)["\']?)?!*\.*$', '^(?:Show|list)(?: me)? (?:sub)?projects(?: (?:for|on|in|under|of) ["\']?(.+?)["\']?)?!*\.*$', '^What are (?:sub)?projects(?: (?:for|on|in|under|of) ["\']?(.+?)["\']?)?\?*!*\.*$' ], handler => sub { my ($context, $user, $item, $project) = @_; my $projectid = undef; if (defined($project)) { $projectid = $main::query->ProjectExists($project); if (!defined($projectid)) { $user->SendMessage([ "Hm... I can't find such project...", 'Wow! Some new project perhaps.', 'No such project...' ]); return; } } if ($main::query->GetProjects($projectid->{'id'})) { my $message = Orangutan::Context::Random( 'I know about the following projects', 'Known projects are', 'Here they go' ); $message .= ":\n"; my $count = 1; while (defined(my $subproject = $main::query->Next)) { $message .= $count.') '; $message .= $subproject->{'project'}; if ($subproject->{'subprojects'} > 0) { $message .= ' ('.$subproject->{'subprojects'}.' subprojects)'; } if (!defined($subproject->{'end_time'})) { my $new = Orangutan::Context::Random( 'nothing was done', 'no jobs ever' ); $message .= ' ('.$new.')'; } elsif ((time - $subproject->{'end_time'}) > (30 * 86400)) { my $old = Orangutan::Context::Random( 'no one worked recently', 'no recent jobs', 'old' ); $message .= ' ('.$old.')'; } $message .= "\n"; $count++; } $user->SendMessage($message); } else { if (defined($projectid)) { $user->SendMessage([ ':S This project does not have subprojects...', 'No subprojects for this project' ]); } else { $user->SendMessage([ ":S No known projects... Perhaps I'm going crazy...", 'Help! I forgot all projects...' ]); } } }, help => { title => 'How can I list projects?', question => '^(?:How )?(?:(?:can|do) I |to )(?:list|know) project(?: name)?s\?*!*\.*$', answer => "If you are not sure what is the correct project name ask Orangutan to list projects. ". "You can specify a parent project name to list only subprojects.\n". "Samples:\n". " o List subprojects for Orangutan\n". " o What are projects of Orangutan\n". " o Show projects", weight => 830 } ); # kate: syntax perl