]> git.vpit.fr Git - perl/scripts/xchat.git/blobdiff - services.pl
Make sure local_context() runs the code only when the context was found
[perl/scripts/xchat.git] / services.pl
index 10f4fd4355e69b0bf78bfd35fc7b5872411bf58a..e57845cf13c0af877a224357bcee38a4807317f6 100755 (executable)
@@ -3,10 +3,11 @@ package Xchat::VPIT::Services;
 use strict;
 use warnings;
 
 use strict;
 use warnings;
 
-use Xchat qw/:all/;
+use Xchat qw<:all>;
 
 use lib get_info 'xchatdir';
 use Xchat::XPI;
 
 use lib get_info 'xchatdir';
 use Xchat::XPI;
+use Xchat::XPI::Utils qw<save_context>;
 
 our $VERSION = '0.03';
 
 
 our $VERSION = '0.03';
 
@@ -32,15 +33,14 @@ hook_command 'ID', sub {
 
 hook_command 'AID', sub {
  my $forcepasswd = $_[0][1];
 
 hook_command 'AID', sub {
  my $forcepasswd = $_[0][1];
- my $oldctxt = get_context;
- my @contexts = get_servers_ctxt;
+ my @contexts     = get_servers_ctxt;
+ my $guard        = save_context;
  for (@contexts) {
  for (@contexts) {
-  set_context $_;
+  set_context $_ or next;
   my $passwd = $forcepasswd || get_info 'nickserv';
   next unless $passwd;
   command 'ID ' . $passwd;
  }
   my $passwd = $forcepasswd || get_info 'nickserv';
   next unless $passwd;
   command 'ID ' . $passwd;
  }
- set_context $oldctxt;
  return EAT_ALL;
 }, {
  help_text => 'AID [password], identify you on all servers'
  return EAT_ALL;
 }, {
  help_text => 'AID [password], identify you on all servers'
@@ -63,17 +63,16 @@ hook_command 'AGHOST', sub {
  my $target = $_[0][1] || get_prefs 'irc_nick1';
  return EAT_ALL unless $target;
  my $forcepasswd = $_[0][2];
  my $target = $_[0][1] || get_prefs 'irc_nick1';
  return EAT_ALL unless $target;
  my $forcepasswd = $_[0][2];
- my $oldctxt = get_context;
- my @contexts = get_servers_ctxt;
+ my @contexts    = get_servers_ctxt;
+ my $guard       = save_context;
  for (@contexts) {
  for (@contexts) {
-  set_context $_;
+  set_context $_ or next;
   my $passwd = $forcepasswd || get_info 'nickserv';
   next unless $passwd;
   if (nickcmp(get_info('nick'), $target)) {
    command join ' ', 'GHOST', $target, $passwd;
   }
  }
   my $passwd = $forcepasswd || get_info 'nickserv';
   next unless $passwd;
   if (nickcmp(get_info('nick'), $target)) {
    command join ' ', 'GHOST', $target, $passwd;
   }
  }
- set_context $oldctxt;
  return EAT_ALL;
 }, {
  help_text => 'AGHOST [nick] [password], kill usurping clients on all servers'
  return EAT_ALL;
 }, {
  help_text => 'AGHOST [nick] [password], kill usurping clients on all servers'
@@ -90,15 +89,17 @@ sub csmode {
 
 hook_command "C$_", \&csmode, {
  data => $_,
 
 hook_command "C$_", \&csmode, {
  data => $_,
- help_text => join ' ', $_, '[nicks] ,', (lc $_),
+ help_text => join ' ', $_, '[nicks] ,', lc($_),
     'the specified targets (or you if none) on the current channel via ChanServ'
     'the specified targets (or you if none) on the current channel via ChanServ'
-} for map { $_, "DE$_" } qw/VOICE HALFOP OP PROTECT/;
+} for map { $_, "DE$_" } qw<VOICE HALFOP OP PROTECT>;
 
 
-$ph = new Xchat::XPI name   => 'IRC Services',
-                     tag    => 'Services',
-                     desc   => 'Various IRC services helpers',
-                     author => 'Vincent Pit (VPIT)',
-                     email  => 'perl@profvince.com',
-                     url    => 'http://www.profvince.com';
+$ph = Xchat::XPI->new(
+ name   => 'IRC Services',
+ tag    => 'Services',
+ desc   => 'Various IRC services helpers',
+ author => 'Vincent Pit (VPIT)',
+ email  => 'perl@profvince.com',
+ url    => 'http://www.profvince.com',
+);
 
 1;
 
 1;