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 ) {
173 &status("!!! Ok. Now type '/msg $ident PASS <pass>' to get master access through DCC CHAT.");
176 # end of first time run.
178 if ( &IsChanConf('Wingate') > 0 ) {
179 my $file = "$bot_base_dir/$param{'ircUser'}.wingate";
183 next unless (/^(\S+)\*$/);
184 push( @wingateBad, $_ );
190 &ScheduleThis( 1, 'setupSchedulers' );
194 if ( &IsParam('ircUMode') ) {
195 &VERB( "Attempting change of user modes to $param{'ircUMode'}.", 2 );
196 if ( $param{'ircUMode'} !~ /^[-+]/ ) {
197 &WARN('ircUMode had no +- prefix; adding +');
198 $param{'ircUMode'} = '+' . $param{'ircUMode'};
201 &rawout("MODE $ident $param{'ircUMode'}");
204 # ok, we're free to do whatever we want now. go for it!
207 # add ourself to notify.
208 $conn->ison( $conn->nick() );
210 # Q, as on quakenet.org.
211 if ( &IsParam('Q_pass') ) {
212 &status('Authing to Q...');
213 &rawout("PRIVMSG Q\@CServe.quakenet.org :AUTH $param{'Q_user'} $param{'Q_pass'}");
216 &status("$ident End of motd. Now lets join some channels...");
225 # &DEBUG("endofwho: chan => $chan");
226 $chan ||= ( $event->args )[1];
228 # &DEBUG("endofwho: chan => $chan");
230 if ( exists $cache{countryStats} ) {
238 my $type = uc( ( $event->args )[1] );
239 my $nick = lc $event->nick();
241 &status("on_dcc type=$type nick=$nick sock=$sock");
243 # pity Net::IRC doesn't store nuh. Here's a hack :)
244 if ( !exists $nuh{ lc $nick } ) {
246 $nuh{$nick} = 'GETTING-NOW'; # trying.
250 if ( $type eq 'SEND' ) { # GET for us.
251 # incoming DCC SEND. we're receiving a file.
252 my $get = ( $event->args )[2];
254 "DCC: not Initializing GET from $nick to '$param{tempDir}/$get'");
256 # FIXME: do we want to get anything?
259 #open(DCCGET,">$param{tempDir}/$get");
260 #$conn->new_get($event, \*DCCGET);
263 elsif ( $type eq 'GET' ) { # SEND for us?
264 &status("DCC: not Initializing SEND for $nick.");
266 # FIXME: do we want to do anything?
268 $conn->new_send( $event->args );
271 elsif ( $type eq 'CHAT' ) {
272 &status("DCC: Initializing CHAT for $nick.");
273 $conn->new_chat($event);
275 # $conn->new_chat(1, $nick, $event->host);
279 &WARN("${b_green}DCC $type$ob (1)");
286 my $nick = $event->nick();
287 my $sock = ( $event->to )[0];
289 # DCC CHAT close on fork exit workaround.
290 if ( $bot_pid != $$ ) {
291 &WARN('run-away fork; exiting.');
295 if ( exists $dcc{'SEND'}{$nick} and -f "$param{tempDir}/$nick.txt" ) {
296 &status("${b_green}DCC SEND$ob close from $b_cyan$nick$ob");
298 &status("dcc_close: purging DCC send $nick.txt");
299 unlink "$param{tempDir}/$nick.txt";
301 delete $dcc{'SEND'}{$nick};
303 elsif ( exists $dcc{'CHAT'}{$nick} and $dcc{'CHAT'}{$nick} eq $sock ) {
304 &status("${b_green}DCC CHAT$ob close from $b_cyan$nick$ob");
305 delete $dcc{'CHAT'}{$nick};
306 delete $dcc{'CHATvrfy'}{$nick};
309 &status("${b_green}DCC$ob UNKNOWN close from $b_cyan$nick$ob (2)");
316 my $type = uc( ( $event->args )[0] );
317 my $nick = lc $event->nick();
318 my $sock = ( $event->to )[0];
320 &status("on_dcc_open type=$type nick=$nick sock=$sock");
324 ### BUG: who is set to bot's nick?
327 if ( $type eq 'SEND' ) {
328 &status("${b_green}DCC lGET$ob established with $b_cyan$nick$ob");
331 elsif ( $type eq 'CHAT' ) {
334 ### TODO: run ScheduleThis inside on_dcc_open_chat recursively
335 ### 1,3,5,10 seconds then fail.
336 if ( $nuh{$nick} eq 'GETTING-NOW' ) {
337 &ScheduleThis( 3 / 60, 'on_dcc_open_chat', $nick, $sock );
340 on_dcc_open_chat( undef, $nick, $sock );
344 elsif ( $type eq 'SEND' ) {
345 &status('Starting DCC receive.');
346 foreach ( $event->args ) {
347 &status(" => '$_'.");
352 &WARN("${b_green}DCC $type$ob (3)");
356 # really custom sub to get NUH since Net::IRC doesn't appear to support
358 sub on_dcc_open_chat {
359 my ( undef, $nick, $sock ) = @_;
361 if ( $nuh{$nick} eq 'GETTING-NOW' ) {
362 &FIXME("getting nuh for $nick failed.");
367 "${b_green}DCC CHAT$ob established with $b_cyan$nick$ob $b_yellow($ob$nuh{$nick}$b_yellow)$ob"
370 &verifyUser( $nick, $nuh{ lc $nick } );
372 if ( !exists $users{$userHandle}{HOSTS} ) {
374 'you have no hosts defined in my user file; rejecting.');
379 my $crypto = $users{$userHandle}{PASS};
380 $dcc{'CHAT'}{$nick} = $sock;
382 # TODO: don't make DCC CHAT established in the first place.
383 if ( $userHandle eq '_default' ) {
384 &dccsay( $nick, '_default/guest not allowed' );
389 if ( defined $crypto ) {
390 &status( "DCC CHAT: going to use $nick\'s crypt." );
391 &dccsay( $nick, 'Enter your password.' );
395 # &dccsay($nick,"Welcome to infobot DCC CHAT interface, $userHandle.");
402 my $from = $event->from();
403 my $what = ( $event->args )[0];
404 my $mynick = $conn->nick();
406 &status("$mynick disconnect from $from ($what).");
407 $ircstats{'DisconnectTime'} = time();
408 $ircstats{'DisconnectReason'} = $what;
409 $ircstats{'DisconnectCount'}++;
410 $ircstats{'TotalTime'} += time() - $ircstats{'ConnectTime'}
411 if ( $ircstats{'ConnectTime'} );
413 # clear any variables on reconnection.
418 if ( !defined $conn ) {
419 &WARN('on_disconnect: self is undefined! WTF');
420 &DEBUG('running function irc... lets hope this works.');
425 &WARN('scheduling call ircCheck() in 60s');
427 &ScheduleThis( 1, 'ircCheck' );
433 my $chan = ( $event->args )[1];
435 # sync time should be done in on_endofwho like in BitchX
436 if ( exists $cache{jointime}{$chan} ) {
438 sprintf( '%.03f', &timedelta( $cache{jointime}{$chan} ) );
439 $delta_time = 0 if ( $delta_time <= 0 );
440 if ( $delta_time > 100 ) {
441 &WARN("endofnames: delta_time > 100 ($delta_time)");
444 &status("$b_blue$chan$ob: sync in ${delta_time}s.");
451 foreach ( 'o', 'v', '' ) {
452 my $count = scalar( keys %{ $channels{$chan}{$_} } );
453 next unless ($count);
455 $txt = 'total' if ( $_ eq '' );
456 $txt = 'voice' if ( $_ eq 'v' );
457 $txt = 'ops' if ( $_ eq 'o' );
459 push( @array, "$count $txt" );
461 my $chanstats = join( ' || ', @array );
462 &status("$b_blue$chan$ob: [$chanstats]");
464 &chanServCheck($chan);
466 # schedule used to solve ircu (OPN) 'target too fast' problems.
467 $conn->schedule( 5, sub { &joinNextChan(); } );
473 my (@args) = ( $event->args );
482 my $chan = lc( ( $event->args )[0] );
483 my $nick = $event->nick;
485 if ( $nick =~ /^\Q$ident\E$/ ) {
486 &DEBUG('on_invite: self invite.');
491 if ( exists $chanconf{$chan} ) {
493 # it's still buggy :/
494 if ( &validChan($chan) ) {
495 &msg( $who, "i'm already in \002$chan\002." );
500 &status("invited to $b_blue$chan$ob by $b_cyan$nick$ob");
508 my ( $user, $host ) = split( /\@/, $event->userhost );
509 $chan = lc( ( $event->to )[0] ); # CASING!!!!
510 $who = $event->nick();
512 my $i = scalar( keys %{ $channels{$chan} } );
513 my $j = $cache{maxpeeps}{$chan} || 0;
515 if ( !&IsParam('noSHM')
516 && time() > ( $sched{shmFlush}{TIME} || time() ) + 3600 )
518 &DEBUG('looks like schedulers died somewhere... restarting...');
522 $chanstats{$chan}{'Join'}++;
523 $userstats{ lc $who }{'Join'} = time() if ( &IsChanConf('seenStats') > 0 );
524 $cache{maxpeeps}{$chan} = $i if ( $i > $j );
526 &joinfloodCheck( $who, $chan, $event->userhost );
530 if ( exists $netsplit{ lc $who } ) {
531 delete $netsplit{ lc $who };
534 if ( !scalar keys %netsplit ) {
535 &DEBUG('on_join: netsplit hash is now empty!');
536 undef %netsplitservers;
537 &netsplitCheck(); # any point in running this?
542 if ( $netsplit and !exists $cache{netsplit} ) {
543 &VERB('on_join: ok.... re-running chanlimitCheck in 60.', 2);
548 delete $cache{netsplit};
552 $cache{netsplit} = time();
555 # how to tell if there's a netjoin???
557 my $netsplitstr = '';
558 $netsplitstr = " $b_yellow\[${ob}NETSPLIT VICTIM$b_yellow]$ob"
561 ">>> join/$b_blue$chan$ob $b_cyan$who$ob $b_yellow($ob$user\@$host$b_yellow)$ob$netsplitstr"
564 $channels{$chan}{''}{$who}++;
565 $nuh = $who . '!' . $user . '@' . $host;
566 $nuh{ lc $who } = $nuh unless ( exists $nuh{ lc $who } );
570 push( @bans, keys %{ $bans{$chan} } ) if ( exists $bans{$chan} );
571 push( @bans, keys %{ $bans{'*'} } ) if ( exists $bans{'*'} );
578 next unless ( $nuh =~ /^$mask$/i );
580 ### TODO: check $channels{$chan}{'b'} if ban already exists.
581 foreach ( keys %{ $channels{$chan}{'b'} } ) {
582 &DEBUG(" bans_on_chan($chan) => $_");
585 my $reason = 'no reason';
586 foreach ( $chan, '*' ) {
587 next unless ( exists $bans{$_} );
588 next unless ( exists $bans{$_}{$ban} );
590 my @array = @{ $bans{$_}{$ban} };
592 $reason = $array[4] if ( $array[4] );
597 &kick( $who, $chan, $reason );
602 # no need to go further.
603 return if ($netsplit);
606 if ( $who =~ /^\Q$ident\E$/i ) {
607 if ( defined( my $whojoin = $cache{join}{$chan} ) ) {
608 &msg( $chan, "Okay, I'm here. (courtesy of $whojoin)" );
609 delete $cache{join}{$chan};
610 &joinNextChan(); # hack.
613 ### TODO: move this to &joinchan()?
614 $cache{jointime}{$chan} = &timeget();
621 &rootWarn( $who, $user, $host, $chan )
622 if ( &IsChanConf('RootWarn') > 0
623 && $user =~ /^~?r(oo|ew|00)t$/i );
625 ### emit a message based on who just joined
626 &onjoin( $who, $user, $host, $chan ) if ( &IsChanConf('OnJoin') > 0 );
629 if ( &IsChanConf('News') > 0 && &IsChanConf('newsKeepRead') > 0 ) {
630 if ( !&loadMyModule('News') ) { # just in case.
631 &DEBUG('could not load news.');
634 &News::latest($chan);
639 if ( &IsChanConf('botmail') > 0 ) {
640 &botmail::check( lc $who );
650 my ( $chan, $reason ) = $event->args;
651 my $kicker = $event->nick;
652 my $kickee = ( $event->to )[0];
653 my $uh = $event->userhost();
656 ">>> kick/$b_blue$chan$ob [$b$kickee!$uh$ob] by $b_cyan$kicker$ob $b_yellow($ob$reason$b_yellow)$ob"
659 $chan = lc $chan; # forgot about this, found by xsdg, 20001229.
660 $chanstats{$chan}{'Kick'}++;
662 if ( $kickee eq $ident ) {
663 &clearChanVars($chan);
665 &status("SELF attempting to rejoin lost channel $chan");
669 &delUserInfo( $kickee, $chan );
676 my ( $user, $host ) = split( /\@/, $event->userhost );
677 my @args = $event->args();
678 my $nick = $event->nick();
679 $chan = ( $event->to )[0];
681 # last element is empty... so nuke it.
682 pop @args while ( $args[$#args] eq '' );
684 if ( $nick eq $chan ) { # UMODE
686 ">>> mode $b_yellow\[$ob$b@args$b_yellow\]$ob by $b_cyan$nick$ob");
690 ">>> mode/$b_blue$chan$ob $b_yellow\[$ob$b@args$b_yellow\]$ob by $b_cyan$nick$ob"
692 &hookMode( $nick, @args );
699 my ( $myself, undef, @args ) = $event->args();
700 my $nick = $event->nick();
701 $chan = ( $event->args() )[1];
703 &hookMode( $nick, @args );
709 my $nick = $event->nick;
710 my $msg = ( $event->args )[0];
712 ( $user, $host ) = split( /\@/, $event->userhost );
713 $uh = $event->userhost();
714 $nuh = $nick . '!' . $uh;
718 if ( $nick eq $ident ) { # hopefully ourselves.
719 if ( $msg eq 'TEST' ) {
720 &status("IRCTEST: Yes, we're alive.");
721 delete $cache{connect};
726 &hookMsg( 'private', undef, $nick, $msg );
735 my @args = $event->args;
736 my $chan = lc $args[2]; # CASING, the last of them!
738 foreach ( split / /, @args[ 3 .. $#args ] ) {
739 $channels{$chan}{'o'}{$_}++ if s/\@//;
740 $channels{$chan}{'v'}{$_}++ if s/\+//;
741 $channels{$chan}{''}{$_}++;
748 my $nick = $event->nick();
749 my $newnick = ( $event->args )[0];
751 if ( exists $netsplit{ lc $newnick } ) {
753 "Netsplit: $newnick/$nick came back from netsplit and changed to original nick! removing from hash."
755 delete $netsplit{ lc $newnick };
756 &netsplitCheck() if ( time() != $sched{netsplitCheck}{TIME} );
760 foreach $chan ( keys %channels ) {
761 foreach $mode ( keys %{ $channels{$chan} } ) {
762 next unless ( exists $channels{$chan}{$mode}{$nick} );
764 $channels{$chan}{$mode}{$newnick} = $channels{$chan}{$mode}{$nick};
768 # TODO: do %flood* aswell.
770 &delUserInfo( $nick, keys %channels );
771 $nuh{ lc $newnick } = $nuh{ lc $nick };
772 delete $nuh{ lc $nick };
774 if ( $nick eq $conn->nick() ) {
775 &status(">>> I materialized into $b_green$newnick$ob from $nick");
777 $conn->nick($newnick);
780 &status(">>> $b_cyan$nick$ob materializes into $b_green$newnick$ob");
781 my $mynick = $conn->nick();
782 if ( $nick =~ /^\Q$mynick\E$/i ) {
790 my $nick = $conn->nick();
792 #my $newnick = $nick . int(rand 10);
793 my $newnick = $nick . '_';
795 &DEBUG("on_nick_taken: nick => $nick");
797 &status("nick taken ($nick); preparing nick change.");
801 #$conn->schedule(5, sub {
802 &status("nick taken; changing to temporary nick ($nick -> $newnick).");
811 my $nick = $event->nick();
812 my $chan = ( $event->to )[0];
813 my $args = ( $event->args )[0];
814 my $mynick = $conn->nick();
816 if ( $nick =~ /^NickServ$/i ) { # nickserv.
817 &status("NickServ: $mynick <== '$args'");
820 $check++ if ( $args =~ /^This nickname is registered/i );
821 $check++ if ( $args =~ /nickname.*owned/i );
824 &status("nickserv told $mynick to register; doing it.");
826 if ( &IsParam('nickServ_pass') ) {
827 &status("NickServ: ==> Identifying as $mynick.");
828 &rawout("PRIVMSG NickServ :IDENTIFY $param{'nickServ_pass'}");
832 &status("$mynick can't tell nickserv a passwd ;(");
837 if ( $args =~ /^Password a/i ) {
840 foreach ( &ChanConfList('chanServ_ops') ) {
841 next unless &chanServCheck($_);
843 &DEBUG('nickserv activated or restarted; doing chanserv check.');
851 elsif ( $nick =~ /^ChanServ$/i ) { # chanserv.
852 &status("ChanServ: <== '$args'.");
856 if ( $chan =~ /^$mask{chan}$/ ) { # channel notice.
857 &status("-$nick/$chan- $args");
860 $server = $nick unless ( defined $server );
861 &status("-$nick- $args"); # private or server notice.
869 my $chan = ( $event->to )[0];
870 my $nick = $event->nick;
872 &status('!!! other called.');
873 &status("!!! $event->args");
879 $chan = lc( ( $event->to )[0] ); # CASING!!!
880 my $mynick = $conn->nick();
881 my $nick = $event->nick;
882 my $userhost = $event->userhost;
886 if ( !exists $channels{$chan} ) {
887 &DEBUG("on_part: found out $mynick is on $chan!");
888 $channels{$chan} = 1;
891 if ( exists $floodjoin{$chan}{$nick}{Time} ) {
892 delete $floodjoin{$chan}{$nick};
895 $chanstats{$chan}{'Part'}++;
896 &delUserInfo( $nick, $chan );
897 if ( $nick eq $ident ) {
898 &clearChanVars($chan);
901 if ( !&IsNickInAnyChan($nick) and &IsChanConf('seenStats') > 0 ) {
902 delete $userstats{ lc $nick };
906 ">>> part/$b_blue$chan$ob $b_cyan$nick$ob $b_yellow($ob$userhost$b_yellow)$ob"
913 my $nick = $event->nick;
915 $conn->ctcp_reply( $nick, join( ' ', ( $event->args ) ) );
917 ">>> ${b_green}CTCP PING$ob request from $b_cyan$nick$ob received.");
923 my $nick = $event->nick;
924 my $t = ( $event->args )[1];
926 &WARN('on_ping_reply: t == undefined.');
930 my $lag = time() - $t;
932 &status(">>> ${b_green}CTCP PING$ob reply from $b_cyan$nick$ob: $lag sec.");
938 my $msg = ( $event->args )[0];
939 $chan = lc( ( $event->to )[0] ); # CASING.
940 my $nick = $event->nick;
942 $uh = $event->userhost();
943 $nuh = $nick . '!' . $uh;
946 # TODO: move this out of hookMsg to here?
947 ( $user, $host ) = split( /\@/, $uh );
950 # rare case should this happen - catch it just in case.
951 if ( $bot_pid != $$ ) {
952 &ERROR('run-away fork; exiting.');
957 $lastWho{$chan} = $nick;
958 ### TODO: use $nick or lc $nick?
959 if ( &IsChanConf('seenStats') > 0 ) {
960 $userstats{ lc $nick }{'Count'}++;
961 $userstats{ lc $nick }{'Time'} = time();
966 if ( !$cache{ircTextCounters} ) {
967 &DEBUG('caching ircTextCounters for first time.');
968 my @str = split( /\s+/, &getChanConf('ircTextCounters') );
969 for (@str) { $_ = quotemeta($_); }
970 $cache{ircTextCounters} = join( '|', @str );
973 my $str = $cache{ircTextCounters};
974 if ( $str && $msg =~ /^($str)[\s!\.]?$/i ) {
977 &VERB( "textcounters: $x matched for $who", 2 );
978 my $c = $chan || 'PRIVATE';
980 # better to do 'counter=counter+1'.
981 # but that will avoid time check.
982 my ( $v, $t ) = &sqlSelect(
993 # don't allow ppl to cheat the stats :-)
994 if ( ( defined $t && $time - $t > 60 ) or ( !defined $t ) ) {
1010 &hookMsg( 'public', $chan, $nick, $msg );
1011 $chanstats{$chan}{'PublicMsg'}++;
1020 my $nick = $event->nick();
1021 my $reason = ( $event->args )[0];
1024 $msgType = 'public';
1026 ### $chan = $reason; # no.
1029 foreach ( grep !/^_default$/, keys %channels ) {
1031 # fixes inconsistent chanstats bug #1.
1032 if ( !&IsNickInChan( $nick, $_ ) ) {
1036 $chanstats{$_}{'SignOff'}++;
1039 if ( $count == scalar keys %channels ) {
1040 &DEBUG("on_quit: nick $nick was not found in any chan.");
1043 # should fix chanstats inconsistencies bug #2.
1044 if ( $reason =~ /^($mask{host})\s($mask{host})$/ ) { # netsplit.
1045 $reason = "NETSPLIT: $1 <=> $2";
1048 foreach $chan ( &getNickInChans($nick) ) {
1049 next unless ( &IsChanConf('chanlimitcheck') > 0 );
1050 next unless ( exists $channels{$_}{'l'} );
1052 &DEBUG("on_quit: netsplit detected on $_; disabling chan limit.");
1053 $conn->mode( $_, '-l' );
1056 $netsplit{ lc $nick } = time();
1057 if ( !exists $netsplitservers{$1}{$2} ) {
1058 &status("netsplit detected between $1 and $2 at ["
1061 $netsplitservers{$1}{$2} = time();
1065 my $chans = join( ' ', &getNickInChans($nick) );
1067 ">>> $b_cyan$nick$ob has signed off IRC $b_red($ob$reason$b_red)$ob [$chans]"
1071 ### ok... lets clear out the cache
1073 &delUserInfo( $nick, keys %channels );
1074 if ( exists $nuh{ lc $nick } ) {
1075 delete $nuh{ lc $nick };
1079 # well.. it's good but weird that this has happened - lets just
1080 # be quiet about it.
1082 delete $userstats{ lc $nick } if ( &IsChanConf('seenStats') > 0 );
1083 delete $chanstats{ lc $nick };
1086 # if we have a temp nick, and whoever is camping on our main nick leaves
1087 # revert to main nick. Note that Net::IRC only knows our main nick
1088 if ( $nick eq $conn->nick() ) {
1089 &status("nickchange: own nick \"$nick\" became free; changing.");
1094 sub on_targettoofast {
1097 my $nick = $event->nick();
1098 my ( $me, $chan, $why ) = $event->args();
1100 ### TODO: incomplete.
1101 if ( $why =~ /.* wait (\d+) second/ ) {
1105 if ( $sleep > $max ) {
1106 &status("targettoofast: going to sleep for $max ($sleep)...");
1110 &status("targettoofast: going to sleep for $sleep");
1113 my $delta = time() - ( $cache{sleepTime} || 0 );
1114 if ( $delta > $max + 2 ) {
1116 $cache{sleepTime} = time();
1122 if ( !exists $cache{TargetTooFast} ) {
1123 &DEBUG("on_ttf: failed: $why");
1124 $cache{TargetTooFast}++;
1132 if ( scalar( $event->args ) == 1 ) { # change.
1133 my $topic = ( $event->args )[0];
1134 my $chan = ( $event->to )[0];
1135 my $nick = $event->nick();
1139 # race condition here. To fix, change '1' to '0'.
1140 # This will keep track of topics set by bot only.
1143 # this may be fixed at a later date with topic queueing.
1146 $topic{$chan}{'Current'} = $topic if (1);
1147 $chanstats{$chan}{'Topic'}++;
1149 &status(">>> topic/$b_blue$chan$ob by $b_cyan$nick$ob -> $topic");
1152 my ( $nick, $chan, $topic ) = $event->args;
1153 if ( &IsChanConf('Topic') > 0 ) {
1154 $topic{$chan}{'Current'} = $topic;
1155 &topicAddHistory( $chan, $topic );
1158 $topic = &fixString( $topic, 1 );
1159 &status(">>> topic/$b_blue$chan$ob is $topic");
1166 my ( $myself, $chan, $setby, $time ) = $event->args();
1169 if ( time() - $time > 60 * 60 * 24 ) {
1170 $timestr = 'at ' . gmtime $time;
1173 $timestr = &Time2String( time() - $time ) . ' ago';
1176 &status(">>> set by $b_cyan$setby$ob $timestr");
1182 my $nick = $event->nick();
1185 if ( scalar $event->args() != 1 ) { # old.
1186 $ver = join ' ', $event->args();
1187 $ver =~ s/^VERSION //;
1190 $ver = ( $event->args() )[0];
1193 if ( grep /^\Q$nick\E$/i, @vernick ) {
1194 &WARN("nick $nick found in vernick ($ver); skipping.");
1197 push( @vernick, $nick );
1199 &DEBUG("on_crversion: Got '$ver' from $nick");
1201 if ( $ver =~ /bitchx/i ) {
1202 $ver{bitchx}{$nick} = $ver;
1205 elsif ( $ver =~ /infobot/i ) {
1206 $ver{infobot}{$nick} = $ver;
1209 elsif ( $ver =~ /(xc\!|xchat)/i ) {
1210 $ver{xchat}{$nick} = $ver;
1213 elsif ( $ver =~ /irssi/i ) {
1214 $ver{irssi}{$nick} = $ver;
1217 elsif ( $ver =~ /(epic|Third Eye)/i ) {
1218 $ver{epic}{$nick} = $ver;
1221 elsif ( $ver =~ /(ircII|PhoEniX)/i ) {
1222 $ver{ircII}{$nick} = $ver;
1225 elsif ( $ver =~ /mirc/i ) {
1226 # Apparently, mIRC gets the reply as "VERSION " and doesnt like the
1227 # space, so mirc matching is considered bugged.
1228 $ver{mirc}{$nick} = $ver;
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