]> git.vpit.fr Git - perl/scripts/xchat.git/blobdiff - services.pl
Add better context handling helpers
[perl/scripts/xchat.git] / services.pl
index f04a80efb8132998cb062e3a435ec5988c18273a..e9f13d687f3ecf2acfdfb256351b9133c71e070c 100755 (executable)
@@ -7,6 +7,7 @@ use Xchat qw<:all>;
 
 use lib get_info 'xchatdir';
 use Xchat::XPI;
+use Xchat::XPI::Utils qw<save_context>;
 
 our $VERSION = '0.03';
 
@@ -32,15 +33,14 @@ hook_command 'ID', sub {
 
 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) {
   set_context $_;
   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'
@@ -63,8 +63,8 @@ hook_command 'AGHOST', sub {
  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) {
   set_context $_;
   my $passwd = $forcepasswd || get_info 'nickserv';
@@ -73,7 +73,6 @@ hook_command 'AGHOST', sub {
    command join ' ', 'GHOST', $target, $passwd;
   }
  }
- set_context $oldctxt;
  return EAT_ALL;
 }, {
  help_text => 'AGHOST [nick] [password], kill usurping clients on all servers'