# Type: Input # Category: Admin # Description: Shows contexts of an user # Author: Andriy Lesyuk new Orangutan::Context( response => [ '^(?:Please )?show (?:(?:my|(.+?)(?:\'s)?) )?contexts!*\.*$', '^(?:Please )?show contexts of (?:the )?user [\'"]?(.+?)[\'"]?!*\.*$' ], handler => sub { my ($context, $creator, $item, $user) = @_; if ($creator->IsCreator) { my $time = time; if (!defined($user)) { $user = $creator; } else { if (!defined($user = $main::users->GetUser($user))) { $creator->SendMessage('Hm... Cannot find such user. Sorry!'); return; } } my $number; my $message = "Ok... Here they go:\n"; $message .= "Filters:\n"; $number = 1; foreach my $id (sort { $user->{'contexts'}->{'filter'}->{$a}[0] <=> $user->{'contexts'}->{'filter'}->{$b}[0] } keys %{$user->{'contexts'}->{'filter'}}) { my $weight = $user->{'contexts'}->{'in'}->{$id}[0]; if ($number > 1) { $message .= "; "; } $message .= "$number) $id"; if ($weight) { $message .= " [$weight]"; } $number++; } if ($number > 1) { $message .= ".\n"; } $message .= "Output contexts:\n"; $number = 1; foreach my $id (sort { $user->{'contexts'}->{'out'}->{$a}[0] <=> $user->{'contexts'}->{'out'}->{$b}[0] } keys %{$user->{'contexts'}->{'out'}}) { my $weight = $user->{'contexts'}->{'out'}->{$id}[0]; if ($number > 1) { $message .= "; "; } $message .= "$number) $id"; if ($weight) { $message .= " [$weight]"; } my $delay = $user->{'contexts'}->{'out'}->{$id}[1]->GetDelay; if ($delay && ($delay > $time)) { my ($sec, $min, $hour) = (localtime($delay))[0..2]; $message .= sprintf(' (%02d:%02d:%02d)', $hour, $min, $sec); } $number++; } if ($number > 1) { $message .= ".\n"; } $message .= "Input contexts:\n"; $number = 1; foreach my $id (sort { $user->{'contexts'}->{'in'}->{$a}[0] <=> $user->{'contexts'}->{'in'}->{$b}[0] } keys %{$user->{'contexts'}->{'in'}}) { my $weight = $user->{'contexts'}->{'in'}->{$id}[0]; if ($number > 1) { $message .= "; "; } $message .= "$number) $id"; if ($weight) { $message .= " [$weight]"; } my $timeout = $user->{'contexts'}->{'in'}->{$id}[1]->GetTimeout; if ($timeout && ($timeout > $time)) { my ($sec, $min, $hour) = (localtime($timeout))[0..2]; $message .= sprintf(' (%02d:%02d:%02d)', $hour, $min, $sec); } $number++; } if ($number > 1) { $message .= "."; } $creator->SendMessage($message); } else { $creator->SendMessage([ 'Dream about!..', "Sorry, I can't - you are not my creator!..", 'What is this?..', 'Maybe next time...' ]); } }, weight => -50 ); # kate: syntax perl