# Type: Input # Category: Aliases # Description: Shows aliases set by a user # Author: Andriy Lesyuk new Orangutan::Context( response => [ '^(?:(?:Show|list)(?: me)? )?(?:(?:my|the) )?aliases!*\.*$', '^What are (?:(?:my|the) )?aliases\?*!*\.*$' ], handler => sub { my ($context, $user, $item) = @_; my $aliases = $user->GetResponse('Aliases'); if ($aliases) { my $list = $aliases->GetField('aliases'); if ($list) { my %readable = ( ); foreach my $alias (keys %{$list}) { if ($alias =~ /^(\Q(\A| )\E|\^)(.+)(?:\Q( |\Z)\E|\$)$/) { my ($whole, $string) = ($1, $2); $string =~ s/\\(.)/$1/g; $readable{$alias} = { alias => $string, text => $list->{$alias}, whole => ($whole eq '^') ? 1 : 0 }; } } my $message = Orangutan::Context::Random( 'These are your aliases', 'So your aliases are', 'Here they go' ); $message .= sprintf(" (%d)", scalar keys %readable); $message .= ":\n"; foreach my $alias (sort { lc($readable{$a}->{'alias'}) cmp lc($readable{$b}->{'alias'}) } keys %readable) { $message .= ' o '; $message .= '"'.$readable{$alias}->{'alias'}.'"'; $message .= ' => '; $message .= '"'.$readable{$alias}->{'text'}.'"'; if (!$readable{$alias}->{'whole'}) { $message .= ' (substring)'; } $message .= "\n"; } $user->SendMessage($message); } else { $user->SendMessage([ 'You have not set any...', 'Nothing to show...', 'No aliases!' ]); } } else { $user->SendMessage([ 'Seems I forgot what are aliases... :S', 'Oops... What are aliases?.. :S', "Seems I'm contused..." ]); } }, help => { title => 'How can I list aliases?', question => '^(?:How )?(?:(?:can|do) I |to )(?:list|check) (?:(?:my|the) )?aliases\?*!*\.*$', answer => "You can ask Orangutan to show your aliases.\n". "Sample queries:\n". " o What are aliases?\n". " o Show aliases\n". " o Aliases\n". "If an alias contains (substring) this means that it is used for a part of a message...", weight => 1220 } ); # kate: syntax perl