use strict; use warnings; use Xchat qw(:all); register( "Whois on PM", "1.0", "Whois whoever sends you a message and keep the result in the query window" ); hook_print( "Open Dialog", sub { my $from = get_info "channel"; command "WHOIS $from"; my @whois_events = ( "WhoIs Authenticated", "WhoIs Away Line", "WhoIs Channel/Oper Line", "WhoIs Identified", "WhoIs Idle Line", "WhoIs Idle Line with Signon", "WhoIs Name Line", "WhoIs Real Host", "WhoIs Server Line", "WhoIs Special", ); my %whois_hooks; my $remove_hook = sub { my $event = shift; unhook delete $whois_hooks{$event}; }; my $remove_hooks = sub { for my $event ( keys %whois_hooks ) { $remove_hook->( $event ); } return REMOVE; }; my $context = get_context; my $event_callback = sub { # not the nick we are looking for # nickcmp returns 0 if they are equal return EAT_NONE if nickcmp $from, $_[0][0]; my $evt = $_[1]; if( set_context $context ) { emit_print $evt, @{$_[0]}; return EAT_ALL; } else { # failed to change context, assume the window got closed # do nothing and let the 10s timer remove any remaining hooks return EAT_ALL; } }; for my $event ( @whois_events ) { $whois_hooks{$event} = hook_print $event, $event_callback, { data => $event }; } # remove all hooks when the end of whois is received or after 10 seconds $whois_hooks{ "WhoIs End" } = hook_print "WhoIs End", sub { my $ret = $event_callback->( $_[0], "WhoIs End" ); $remove_hooks->(); return $ret; }; hook_timer 10_000, $remove_hooks; return EAT_NONE; } );