X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=clones.pl;h=c1e0dd950ebc47c5a3666179c6906cbc7a72d2ec;hb=edef44980a97323b66add1052bc737fe1e11975f;hp=5e385959a4b390729152b24c436adf8e91ed7fe4;hpb=00463e42661628d19236d6951afa32315f8f9f32;p=perl%2Fscripts%2Fxchat.git diff --git a/clones.pl b/clones.pl index 5e38595..c1e0dd9 100755 --- a/clones.pl +++ b/clones.pl @@ -10,6 +10,7 @@ use Xchat qw<:all>; use lib get_info 'xchatdir'; use Xchat::XPI; use Xchat::XPI::Events qw; +use Xchat::XPI::Utils qw; use constant { JOIN_DELAY => 1000, @@ -168,11 +169,10 @@ hook_server '315', sub { # WHO end return EAT_NONE if $fetched{$serv}{$chan}; - my $oldctxt = get_context; - set_context $chan, $serv or return EAT_NONE; - fetch $serv, $chan; - scan $serv, $chan; - set_context $oldctxt; + local_context $chan, $serv => sub { + fetch $serv, $chan; + scan $serv, $chan; + }; return EAT_NONE; }; @@ -186,20 +186,16 @@ hook_server 'JOIN', sub { my $chan = lc substr $_[0][2], 1; # starts with colon my $clones = add $nick, host($userhost), $serv, $chan; - if ($clones > 0) { - my $oldctxt = get_context; - if (set_context $chan, $serv) { - print $ph clone_enter_str $userhost, $nick, $clones; - set_context $oldctxt; - } else { - delay JOIN_DELAY, sub { - my $oldctxt = get_context; - return unless set_context $chan, $serv; - print $ph clone_enter_str $userhost, $nick, $clones; - set_context $oldctxt; - }; - } - } + return EAT_NONE unless $clones > 0; + + my $printer = sub { + print $ph clone_enter_str $userhost, $nick, $clones; + 1 + }; + + local_context $chan, $serv, $printer or delay JOIN_DELAY, sub { + local_context $chan, $serv, $printer; + }; return EAT_NONE; }; @@ -248,8 +244,8 @@ hook_server 'QUIT', sub { get_list 'channels'; if (nickcmp get_info('nick'), $nick) { - my $oldctxt = get_context; - my $host = host $userhost; + my $guard = save_context; + my $host = host $userhost; for (@chans) { my $clones = remove $nick, $host, $serv, $_->[0]; if ($clones > 0) { @@ -257,7 +253,6 @@ hook_server 'QUIT', sub { print $ph clone_leave_str $userhost, $nick, $clones; } } - set_context $oldctxt; } else { flush $serv, $_->[0] for @chans; } @@ -266,9 +261,9 @@ hook_server 'QUIT', sub { }; hook_print 'Disconnected', sub { - my %servers = map { $_->{server} => 1 } - grep { $_->{flags} & 9 and not($_->{flags} & 2) } - get_list 'channels'; + my %servers; + $servers{$_->{server}} = 1 for grep +($_->{flags} & 0b1011) == 0b1001, + get_list 'channels'; delete @users{ grep !$servers{$_}, keys %users}; delete @fetched{grep !$servers{$_}, keys %fetched}; @@ -319,7 +314,10 @@ $ph = Xchat::XPI->new( author => 'Vincent Pit (VPIT)', email => 'perl@profvince.com', url => 'http://www.profvince.com', - unload => sub { undef %users }, + unload => sub { + undef %users; + undef %fetched; + }, ); 1;