# Type: Input and output # Category: Configuration # Description: Shows user's configuration # Author: Andriy Lesyuk use Orangutan::User; new Orangutan::Context( response => sub { my ($context, $user, $message) = @_; my @result = ( ); # All configuration my @regexps = ( '(?:(?:Show|give|list) )?(?:(?:my|the|([^ ]+?)(?:\'s)?) )?config(?:uration)?(?: options)?!*\.*', 'What(?:\'s| is| are) (?:(?:my|the|([^ ]+?)(?:\'s)?) )?config(?:uration)?(?: options)?\?*!*\.*', '(?:(?:Show|give|list) )?(?:the )?config(?:uration)?(?: options)? of ([^ ]+)!*\.*', 'What(?:\'s| is| are) (?:the )?config(?:uration)?(?: options)? of ([^ ]+)\?*!*\.*' ); foreach my $regexp (@regexps) { if ($message =~ /^$regexp$/i) { push(@result, 1); push(@result, $1); last; } } # Show project of user if (scalar @result == 0) { @regexps = ( '(?:(?:Show|give) )?(?:(?:main|primary|default) )?(project|issue|activity)(?: of ([^ ]+?))?!*\.*', 'What(?:\'| i)s (?:(?:main|primary|default) )?(project|issue|activity)(?: of ([^ ]+?))?\?*!*\.*' ); foreach my $regexp (@regexps) { if ($message =~ /^$regexp$/i) { push(@result, 2); push(@result, $2); push(@result, $1); last; } } } # Show user's project if (scalar @result == 0) { @regexps = ( '(?:(?:Show|give) )?(?:(?:my|the|([^ ]+?)(?:\'s)?) )?(?:(?:main|primary|default) )?(project|issue|activity)!*\.*', 'What(?:\'| i)s (?:(?:my|the|([^ ]+?)(?:\'s)?) )?(?:(?:main|primary|default) )?(project|issue|activity)\?*!*\.*' ); foreach my $regexp (@regexps) { if ($message =~ /^$regexp$/i) { push(@result, 2); push(@result, $1); push(@result, $2); last; } } } # Work day start/end time if (scalar @result == 0) { @regexps = ( 'When (?:do )?(?:I|([^ ]+)) (?:(start|begin)|(stop))(?:s)? (?:to )?'. '(?:work|do)(?:ing)?(?: (?:(?:my|his|her) )?job)?\?*!*\.*', 'When (?:does )?(?:(?:my|the|([^ ]+?)(?:\'s)?) )?(?:work(?:ing)? )?(?:day|time) (?:(start|begin)|(end))s?\?*!*\.*', 'When (?:do )?(?:work(?:ing)? )?(?:day|time) of ([^ ]+) (?:(start|begin)|(end))s\?*!*\.*' ); foreach my $regexp (@regexps) { if ($message =~ /^$regexp$/i) { push(@result, 3); push(@result, $1); if (defined($2)) { push(@result, 'start'); } else { push(@result, 'end'); } last; } } } # Work day length if (scalar @result == 0) { @regexps = ( 'How (?:many hours|much time) (?:(?:do|should|must) )?(?:I|([^ ]+)) work(?: per day)?\?*!*\.*', 'How long (?:do )?(?:(?:my|the|([^ ]+?)(?:\'s)?) )?(?:work(?:ing)? )?day lasts\?*!*\.*' ); foreach my $regexp (@regexps) { if ($message =~ /^$regexp$/i) { push(@result, 4); push(@result, $1); last; } } } # Working week days if (scalar @result == 0) { @regexps = ( '(?:Show|give|list)(?: me)?(?: list of)? (?:(?:my|the|([^ ]+?)(?:\'s)?) )?work(?:ing)? (?:week ?-? ?)?days!*\.*', '(?:Which|what) (?:week ?-? ?)?days (?:(?:should|must|do) )?(?:I|([^ ]+))(?: (?:should|must))? work(?: on)?\?*!*\.*' ); foreach my $regexp (@regexps) { if ($message =~ /^$regexp$/i) { push(@result, 5); push(@result, $1); last; } } } return @result; }, handler => sub { my ($context, $creator, $item, $username, $option) = @_; my $user; if (!defined($username) || ($username eq $creator->GetJID) || ($username eq $creator->GetJabberUserID) || ($username eq $creator->GetLogin)) { $user = $creator; } elsif (!$creator->IsCreator) { if (defined($user = $main::users->GetUser($username))) { $creator->SendMessage([ "Hm... I can't show you configuration of another user!", "Why do you care?.. Sorry, but I won't do this!", 'Ask user!' ]); } else { $creator->SendMessage([ "I don't understand what do you want from me...", 'You might make a mistake in the request...', 'Not sure what does this mean...' ]); } return; } else { if (!defined($user = $main::users->GetUser($username))) { $creator->SendMessage([ 'No such user or not yet registered in Orangutan...', 'I guess you made a mistake in username...', 'The user does not exits.' ]); return; } } my $message; # All configuration if ($item == 1) { if ($user->GetJID eq $creator->GetJID) { $message = Orangutan::Context::Random( 'Your configuration options are', 'Here is your configuration', 'Your configuration is' ); } else { $message = Orangutan::Context::Random( 'This user configured me in the following way', 'The configuration of the user is', "User's configuration is" ); } $message .= ":\n"; $message .= 'Login: '.$user->GetLogin."\n"; $message .= 'Jabber ID: '.$user->GetJID."\n"; $message .= 'Default project: '; if ($user->GetProject) { $message .= $user->GetProject; } else { $message .= 'none'; } $message .= "\n"; $message .= 'Default issue: '; if ($user->GetIssue) { my $issue = $main::query->GetIssue($user->GetIssue); if ($issue) { utf8::decode($issue->{'subject'}); $message .= $issue->{'tracker_name'}.' #'.$user->GetIssue.' - '.$issue->{'subject'}; } else { $message .= '#'.$user->GetIssue; } } else { $message .= 'none'; } $message .= "\n"; $message .= 'Default activity: '; if ($user->GetActivity) { $message .= $user->GetActivity; } else { $message .= 'none'; } $message .= "\n"; $message .= 'Work time: '; $message .= sprintf("%02d:00 - %02d:00", $user->GetWorkTimeStart, $user->GetWorkTimeEnd); $message .= ' ('.$user->GetWorkTimeHours.' hours)'; $message .= "\n"; $message .= 'Work days: '; for (my $i = 0; $i < scalar @{$user->{'workdays'}}; $i++) { if ($i > 0) { if (($i > 1) && ($i == $#{$user->{'workdays'}})) { $message .= ' and '; } else { $message .= ', '; } } $message .= $Orangutan::Date::weekdays_short[$user->{'workdays'}[$i]]; } if ($user->GetJID eq $creator->GetJID) { $username = 'you'; } else { $username = Orangutan::Context::Random('this user', 'the user', 'user'); } if ($user->IsSet(USER_NOASKTASK)) { $message .= "\n"; my $format = Orangutan::Context::Random( 'I should not ever ask %s to tell me tasks.', 'I should not ask %s to enter tasks.', 'I may not ask %s to enter tasks.' ); $message .= sprintf($format, $username); } if ($user->IsSet(USER_NONOTIFY)) { $message .= "\n"; my $format = Orangutan::Context::Random( 'I should not notify %s about new issues, changes in issues etc.', 'I may not tell %s about any changes in issues etc.' ); $message .= sprintf($format, $username); } # Project, issue and activity } elsif ($item == 2) { my $empty = 0; if (lc($option) eq 'project') { if (!$user->GetProject) { $empty = 1; } } elsif (lc($option) eq 'issue') { if (!$user->GetIssue) { $empty = 1; } } else { if (!$user->GetActivity) { $empty = 1; } } if ($empty) { if ($user->GetJID eq $creator->GetJID) { $message = 'You'; } else { $message = "User"; } $message .= ' did not '; $message .= Orangutan::Context::Random('set', 'select', 'specify').' '; $message .= Orangutan::Context::Random('default', 'primary', 'main').' '; $message .= lc($option); $message .= '...'; } else { if ($user->GetJID eq $creator->GetJID) { $message = 'Your'; } else { $message = "User's"; } $message .= ' '.Orangutan::Context::Random('default', 'primary', 'main').' '; $message .= lc($option); $message .= " is "; if (lc($option) eq 'project') { $message .= $user->GetProject; } elsif (lc($option) eq 'issue') { my $issue = $main::query->GetIssue($user->GetIssue); if ($issue) { utf8::decode($issue->{'subject'}); $message .= $issue->{'tracker_name'}.' #'.$user->GetIssue.': '.$issue->{'subject'}; } else { $message .= '#'.$user->GetIssue; } } else { $message .= $user->GetActivity; } $message .= '.'; } # Work day start and end times } elsif ($item == 3) { if ($user->GetJID eq $creator->GetJID) { $message = 'Your'; } else { $message = "User's"; } $message .= ' '.Orangutan::Context::Random('work day', 'work time', 'working day'); $message .= ' '.$option.'s at '; $message .= sprintf("%02d:00", ($option eq 'start') ? $user->GetWorkTimeStart : $user->GetWorkTimeEnd); $message .= '.'; # Work day length } elsif ($item == 4) { if ($user->GetJID eq $creator->GetJID) { $message = 'You'; } else { $message = "User"; } $message .= ' should work '.$user->GetWorkTimeHours.' hours per day.'; # Working week days } else { if ($user->GetJID eq $creator->GetJID) { $message = Orangutan::Context::Random( 'You should work on ', 'You work on ', '' ); } else { $message = Orangutan::Context::Random( 'User should work on ', 'User works on ', '' ); } for (my $i = 0; $i < scalar @{$user->{'workdays'}}; $i++) { if ($i > 0) { if (($i > 1) && ($i == $#{$user->{'workdays'}})) { $message .= ' and '; } else { $message .= ', '; } } $message .= $Orangutan::Date::weekdays[$user->{'workdays'}[$i]]; } $message .= '.'; } $creator->SendMessage($message); }, help => { title => 'How can I check my current configuration?', question => '^(?:How )?(?:(?:can|do) I |to )(?:check|see|know|get) (?:(?:my|the) )?(?:current )?configuration\?*!*\.*$', answer => "Forgot configuration you specified some time ago? ". "Just ask Orangutan to show it to you. ". "Orangutan is able to show all configuration options or just a certain configuration option in one message.\n". "Sample queries to get all configuration options:\n". " o List my configuration options\n". " o What is my configuration?\n". " o Show my configuration\n". " o Configuration\n". "Sample queries to get certain options:\n". " o Show main project\n". " o Show main issue\n". " o Show main activity\n". " o When does my work day start?\n". " o When does my work day end?\n". " o How many hours should I work per day?\n". " o Show my working week days\n", weight => 100 }, weight => 90 ); # kate: syntax perl