X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=clones.pl;h=46ca4d648815aada8713f28f8c029bbc70d5adcd;hb=4d2f1a94053d536b838ab1601317dcfae36ad789;hp=20aecfae044feabb10c3711294a00c6d66c89ed1;hpb=1653942ef55abd3f4aefff434f4452b641b3ce76;p=perl%2Fscripts%2Fxchat.git diff --git a/clones.pl b/clones.pl index 20aecfa..46ca4d6 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; }