]> git.vpit.fr Git - perl/scripts/xchat.git/blob - services.pl
Make sure local_context() runs the code only when the context was found
[perl/scripts/xchat.git] / services.pl
1 package Xchat::VPIT::Services;
2
3 use strict;
4 use warnings;
5
6 use Xchat qw<:all>;
7
8 use lib get_info 'xchatdir';
9 use Xchat::XPI;
10 use Xchat::XPI::Utils qw<save_context>;
11
12 our $VERSION = '0.03';
13
14 my $ph;
15
16 sub get_servers_ctxt {
17  my %s;
18  return map $_->{context},
19          grep !$s{$_->{server}}++,
20           sort { $a->{type} <=> $b->{type} }
21            get_list 'channels';
22 }
23
24 hook_command 'ID', sub {
25  return EAT_PLUGIN if $_[0][1];
26  my $passwd = get_info 'nickserv';
27  return EAT_ALL unless $passwd;
28  command 'ID ' . $passwd;
29  return EAT_ALL;
30 }, {
31  help_text => 'ID [password], identify you to NickServ'
32 };
33
34 hook_command 'AID', sub {
35  my $forcepasswd = $_[0][1];
36  my @contexts     = get_servers_ctxt;
37  my $guard        = save_context;
38  for (@contexts) {
39   set_context $_ or next;
40   my $passwd = $forcepasswd || get_info 'nickserv';
41   next unless $passwd;
42   command 'ID ' . $passwd;
43  }
44  return EAT_ALL;
45 }, {
46  help_text => 'AID [password], identify you on all servers'
47 };
48
49 hook_command 'GHOST', sub {
50  return EAT_PLUGIN if $_[0][2];
51  my $target = $_[0][1] || get_prefs 'irc_nick1';
52  my $passwd = get_info 'nickserv';
53  return EAT_ALL unless $target && $passwd;
54  if (nickcmp(get_info('nick'), $target)) {
55   command join ' ', 'GHOST', $target, $passwd;
56  }
57  return EAT_ALL;
58 }, {
59  help_text => 'GHOST [nick] [password], kill the client currently connected with your nickname'
60 };
61
62 hook_command 'AGHOST', sub {
63  my $target = $_[0][1] || get_prefs 'irc_nick1';
64  return EAT_ALL unless $target;
65  my $forcepasswd = $_[0][2];
66  my @contexts    = get_servers_ctxt;
67  my $guard       = save_context;
68  for (@contexts) {
69   set_context $_ or next;
70   my $passwd = $forcepasswd || get_info 'nickserv';
71   next unless $passwd;
72   if (nickcmp(get_info('nick'), $target)) {
73    command join ' ', 'GHOST', $target, $passwd;
74   }
75  }
76  return EAT_ALL;
77 }, {
78  help_text => 'AGHOST [nick] [password], kill usurping clients on all servers'
79 };
80
81 sub csmode {
82  my $cmd = join ' ', 'QUOTE CHANSERV', $_[2], get_info('channel');
83  my @targets = @{$_[0]};
84  shift @targets;
85  @targets = (get_info 'nick') unless @targets;
86  command join ' ', $cmd, $_ for @targets;
87  return EAT_ALL;
88 }
89
90 hook_command "C$_", \&csmode, {
91  data => $_,
92  help_text => join ' ', $_, '[nicks] ,', lc($_),
93     'the specified targets (or you if none) on the current channel via ChanServ'
94 } for map { $_, "DE$_" } qw<VOICE HALFOP OP PROTECT>;
95
96 $ph = Xchat::XPI->new(
97  name   => 'IRC Services',
98  tag    => 'Services',
99  desc   => 'Various IRC services helpers',
100  author => 'Vincent Pit (VPIT)',
101  email  => 'perl@profvince.com',
102  url    => 'http://www.profvince.com',
103 );
104
105 1;