2 # IrcHooks.pl: IRC Hooks stuff.
5 # NOTE: Based on code by Kevin Lenzo & Patrick Cole (c) 1997
7 use vars qw(%chanconf);
13 my $nick = $event->nick();
14 my $chan = ( $event->to )[0];
16 &DEBUG("on_generic: nick => '$nick'.");
17 &DEBUG("on_generic: chan => '$chan'.");
19 foreach ( $event->args ) {
20 &DEBUG("on_generic: args => '$_'.");
27 my ( $nick, $args ) = ( $event->nick, $event->args );
28 my $chan = ( $event->to )[0];
30 if ( $chan eq $ident ) {
31 &status("* [$nick] $args");
34 &status("* $nick/$chan $args");
41 my $msg = ( $event->args )[0];
42 my $sock = ( $event->to )[0];
43 my $nick = lc $event->nick();
45 if ( !exists $nuh{$nick} ) {
46 &DEBUG("chat: nuh{$nick} doesn't exist; trying WHOIS .");
51 ### set vars that would have been set in hookMsg.
52 $userHandle = ''; # reset.
56 $orig{message} = $msg;
58 $uh = ( split /\!/, $nuh )[1];
59 $h = ( split /\@/, $uh )[1];
63 if ( !exists $dcc{'CHATvrfy'}{$nick} ) {
64 $userHandle = &verifyUser( $who, $nuh );
65 my $crypto = $users{$userHandle}{PASS};
68 if ( $userHandle eq '_default' ) {
69 &WARN('DCC CHAT: _default/guest not allowed.');
73 ### TODO: prevent users without CRYPT chatting.
74 if ( !defined $crypto ) {
75 &TODO('dcc close chat');
76 &msg( $who, 'nope, no guest logins allowed...' );
80 if ( &ckpasswd( $msg, $crypto ) ) {
82 # stolen from eggdrop.
83 $conn->privmsg( $sock, "Connected to $ident" );
84 $conn->privmsg( $sock,
85 'Commands start with "." (like ".quit" or ".help")' );
86 $conn->privmsg( $sock,
87 'Everything else goes out to the party line.' );
89 &dccStatus(2) unless ( exists $sched{'dccStatus'}{RUNNING} );
95 &status('DCC CHAT: incorrect pass; closing connection.');
96 &DEBUG("chat: sock => '$sock'.");
98 delete $dcc{'CHAT'}{$nick};
99 &FIXME('chat: after closing sock.');
100 ### BUG: close seizes bot. why?
104 &status("DCC CHAT: user $nick is here!");
105 &DCCBroadcast("*** $nick ($uh) joined the party line.");
107 $dcc{'CHATvrfy'}{$nick} = $userHandle;
109 return if ( $userHandle eq '_default' );
111 &dccsay( $nick, "Flags: $users{$userHandle}{FLAGS}" );
117 &status("$b_red=$b_cyan$who$b_red=$ob $message");
119 if ( $message =~ s/^\.// ) { # dcc chat commands.
120 ### TODO: make use of &Forker(); here?
121 &loadMyModule('UserDCC');
123 &DCCBroadcast( "#$who# $message", 'm' );
125 my $retval = &userDCC();
126 return unless ( defined $retval );
127 return if ( $retval eq $noreply );
129 $conn->privmsg( $dcc{'CHAT'}{$who}, 'Invalid command.' );
132 else { # dcc chat arena.
134 foreach ( keys %{ $dcc{'CHAT'} } ) {
135 $conn->privmsg( $dcc{'CHAT'}{$_}, "<$who> $orig{message}" );
139 return 'DCC CHAT MESSAGE';
142 # is there isoff? how do we know if someone signs off?
146 my $x1 = ( $event->args )[0];
147 my $x2 = ( $event->args )[1];
150 &DEBUG("on_ison: x1 = '$x1', x2 => '$x2'");
157 $ident = $conn->nick();
158 $ircstats{'ConnectTime'} = time();
159 $ircstats{'ConnectCount'}++;
160 if ( defined $ircstats{'DisconnectTime'} ) {
161 $ircstats{'OffTime'} += time() - $ircstats{'DisconnectTime'};
165 if ( !exists $users{_default} ) {
166 &status('!!! First time run... adding _default user.');
167 $users{_default}{FLAGS} = 'amrt';
168 $users{_default}{HOSTS}{'*!*@*'} = 1;
171 if ( scalar keys %users < 2 ) {
174 "!!! Ok. Now type '/msg $ident PASS <pass>' to get master access through DCC CHAT."
179 # end of first time run.
181 if ( &IsChanConf('Wingate') > 0 ) {
182 my $file = "$bot_base_dir/$param{'ircUser'}.wingate";
186 next unless (/^(\S+)\*$/);
187 push( @wingateBad, $_ );
193 &ScheduleThis( 1, 'setupSchedulers' );
197 if ( &IsParam('ircUMode') ) {
198 &VERB( "Attempting change of user modes to $param{'ircUMode'}.", 2 );
199 if ( $param{'ircUMode'} !~ /^[-+]/ ) {
200 &WARN('ircUMode had no +- prefix; adding +');
201 $param{'ircUMode'} = '+' . $param{'ircUMode'};
204 &rawout("MODE $ident $param{'ircUMode'}");
207 # ok, we're free to do whatever we want now. go for it!
210 # add ourself to notify.
211 $conn->ison( $conn->nick() );
213 # Q, as on quakenet.org.
214 if ( &IsParam('Q_pass') ) {
215 &status('Authing to Q...');
217 "PRIVMSG Q\@CServe.quakenet.org :AUTH $param{'Q_user'} $param{'Q_pass'}"
221 &status('End of motd. Now lets join some channels...');
230 # &DEBUG("endofwho: chan => $chan");
231 $chan ||= ( $event->args )[1];
233 # &DEBUG("endofwho: chan => $chan");
235 if ( exists $cache{countryStats} ) {
243 my $type = uc( ( $event->args )[1] );
244 my $nick = lc $event->nick();
246 &status("on_dcc type=$type nick=$nick sock=$sock");
248 # pity Net::IRC doesn't store nuh. Here's a hack :)
249 if ( !exists $nuh{ lc $nick } ) {
251 $nuh{$nick} = 'GETTING-NOW'; # trying.
255 if ( $type eq 'SEND' ) { # GET for us.
256 # incoming DCC SEND. we're receiving a file.
257 my $get = ( $event->args )[2];
259 "DCC: not Initializing GET from $nick to '$param{tempDir}/$get'");
261 # FIXME: do we want to get anything?
264 #open(DCCGET,">$param{tempDir}/$get");
265 #$conn->new_get($event, \*DCCGET);
268 elsif ( $type eq 'GET' ) { # SEND for us?
269 &status("DCC: not Initializing SEND for $nick.");
271 # FIXME: do we want to do anything?
273 $conn->new_send( $event->args );
276 elsif ( $type eq 'CHAT' ) {
277 &status("DCC: Initializing CHAT for $nick.");
278 $conn->new_chat($event);
280 # $conn->new_chat(1, $nick, $event->host);
284 &WARN("${b_green}DCC $type$ob (1)");
291 my $nick = $event->nick();
292 my $sock = ( $event->to )[0];
294 # DCC CHAT close on fork exit workaround.
295 if ( $bot_pid != $$ ) {
296 &WARN('run-away fork; exiting.');
300 if ( exists $dcc{'SEND'}{$nick} and -f "$param{tempDir}/$nick.txt" ) {
301 &status("${b_green}DCC SEND$ob close from $b_cyan$nick$ob");
303 &status("dcc_close: purging DCC send $nick.txt");
304 unlink "$param{tempDir}/$nick.txt";
306 delete $dcc{'SEND'}{$nick};
308 elsif ( exists $dcc{'CHAT'}{$nick} and $dcc{'CHAT'}{$nick} eq $sock ) {
309 &status("${b_green}DCC CHAT$ob close from $b_cyan$nick$ob");
310 delete $dcc{'CHAT'}{$nick};
311 delete $dcc{'CHATvrfy'}{$nick};
314 &status("${b_green}DCC$ob UNKNOWN close from $b_cyan$nick$ob (2)");
321 my $type = uc( ( $event->args )[0] );
322 my $nick = lc $event->nick();
323 my $sock = ( $event->to )[0];
325 &status("on_dcc_open type=$type nick=$nick sock=$sock");
329 ### BUG: who is set to bot's nick?
332 if ( $type eq 'SEND' ) {
333 &status("${b_green}DCC lGET$ob established with $b_cyan$nick$ob");
336 elsif ( $type eq 'CHAT' ) {
339 ### TODO: run ScheduleThis inside on_dcc_open_chat recursively
340 ### 1,3,5,10 seconds then fail.
341 if ( $nuh{$nick} eq 'GETTING-NOW' ) {
342 &ScheduleThis( 3 / 60, 'on_dcc_open_chat', $nick, $sock );
345 on_dcc_open_chat( undef, $nick, $sock );
349 elsif ( $type eq 'SEND' ) {
350 &status('Starting DCC receive.');
351 foreach ( $event->args ) {
352 &status(" => '$_'.");
357 &WARN("${b_green}DCC $type$ob (3)");
361 # really custom sub to get NUH since Net::IRC doesn't appear to support
363 sub on_dcc_open_chat {
364 my ( undef, $nick, $sock ) = @_;
366 if ( $nuh{$nick} eq 'GETTING-NOW' ) {
367 &FIXME("getting nuh for $nick failed.");
372 "${b_green}DCC CHAT$ob established with $b_cyan$nick$ob $b_yellow($ob$nuh{$nick}$b_yellow)$ob"
375 &verifyUser( $nick, $nuh{ lc $nick } );
377 if ( !exists $users{$userHandle}{HOSTS} ) {
379 'you have no hosts defined in my user file; rejecting.');
384 my $crypto = $users{$userHandle}{PASS};
385 $dcc{'CHAT'}{$nick} = $sock;
387 # TODO: don't make DCC CHAT established in the first place.
388 if ( $userHandle eq '_default' ) {
389 &dccsay( $nick, '_default/guest not allowed' );
394 if ( defined $crypto ) {
395 &status( "DCC CHAT: going to use $nick\'s crypt." );
396 &dccsay( $nick, 'Enter your password.' );
400 # &dccsay($nick,"Welcome to infobot DCC CHAT interface, $userHandle.");
407 my $from = $event->from();
408 my $what = ( $event->args )[0];
409 my $mynick = $conn->nick();
411 &status("$mynick disconnect from $from ($what).");
412 $ircstats{'DisconnectTime'} = time();
413 $ircstats{'DisconnectReason'} = $what;
414 $ircstats{'DisconnectCount'}++;
415 $ircstats{'TotalTime'} += time() - $ircstats{'ConnectTime'}
416 if ( $ircstats{'ConnectTime'} );
418 # clear any variables on reconnection.
423 if ( !defined $conn ) {
424 &WARN('on_disconnect: self is undefined! WTF');
425 &DEBUG('running function irc... lets hope this works.');
430 &WARN('scheduling call ircCheck() in 60s');
432 &ScheduleThis( 1, 'ircCheck' );
438 my $chan = ( $event->args )[1];
440 # sync time should be done in on_endofwho like in BitchX
441 if ( exists $cache{jointime}{$chan} ) {
443 sprintf( '%.03f', &timedelta( $cache{jointime}{$chan} ) );
444 $delta_time = 0 if ( $delta_time <= 0 );
445 if ( $delta_time > 100 ) {
446 &WARN("endofnames: delta_time > 100 ($delta_time)");
449 &status("$b_blue$chan$ob: sync in ${delta_time}s.");
456 foreach ( 'o', 'v', '' ) {
457 my $count = scalar( keys %{ $channels{$chan}{$_} } );
458 next unless ($count);
460 $txt = 'total' if ( $_ eq '' );
461 $txt = 'voice' if ( $_ eq 'v' );
462 $txt = 'ops' if ( $_ eq 'o' );
464 push( @array, "$count $txt" );
466 my $chanstats = join( ' || ', @array );
467 &status("$b_blue$chan$ob: [$chanstats]");
469 &chanServCheck($chan);
471 # schedule used to solve ircu (OPN) "target too fast" problems.
472 $conn->schedule( 5, sub { &joinNextChan(); } );
478 my (@args) = ( $event->args );
487 my $chan = lc( ( $event->args )[0] );
488 my $nick = $event->nick;
490 if ( $nick =~ /^\Q$ident\E$/ ) {
491 &DEBUG('on_invite: self invite.');
496 if ( exists $chanconf{$chan} ) {
498 # it's still buggy :/
499 if ( &validChan($chan) ) {
500 &msg( $who, "i'm already in \002$chan\002." );
505 &status("invited to $b_blue$chan$ob by $b_cyan$nick$ob");
513 my ( $user, $host ) = split( /\@/, $event->userhost );
514 $chan = lc( ( $event->to )[0] ); # CASING!!!!
515 $who = $event->nick();
517 my $i = scalar( keys %{ $channels{$chan} } );
518 my $j = $cache{maxpeeps}{$chan} || 0;
520 if ( !&IsParam('noSHM')
521 && time() > ( $sched{shmFlush}{TIME} || time() ) + 3600 )
523 &DEBUG('looks like schedulers died somewhere... restarting...');
527 $chanstats{$chan}{'Join'}++;
528 $userstats{ lc $who }{'Join'} = time() if ( &IsChanConf('seenStats') > 0 );
529 $cache{maxpeeps}{$chan} = $i if ( $i > $j );
531 &joinfloodCheck( $who, $chan, $event->userhost );
535 if ( exists $netsplit{ lc $who } ) {
536 delete $netsplit{ lc $who };
539 if ( !scalar keys %netsplit ) {
540 &DEBUG('on_join: netsplit hash is now empty!');
541 undef %netsplitservers;
542 &netsplitCheck(); # any point in running this?
547 if ( $netsplit and !exists $cache{netsplit} ) {
548 &VERB('on_join: ok.... re-running chanlimitCheck in 60.', 2);
553 delete $cache{netsplit};
557 $cache{netsplit} = time();
560 # how to tell if there's a netjoin???
562 my $netsplitstr = '';
563 $netsplitstr = " $b_yellow\[${ob}NETSPLIT VICTIM$b_yellow]$ob"
566 ">>> join/$b_blue$chan$ob $b_cyan$who$ob $b_yellow($ob$user\@$host$b_yellow)$ob$netsplitstr"
569 $channels{$chan}{''}{$who}++;
570 $nuh = $who . '!' . $user . '@' . $host;
571 $nuh{ lc $who } = $nuh unless ( exists $nuh{ lc $who } );
575 push( @bans, keys %{ $bans{$chan} } ) if ( exists $bans{$chan} );
576 push( @bans, keys %{ $bans{'*'} } ) if ( exists $bans{'*'} );
583 next unless ( $nuh =~ /^$mask$/i );
585 ### TODO: check $channels{$chan}{'b'} if ban already exists.
586 foreach ( keys %{ $channels{$chan}{'b'} } ) {
587 &DEBUG(" bans_on_chan($chan) => $_");
590 my $reason = 'no reason';
591 foreach ( $chan, '*' ) {
592 next unless ( exists $bans{$_} );
593 next unless ( exists $bans{$_}{$ban} );
595 my @array = @{ $bans{$_}{$ban} };
597 $reason = $array[4] if ( $array[4] );
602 &kick( $who, $chan, $reason );
607 # no need to go further.
608 return if ($netsplit);
611 if ( $who =~ /^\Q$ident\E$/i ) {
612 if ( defined( my $whojoin = $cache{join}{$chan} ) ) {
613 &msg( $chan, "Okay, I'm here. (courtesy of $whojoin)" );
614 delete $cache{join}{$chan};
615 &joinNextChan(); # hack.
618 ### TODO: move this to &joinchan()?
619 $cache{jointime}{$chan} = &timeget();
626 &rootWarn( $who, $user, $host, $chan )
627 if ( &IsChanConf('RootWarn') > 0
628 && $user =~ /^~?r(oo|ew|00)t$/i );
630 ### emit a message based on who just joined
631 &onjoin( $who, $user, $host, $chan ) if ( &IsChanConf('OnJoin') > 0 );
634 if ( &IsChanConf('News') > 0 && &IsChanConf('newsKeepRead') > 0 ) {
635 if ( !&loadMyModule('News') ) { # just in case.
636 &DEBUG('could not load news.');
639 &News::latest($chan);
644 if ( &IsChanConf('botmail') > 0 ) {
645 &botmail::check( lc $who );
655 my ( $chan, $reason ) = $event->args;
656 my $kicker = $event->nick;
657 my $kickee = ( $event->to )[0];
658 my $uh = $event->userhost();
661 ">>> kick/$b_blue$chan$ob [$b$kickee!$uh$ob] by $b_cyan$kicker$ob $b_yellow($ob$reason$b_yellow)$ob"
664 $chan = lc $chan; # forgot about this, found by xsdg, 20001229.
665 $chanstats{$chan}{'Kick'}++;
667 if ( $kickee eq $ident ) {
668 &clearChanVars($chan);
670 &status("SELF attempting to rejoin lost channel $chan");
674 &delUserInfo( $kickee, $chan );
681 my ( $user, $host ) = split( /\@/, $event->userhost );
682 my @args = $event->args();
683 my $nick = $event->nick();
684 $chan = ( $event->to )[0];
686 # last element is empty... so nuke it.
687 pop @args while ( $args[$#args] eq '' );
689 if ( $nick eq $chan ) { # UMODE
691 ">>> mode $b_yellow\[$ob$b@args$b_yellow\]$ob by $b_cyan$nick$ob");
695 ">>> mode/$b_blue$chan$ob $b_yellow\[$ob$b@args$b_yellow\]$ob by $b_cyan$nick$ob"
697 &hookMode( $nick, @args );
704 my ( $myself, undef, @args ) = $event->args();
705 my $nick = $event->nick();
706 $chan = ( $event->args() )[1];
708 &hookMode( $nick, @args );
714 my $nick = $event->nick;
715 my $msg = ( $event->args )[0];
717 ( $user, $host ) = split( /\@/, $event->userhost );
718 $uh = $event->userhost();
719 $nuh = $nick . '!' . $uh;
723 if ( $nick eq $ident ) { # hopefully ourselves.
724 if ( $msg eq 'TEST' ) {
725 &status("IRCTEST: Yes, we're alive.");
726 delete $cache{connect};
731 &hookMsg( 'private', undef, $nick, $msg );
740 my @args = $event->args;
741 my $chan = lc $args[2]; # CASING, the last of them!
743 foreach ( split / /, @args[ 3 .. $#args ] ) {
744 $channels{$chan}{'o'}{$_}++ if s/\@//;
745 $channels{$chan}{'v'}{$_}++ if s/\+//;
746 $channels{$chan}{''}{$_}++;
753 my $nick = $event->nick();
754 my $newnick = ( $event->args )[0];
756 if ( exists $netsplit{ lc $newnick } ) {
758 "Netsplit: $newnick/$nick came back from netsplit and changed to original nick! removing from hash."
760 delete $netsplit{ lc $newnick };
761 &netsplitCheck() if ( time() != $sched{netsplitCheck}{TIME} );
765 foreach $chan ( keys %channels ) {
766 foreach $mode ( keys %{ $channels{$chan} } ) {
767 next unless ( exists $channels{$chan}{$mode}{$nick} );
769 $channels{$chan}{$mode}{$newnick} = $channels{$chan}{$mode}{$nick};
773 # TODO: do %flood* aswell.
775 &delUserInfo( $nick, keys %channels );
776 $nuh{ lc $newnick } = $nuh{ lc $nick };
777 delete $nuh{ lc $nick };
779 if ( $nick eq $conn->nick() ) {
780 &status(">>> I materialized into $b_green$newnick$ob from $nick");
782 $conn->nick($newnick);
785 &status(">>> $b_cyan$nick$ob materializes into $b_green$newnick$ob");
786 my $mynick = $conn->nick();
787 if ( $nick =~ /^\Q$mynick\E$/i ) {
795 my $nick = $conn->nick();
797 #my $newnick = $nick . int(rand 10);
798 my $newnick = $nick . '_';
800 &DEBUG("on_nick_taken: nick => $nick");
802 &status("nick taken ($nick); preparing nick change.");
806 #$conn->schedule(5, sub {
807 &status("nick taken; changing to temporary nick ($nick -> $newnick).");
816 my $nick = $event->nick();
817 my $chan = ( $event->to )[0];
818 my $args = ( $event->args )[0];
820 if ( $nick =~ /^NickServ$/i ) { # nickserv.
821 &status("NickServ: <== '$args'");
824 $check++ if ( $args =~ /^This nickname is registered/i );
825 $check++ if ( $args =~ /nickname.*owned/i );
828 &status("nickserv told us to register; doing it.");
830 if ( &IsParam('nickServ_pass') ) {
831 &status("NickServ: ==> Identifying.");
832 &rawout("PRIVMSG NickServ :IDENTIFY $param{'nickServ_pass'}");
836 &status("We can't tell nickserv a passwd ;(");
841 if ( $args =~ /^Password a/i ) {
844 foreach ( &ChanConfList('chanServ_ops') ) {
845 next unless &chanServCheck($_);
848 "nickserv activated or restarted; doing chanserv check.");
856 elsif ( $nick =~ /^ChanServ$/i ) { # chanserv.
857 &status("ChanServ: <== '$args'.");
861 if ( $chan =~ /^$mask{chan}$/ ) { # channel notice.
862 &status("-$nick/$chan- $args");
865 $server = $nick unless ( defined $server );
866 &status("-$nick- $args"); # private or server notice.
874 my $chan = ( $event->to )[0];
875 my $nick = $event->nick;
877 &status("!!! other called.");
878 &status("!!! $event->args");
884 $chan = lc( ( $event->to )[0] ); # CASING!!!
885 my $mynick = $conn->nick();
886 my $nick = $event->nick;
887 my $userhost = $event->userhost;
891 if ( !exists $channels{$chan} ) {
892 &DEBUG("on_part: found out $mynick is on $chan!");
893 $channels{$chan} = 1;
896 if ( exists $floodjoin{$chan}{$nick}{Time} ) {
897 delete $floodjoin{$chan}{$nick};
900 $chanstats{$chan}{'Part'}++;
901 &delUserInfo( $nick, $chan );
902 if ( $nick eq $ident ) {
903 &clearChanVars($chan);
906 if ( !&IsNickInAnyChan($nick) and &IsChanConf('seenStats') > 0 ) {
907 delete $userstats{ lc $nick };
911 ">>> part/$b_blue$chan$ob $b_cyan$nick$ob $b_yellow($ob$userhost$b_yellow)$ob"
918 my $nick = $event->nick;
920 $conn->ctcp_reply( $nick, join( ' ', ( $event->args ) ) );
922 ">>> ${b_green}CTCP PING$ob request from $b_cyan$nick$ob received.");
928 my $nick = $event->nick;
929 my $t = ( $event->args )[1];
931 &WARN("on_ping_reply: t == undefined.");
935 my $lag = time() - $t;
937 &status(">>> ${b_green}CTCP PING$ob reply from $b_cyan$nick$ob: $lag sec.");
943 my $msg = ( $event->args )[0];
944 $chan = lc( ( $event->to )[0] ); # CASING.
945 my $nick = $event->nick;
947 $uh = $event->userhost();
948 $nuh = $nick . '!' . $uh;
951 # TODO: move this out of hookMsg to here?
952 ( $user, $host ) = split( /\@/, $uh );
955 # rare case should this happen - catch it just in case.
956 if ( $bot_pid != $$ ) {
957 &ERROR("run-away fork; exiting.");
962 $lastWho{$chan} = $nick;
963 ### TODO: use $nick or lc $nick?
964 if ( &IsChanConf('seenStats') > 0 ) {
965 $userstats{ lc $nick }{'Count'}++;
966 $userstats{ lc $nick }{'Time'} = time();
971 if ( !$cache{ircTextCounters} ) {
972 &DEBUG("caching ircTextCounters for first time.");
973 my @str = split( /\s+/, &getChanConf('ircTextCounters') );
974 for (@str) { $_ = quotemeta($_); }
975 $cache{ircTextCounters} = join( '|', @str );
978 my $str = $cache{ircTextCounters};
979 if ( $str && $msg =~ /^($str)[\s!\.]?$/i ) {
982 &VERB( "textcounters: $x matched for $who", 2 );
983 my $c = $chan || 'PRIVATE';
985 # better to do "counter=counter+1".
986 # but that will avoid time check.
987 my ( $v, $t ) = &sqlSelect(
998 # don't allow ppl to cheat the stats :-)
999 if ( ( defined $t && $time - $t > 60 ) or ( !defined $t ) ) {
1015 &hookMsg( 'public', $chan, $nick, $msg );
1016 $chanstats{$chan}{'PublicMsg'}++;
1025 my $nick = $event->nick();
1026 my $reason = ( $event->args )[0];
1029 $msgType = 'public';
1031 ### $chan = $reason; # no.
1034 foreach ( grep !/^_default$/, keys %channels ) {
1036 # fixes inconsistent chanstats bug #1.
1037 if ( !&IsNickInChan( $nick, $_ ) ) {
1041 $chanstats{$_}{'SignOff'}++;
1044 if ( $count == scalar keys %channels ) {
1045 &DEBUG("on_quit: nick $nick was not found in any chan.");
1048 # should fix chanstats inconsistencies bug #2.
1049 if ( $reason =~ /^($mask{host})\s($mask{host})$/ ) { # netsplit.
1050 $reason = "NETSPLIT: $1 <=> $2";
1053 foreach $chan ( &getNickInChans($nick) ) {
1054 next unless ( &IsChanConf('chanlimitcheck') > 0 );
1055 next unless ( exists $channels{$_}{'l'} );
1057 &DEBUG("on_quit: netsplit detected on $_; disabling chan limit.");
1058 $conn->mode( $_, '-l' );
1061 $netsplit{ lc $nick } = time();
1062 if ( !exists $netsplitservers{$1}{$2} ) {
1063 &status("netsplit detected between $1 and $2 at ["
1066 $netsplitservers{$1}{$2} = time();
1070 my $chans = join( ' ', &getNickInChans($nick) );
1072 ">>> $b_cyan$nick$ob has signed off IRC $b_red($ob$reason$b_red)$ob [$chans]"
1076 ### ok... lets clear out the cache
1078 &delUserInfo( $nick, keys %channels );
1079 if ( exists $nuh{ lc $nick } ) {
1080 delete $nuh{ lc $nick };
1084 # well.. it's good but weird that this has happened - lets just
1085 # be quiet about it.
1087 delete $userstats{ lc $nick } if ( &IsChanConf('seenStats') > 0 );
1088 delete $chanstats{ lc $nick };
1091 # if we have a temp nick, and whoever is camping on our main nick leaves
1092 # revert to main nick. Note that Net::IRC only knows our main nick
1093 if ( $nick eq $conn->nick() ) {
1094 &status("nickchange: own nick \"$nick\" became free; changing.");
1099 sub on_targettoofast {
1102 my $nick = $event->nick();
1103 my ( $me, $chan, $why ) = $event->args();
1105 ### TODO: incomplete.
1106 if ( $why =~ /.* wait (\d+) second/ ) {
1110 if ( $sleep > $max ) {
1111 &status("targettoofast: going to sleep for $max ($sleep)...");
1115 &status("targettoofast: going to sleep for $sleep");
1118 my $delta = time() - ( $cache{sleepTime} || 0 );
1119 if ( $delta > $max + 2 ) {
1121 $cache{sleepTime} = time();
1127 if ( !exists $cache{TargetTooFast} ) {
1128 &DEBUG("on_ttf: failed: $why");
1129 $cache{TargetTooFast}++;
1137 if ( scalar( $event->args ) == 1 ) { # change.
1138 my $topic = ( $event->args )[0];
1139 my $chan = ( $event->to )[0];
1140 my $nick = $event->nick();
1144 # race condition here. To fix, change '1' to '0'.
1145 # This will keep track of topics set by bot only.
1148 # this may be fixed at a later date with topic queueing.
1151 $topic{$chan}{'Current'} = $topic if (1);
1152 $chanstats{$chan}{'Topic'}++;
1154 &status(">>> topic/$b_blue$chan$ob by $b_cyan$nick$ob -> $topic");
1157 my ( $nick, $chan, $topic ) = $event->args;
1158 if ( &IsChanConf('Topic') > 0 ) {
1159 $topic{$chan}{'Current'} = $topic;
1160 &topicAddHistory( $chan, $topic );
1163 $topic = &fixString( $topic, 1 );
1164 &status(">>> topic/$b_blue$chan$ob is $topic");
1171 my ( $myself, $chan, $setby, $time ) = $event->args();
1174 if ( time() - $time > 60 * 60 * 24 ) {
1175 $timestr = 'at ' . gmtime $time;
1178 $timestr = &Time2String( time() - $time ) . ' ago';
1181 &status(">>> set by $b_cyan$setby$ob $timestr");
1187 my $nick = $event->nick();
1190 if ( scalar $event->args() != 1 ) { # old.
1191 $ver = join ' ', $event->args();
1192 $ver =~ s/^VERSION //;
1195 $ver = ( $event->args() )[0];
1198 if ( grep /^\Q$nick\E$/i, @vernick ) {
1199 &WARN("nick $nick found in vernick ($ver); skipping.");
1202 push( @vernick, $nick );
1204 if ( $ver =~ /bitchx/i ) {
1205 $ver{bitchx}{$nick} = $ver;
1208 elsif ( $ver =~ /xc\!|xchat/i ) {
1209 $ver{xchat}{$nick} = $ver;
1212 elsif ( $ver =~ /irssi/i ) {
1213 $ver{irssi}{$nick} = $ver;
1216 elsif ( $ver =~ /epic|(Third Eye)/i ) {
1217 $ver{epic}{$nick} = $ver;
1220 elsif ( $ver =~ /ircII|PhoEniX/i ) {
1221 $ver{ircII}{$nick} = $ver;
1224 elsif ( $ver =~ /mirc/i ) {
1226 # &DEBUG("verstats: mirc: $nick => '$ver'.");
1227 $ver{mirc}{$nick} = $ver;
1229 # ok... then we get to the lesser known/used clients.
1231 elsif ( $ver =~ /ircle/i ) {
1232 $ver{ircle}{$nick} = $ver;
1235 elsif ( $ver =~ /chatzilla/i ) {
1236 $ver{chatzilla}{$nick} = $ver;
1239 elsif ( $ver =~ /pirch/i ) {
1240 $ver{pirch}{$nick} = $ver;
1243 elsif ( $ver =~ /sirc /i ) {
1244 $ver{sirc}{$nick} = $ver;
1247 elsif ( $ver =~ /kvirc/i ) {
1248 $ver{kvirc}{$nick} = $ver;
1251 elsif ( $ver =~ /eggdrop/i ) {
1252 $ver{eggdrop}{$nick} = $ver;
1255 elsif ( $ver =~ /xircon/i ) {
1256 $ver{xircon}{$nick} = $ver;
1260 &DEBUG("verstats: other: $nick => '$ver'.");
1261 $ver{other}{$nick} = $ver;
1268 my $nick = $event->nick;
1270 &status(">>> ${b_green}CTCP VERSION$ob request from $b_cyan$nick$ob");
1271 $conn->ctcp_reply( $nick, "VERSION $bot_version" );
1277 my @args = $event->args;
1278 my $str = $args[5] . '!' . $args[2] . '@' . $args[3];
1280 if ( $cache{on_who_Hack} ) {
1281 $cache{nuhInfo}{ lc $args[5] }{Nick} = $args[5];
1282 $cache{nuhInfo}{ lc $args[5] }{User} = $args[2];
1283 $cache{nuhInfo}{ lc $args[5] }{Host} = $args[3];
1284 $cache{nuhInfo}{ lc $args[5] }{NUH} = "$args[5]!$args[2]\@$args[3]";
1288 if ( $args[5] =~ /^nickserv$/i and !$nickserv ) {
1289 &DEBUG('ok... we did a who for nickserv.');
1290 &rawout("PRIVMSG NickServ :IDENTIFY $param{'nickServ_pass'}");
1293 $nuh{ lc $args[5] } = $args[5] . '!' . $args[2] . '@' . $args[3];
1299 my @args = $event->args;
1301 $nuh{ lc $args[1] } = $args[1] . '!' . $args[2] . '@' . $args[3];
1304 sub on_whoischannels {
1307 my @args = $event->args;
1309 &DEBUG("on_whoischannels: @args");
1312 sub on_useronchannel {
1315 my @args = $event->args;
1317 &DEBUG("on_useronchannel: @args");
1322 ### since joinnextchan is hooked onto on_endofnames, these are needed.
1328 my @args = $event->args;
1330 &status(">>> chanfull/$b_blue$args[1]$ob");
1338 my @args = $event->args;
1340 &status(">>> inviteonly/$b_cyan$args[1]$ob");
1348 my @args = $event->args;
1349 my $chan = $args[1];
1352 ">>> banned/$b_blue$chan$ob $b_cyan$args[0]$ob, removing autojoin for $chan"
1354 delete $chanconf{$chan}{autojoin};
1361 my @args = $event->args;
1362 my $chan = $args[1];
1364 &DEBUG("on_badchankey: args => @args, removing autojoin for $chan");
1365 delete $chanconf{$chan}{autojoin};
1372 my @args = $event->args;
1374 &DEBUG("on_useronchan: args => @args");
1382 &FIXME("on_stdin: line => \"$line\"");
1387 # vim:ts=4:sw=4:expandtab:tw=80