Changeset 2150

Show
Ignore:
Timestamp:
01/29/07 17:22:46
Author:
miyagawa
Message:

some output modification. Added calc code

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • POE-Component-Client-Lingr/trunk/eg/connect.pl

    r2148 r2150  
    4545    warn "Occupants:\n"; 
    4646    for my $occupant (@{$event->{occupants} || []}) { 
    47         warn "  ", ($occupant->{nickname} || "(anonymous)"), ($occupant->{client_type} eq 'automaton' ? '*' : ''), "\n"; 
     47        my $nick = $occupant->{nickname} || "(anonymous)"; 
     48        if ($occupant->{client_type} eq 'automaton') { 
     49            $nick = "($nick)"; 
     50        } 
     51        warn "  $nick\n"; 
    4852    } 
    4953    $heap->{room} = $event->{room}; 
     
    5559    for my $msg (@{$event->{messages} || []}) { 
    5660        warn "$msg->{nickname}: $msg->{text} ($msg->{timestamp})\n"; 
     61 
     62        # Homework: make this pluggable 
     63        if ($msg->{text} =~ m!^calc: (.*)!) { 
     64            eval { 
     65                require WWW::Google::Calculator; 
     66                my $answer = WWW::Google::Calculator->new->calc($1); # xxx blocks! 
     67                $kernel->post(lingr => call => 'room.say', { message => $answer }); 
     68            }; 
     69            warn $@ if $@; 
     70        } 
    5771    } 
    5872}