]> git.vpit.fr Git - perl/scripts/xchat.git/blob - opers.pl
4ff5c788cfb677b51e92bc8c95fdceb24b96ce5a
[perl/scripts/xchat.git] / opers.pl
1 package Xchat::VPIT::Opers;
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
11 our $VERSION = '0.03';
12
13 my ($ph, %opers);
14
15 sub print_op { print $ph "\002$_[0]\002 ($_[1]) \002is an IRC operator\n"; 1 }
16
17 hook_server '352', sub {
18  return EAT_NONE unless (rindex $_[0][8], '*') >= 0;
19  my $serv = get_info 'server';
20  my $nick = $_[0][7];
21  if (!$opers{$serv}{$nick}) {
22   $opers{$serv}{$nick} = 1;
23   my $host = $_[0][4].'@'.$_[0][5];
24   my %chans;
25   push @{$chans{$_->{type}}}, $_ for grep { $_->{server} eq $serv }
26                                       get_list 'channels';
27   my $oldctxt = get_context;
28   my $onachan = grep { $_ } map {
29    set_context($_->{context}) && user_info($nick) && print_op($nick, $host)
30   } @{$chans{2}};
31   do {
32    set_context($_->{context}) && print_op($nick, $host)
33   } for ($onachan ? () : @{$chans{1}}),
34                          grep { !nickcmp($_->{channel}, $nick) } @{$chans{3}};
35   set_context $oldctxt;
36  }
37  return EAT_NONE;
38 };
39
40 hook_print 'Disconnected', sub {
41  my %servers = map { $_->{server} => 1 }
42                 grep { $_->{flags} & 9 && not $_->{flags} & 2 }
43                  get_list 'channels';
44  delete $opers{$_} for grep { !$servers{$_} } keys %opers;
45  return EAT_NONE;
46 };
47
48 hook_server 'QUIT', sub {
49  my ($nick) = ($_[0][0] =~ /^:([^!]+)!/);
50  my $serv = get_info 'server';
51  delete $opers{$serv}{$nick};
52  return EAT_NONE;
53 };
54
55 sub nick_cb {
56  my ($old, $new) = @{$_[0]};
57  my $ops = $opers{get_info 'server'};
58  if ($ops && $ops->{$old}) {
59   $ops->{$new} = 1;
60   delete $ops->{$old};
61  }
62  return EAT_NONE;
63 }
64
65 hook_print $_, \&nick_cb for ('Change Nick', 'Your Nick Changing');
66
67 hook_command 'OPSCAN', sub {
68  my $serv = get_info 'server';
69  if (!$opers{$serv}) {
70   print $ph "No information for this network yet\n";
71   return EAT_ALL;
72  }
73  my ($chan, $isnet) = (get_info('channel'), 0);
74  for (get_list 'channels') {
75   if ($_->{type} eq 1 && $_->{channel} eq $chan) { $isnet = 1; last; }
76  }
77  my ($name, @ops) = ($isnet) ? ('network', keys %{$opers{$serv}})
78                              : ('channel', map { $_->{nick} }
79                                             grep { $opers{$serv}{$_->{nick}} }
80                                              get_list 'users');
81  if (@ops) {
82   print $ph 'IRC operators on this '.$name." : \002@ops\n";
83  } else {
84   print $ph 'No IRC operators on this '.$name."\n";
85  }
86  return EAT_ALL;
87 }, {
88  help_text => 'OPSCAN, scan for IRC operators in the current channel'
89 };
90
91 $ph = new Xchat::XPI name   => 'Operators',
92                      tag    => 'Opers',
93                      desc   => 'IRC operators scanner',
94                      author => 'Vincent Pit (VPIT)',
95                      email  => 'perl@profvince.com',
96                      url    => 'http://www.profvince.com',
97                      unload => sub { undef %opers; };
98
99 1;