1 package Xchat::VPIT::Opers;
8 use lib get_info 'xchatdir';
10 use Xchat::XPI::Utils qw<irc_lc save_context>;
12 our $VERSION = '0.03';
16 sub print_op { print $ph "\002$_[0]\002 ($_[1]) \002is an IRC operator\n" }
18 hook_server '352', sub {
19 return EAT_NONE unless 0 <= rindex $_[0][8], '*';
21 my $serv = get_info 'server';
23 return EAT_NONE if $opers{$serv}{irc_lc($nick)};
24 $opers{$serv}{irc_lc($nick)} = $nick;
26 my $host = $_[0][4] . '@' . strip_code $_[0][5];
28 push @{$chans{$_->{type}}}, $_ for grep $_->{server} eq $serv,
31 my $guard = save_context;
35 set_context $_->{context} or next;
36 user_info $nick or next;
37 print_op $nick, $host;
42 @opchans = @{$chans{1}} unless $onachan;
43 push @opchans, grep !nickcmp($_->{channel}, $nick), @{$chans{3}};
45 set_context $_->{context} or next;
46 print_op $nick, $host;
52 hook_print 'Disconnected', sub {
54 $servers{$_->{server}} = 1 for grep +($_->{flags} & 0b1011) == 0b1001,
57 delete @opers{grep !$servers{$_}, keys %opers};
62 hook_server 'QUIT', sub {
63 my ($nick) = $_[0][0] =~ /^:([^!]+)!/;
65 my $serv = get_info 'server';
66 delete $opers{$serv}{irc_lc($nick)};
72 my ($old, $new) = @{$_[0]};
76 my $ops = $opers{get_info 'server'};
77 if ($ops and $ops->{$old}) {
78 $ops->{irc_lc($new)} = $new;
85 hook_print $_, \&nick_cb for 'Change Nick', 'Your Nick Changing';
87 hook_command 'OPSCAN', sub {
88 my $serv = get_info 'server';
90 print $ph "No information for this network yet\n";
94 my $chan = get_info 'channel';
96 for (get_list 'channels') {
97 if ($_->{type} == 1 and $_->{channel} eq $chan) {
106 @ops = values %{$opers{$serv}};
109 @ops = map $_->{nick},
110 grep $opers{$serv}{irc_lc($_->{nick})},
115 print $ph "IRC operators on this $name : \002@ops\n";
117 print $ph "No IRC operators on this $name\n";
122 help_text => 'OPSCAN, scan for IRC operators in the current channel'
125 $ph = Xchat::XPI->new(
128 desc => 'IRC operators scanner',
129 author => 'Vincent Pit (VPIT)',
130 email => 'perl@profvince.com',
131 url => 'http://www.profvince.com',
132 unload => sub { undef %opers },