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];
32 if ($chan eq $ident) {
33 &status("* [$nick] @args");
35 &status("* $nick/$chan @args");
42 my $msg = ($event->args)[0];
43 my $sock = ($event->to)[0];
44 my $nick = lc $event->nick();
46 if (!exists $nuh{$nick}) {
47 &DEBUG("chat: nuh{$nick} doesn't exist; trying WHOIS .");
52 ### set vars that would have been set in hookMsg.
53 $userHandle = ""; # reset.
57 $orig{message} = $msg;
59 $uh = (split /\!/, $nuh)[1];
60 $h = (split /\@/, $uh)[1];
64 if (!exists $dcc{'CHATvrfy'}{$nick}) {
65 $userHandle = &verifyUser($who, $nuh);
66 my $crypto = $users{$userHandle}{PASS};
69 if ($userHandle eq "_default") {
70 &WARN("DCC CHAT: _default/guest not allowed.");
74 ### TODO: prevent users without CRYPT chatting.
75 if (!defined $crypto) {
76 &TODO("dcc close chat");
77 &msg($who, "nope, no guest logins allowed...");
81 if (&ckpasswd($msg, $crypto)) {
82 # stolen from eggdrop.
83 $conn->privmsg($sock, "Connected to $ident");
84 $conn->privmsg($sock, "Commands start with '.' (like '.quit' or '.help')");
85 $conn->privmsg($sock, "Everything else goes out to the party line.");
87 &dccStatus(2) unless (exists $sched{"dccStatus"}{RUNNING});
92 &status("DCC CHAT: incorrect pass; closing connection.");
93 &DEBUG("chat: sock => '$sock'.");
95 delete $dcc{'CHAT'}{$nick};
96 &FIXME("chat: after closing sock.");
97 ### BUG: close seizes bot. why?
101 &status("DCC CHAT: user $nick is here!");
102 &DCCBroadcast("*** $nick ($uh) joined the party line.");
104 $dcc{'CHATvrfy'}{$nick} = $userHandle;
106 return if ($userHandle eq "_default");
108 &dccsay($nick,"Flags: $users{$userHandle}{FLAGS}");
114 &status("$b_red=$b_cyan$who$b_red=$ob $message");
116 if ($message =~ s/^\.//) { # dcc chat commands.
117 ### TODO: make use of &Forker(); here?
118 &loadMyModule('UserDCC');
120 &DCCBroadcast("#$who# $message","m");
122 my $retval = &userDCC();
123 return unless (defined $retval);
124 return if ($retval eq $noreply);
126 $conn->privmsg($dcc{'CHAT'}{$who}, "Invalid command.");
128 } else { # dcc chat arena.
130 foreach (keys %{ $dcc{'CHAT'} }) {
131 $conn->privmsg($dcc{'CHAT'}{$_}, "<$who> $orig{message}");
135 return 'DCC CHAT MESSAGE';
138 # is there isoff? how do we know if someone signs off?
142 my $x1 = ($event->args)[0];
143 my $x2 = ($event->args)[1];
146 &DEBUG("on_ison: x1 = '$x1', x2 => '$x2'");
153 $ident = $conn->nick();
154 $ircstats{'ConnectTime'} = time();
155 $ircstats{'ConnectCount'}++;
156 if (defined $ircstats{'DisconnectTime'}) {
157 $ircstats{'OffTime'} += time() - $ircstats{'DisconnectTime'};
161 if (!exists $users{_default}) {
162 &status("!!! First time run... adding _default user.");
163 $users{_default}{FLAGS} = "amrt";
164 $users{_default}{HOSTS}{"*!*@*"} = 1;
167 if (scalar keys %users < 2) {
169 &status("!!! Ok. Now type '/msg $ident PASS <pass>' to get master access through DCC CHAT.");
172 # end of first time run.
174 if (&IsChanConf('Wingate')) {
175 my $file = "$bot_base_dir/$param{'ircUser'}.wingate";
179 next unless (/^(\S+)\*$/);
180 push(@wingateBad, $_);
186 &ScheduleThis(1, "setupSchedulers");
190 if (&IsParam("ircUMode")) {
191 &VERB("Attempting change of user modes to $param{'ircUMode'}.", 2);
192 if ($param{'ircUMode'} !~ /^[-+]/) {
193 &WARN("ircUMode had no +- prefix; adding +");
194 $param{'ircUMode'} = "+".$param{'ircUMode'};
197 &rawout("MODE $ident $param{'ircUMode'}");
200 # ok, we're free to do whatever we want now. go for it!
203 # add ourself to notify.
204 $conn->ison($conn->nick());
206 # Q, as on quakenet.org.
207 if (&IsParam("Q_pass")) {
208 &status("Authing to Q...");
209 &rawout("PRIVMSG Q\@CServe.quakenet.org :AUTH $param{'Q_user'} $param{'Q_pass'}");
212 &status("End of motd. Now lets join some channels...");
219 # &DEBUG("endofwho: chan => $chan");
220 $chan ||= ($event->args)[1];
221 # &DEBUG("endofwho: chan => $chan");
223 if (exists $cache{countryStats}) {
231 my $type = uc( ($event->args)[1] );
232 my $nick = lc $event->nick();
234 &status("on_dcc type=$type nick=$nick sock=$sock");
236 # pity Net::IRC doesn't store nuh. Here's a hack :)
237 if (!exists $nuh{lc $nick}) {
239 $nuh{$nick} = "GETTING-NOW"; # trying.
243 if ($type eq 'SEND') { # GET for us.
244 # incoming DCC SEND. we're receiving a file.
245 my $get = ($event->args)[2];
246 &status("DCC: not Initializing GET from $nick to '$param{tempDir}/$get'");
247 # FIXME: do we want to get anything?
249 #open(DCCGET,">$param{tempDir}/$get");
250 #$conn->new_get($event, \*DCCGET);
252 } elsif ($type eq 'GET') { # SEND for us?
253 &status("DCC: not Initializing SEND for $nick.");
254 # FIXME: do we want to do anything?
256 $conn->new_send($event->args);
258 } elsif ($type eq 'CHAT') {
259 &status("DCC: Initializing CHAT for $nick.");
260 $conn->new_chat($event);
261 # $conn->new_chat(1, $nick, $event->host);
264 &WARN("${b_green}DCC $type$ob (1)");
271 my $nick = $event->nick();
272 my $sock = ($event->to)[0];
274 # DCC CHAT close on fork exit workaround.
275 if ($bot_pid != $$) {
276 &WARN("run-away fork; exiting.");
280 if (exists $dcc{'SEND'}{$nick} and -f "$param{tempDir}/$nick.txt") {
281 &status("${b_green}DCC SEND$ob close from $b_cyan$nick$ob");
283 &status("dcc_close: purging DCC send $nick.txt");
284 unlink "$param{tempDir}/$nick.txt";
286 delete $dcc{'SEND'}{$nick};
287 } elsif (exists $dcc{'CHAT'}{$nick} and $dcc{'CHAT'}{$nick} eq $sock) {
288 &status("${b_green}DCC CHAT$ob close from $b_cyan$nick$ob");
289 delete $dcc{'CHAT'}{$nick};
290 delete $dcc{'CHATvrfy'}{$nick};
292 &status("${b_green}DCC$ob UNKNOWN close from $b_cyan$nick$ob (2)");
299 my $type = uc( ($event->args)[0] );
300 my $nick = lc $event->nick();
301 my $sock = ($event->to)[0];
303 &status("on_dcc_open type=$type nick=$nick sock=$sock");
307 ### BUG: who is set to bot's nick?
310 if ($type eq 'SEND') {
311 &status("${b_green}DCC lGET$ob established with $b_cyan$nick$ob");
313 } elsif ($type eq 'CHAT') {
315 ### TODO: run ScheduleThis inside on_dcc_open_chat recursively
316 ### 1,3,5,10 seconds then fail.
317 if ($nuh{$nick} eq "GETTING-NOW") {
318 &ScheduleThis(3/60, "on_dcc_open_chat", $nick, $sock);
320 on_dcc_open_chat(undef, $nick, $sock);
323 } elsif ($type eq 'SEND') {
324 &status("Starting DCC receive.");
325 foreach ($event->args) {
326 &status(" => '$_'.");
330 &WARN("${b_green}DCC $type$ob (3)");
334 # really custom sub to get NUH since Net::IRC doesn't appear to support
336 sub on_dcc_open_chat {
337 my(undef, $nick, $sock) = @_;
339 if ($nuh{$nick} eq "GETTING-NOW") {
340 &FIXME("getting nuh for $nick failed.");
344 &status("${b_green}DCC CHAT$ob established with $b_cyan$nick$ob $b_yellow($ob$nuh{$nick}$b_yellow)$ob");
346 &verifyUser($nick, $nuh{lc $nick});
348 if (!exists $users{$userHandle}{HOSTS}) {
349 &performStrictReply("you have no hosts defined in my user file; rejecting.");
354 my $crypto = $users{$userHandle}{PASS};
355 $dcc{'CHAT'}{$nick} = $sock;
357 # TODO: don't make DCC CHAT established in the first place.
358 if ($userHandle eq "_default") {
359 &dccsay($nick, "_default/guest not allowed");
364 if (defined $crypto) {
365 &status("DCC CHAT: going to use ".$nick."'s crypt.");
366 &dccsay($nick,"Enter your password.");
368 # &dccsay($nick,"Welcome to blootbot DCC CHAT interface, $userHandle.");
375 my $from = $event->from();
376 my $what = ($event->args)[0];
377 my $mynick=$conn->nick();
379 &status("$mynick disconnect from $from ($what).");
380 $ircstats{'DisconnectTime'} = time();
381 $ircstats{'DisconnectReason'} = $what;
382 $ircstats{'DisconnectCount'}++;
383 $ircstats{'TotalTime'} += time() - $ircstats{'ConnectTime'}
384 if ($ircstats{'ConnectTime'});
386 # clear any variables on reconnection.
391 if (!defined $conn) {
392 &WARN("on_disconnect: self is undefined! WTF");
393 &DEBUG("running function irc... lets hope this works.");
398 &WARN("scheduling call ircCheck() in 60s");
400 &ScheduleThis(1, "ircCheck");
406 my $chan = ($event->args)[1];
408 # sync time should be done in on_endofwho like in BitchX
409 if (exists $cache{jointime}{$chan}) {
410 my $delta_time = sprintf("%.03f", &timedelta($cache{jointime}{$chan}) );
411 $delta_time = 0 if ($delta_time <= 0);
412 if ($delta_time > 100) {
413 &WARN("endofnames: delta_time > 100 ($delta_time)");
416 &status("$b_blue$chan$ob: sync in ${delta_time}s.");
423 foreach ("o","v","") {
424 my $count = scalar(keys %{ $channels{$chan}{$_} });
425 next unless ($count);
427 $txt = "total" if ($_ eq "");
428 $txt = "voice" if ($_ eq "v");
429 $txt = "ops" if ($_ eq "o");
431 push(@array, "$count $txt");
433 my $chanstats = join(' || ', @array);
434 &status("$b_blue$chan$ob: [$chanstats]");
436 &chanServCheck($chan);
437 # schedule used to solve ircu (OPN) "target too fast" problems.
438 $conn->schedule(5, sub { &joinNextChan(); } );
444 my (@args) = ($event->args);
453 my $chan = lc( ($event->args)[0] );
454 my $nick = $event->nick;
456 if ($nick =~ /^\Q$ident\E$/) {
457 &DEBUG("on_invite: self invite.");
462 if (exists $chanconf{$chan}) {
463 # it's still buggy :/
464 if (&validChan($chan)) {
465 &msg($who, "i'm already in \002$chan\002.");
469 &status("invited to $b_blue$chan$ob by $b_cyan$nick$ob");
477 my ($user,$host) = split(/\@/, $event->userhost);
478 $chan = lc( ($event->to)[0] ); # CASING!!!!
479 $who = $event->nick();
481 my $i = scalar(keys %{ $channels{$chan} });
482 my $j = $cache{maxpeeps}{$chan} || 0;
484 if (!&IsParam("noSHM") && time() > ($sched{shmFlush}{TIME} || time()) + 3600) {
485 &DEBUG("looks like schedulers died somewhere... restarting...");
489 $chanstats{$chan}{'Join'}++;
490 $userstats{lc $who}{'Join'} = time() if (&IsChanConf("seenStats") > 0);
491 $cache{maxpeeps}{$chan} = $i if ($i > $j);
493 &joinfloodCheck($who, $chan, $event->userhost);
497 if (exists $netsplit{lc $who}) {
498 delete $netsplit{lc $who};
501 if (!scalar keys %netsplit) {
502 &DEBUG("on_join: netsplit hash is now empty!");
503 undef %netsplitservers;
504 &netsplitCheck(); # any point in running this?
509 if ($netsplit and !exists $cache{netsplit}) {
510 &VERB("on_join: ok.... re-running chanlimitCheck in 60.",2);
511 $conn->schedule(60, sub {
513 delete $cache{netsplit};
516 $cache{netsplit} = time();
519 # how to tell if there's a netjoin???
521 my $netsplitstr = "";
522 $netsplitstr = " $b_yellow\[${ob}NETSPLIT VICTIM$b_yellow]$ob" if ($netsplit);
523 &status(">>> join/$b_blue$chan$ob $b_cyan$who$ob $b_yellow($ob$user\@$host$b_yellow)$ob$netsplitstr");
525 $channels{$chan}{''}{$who}++;
526 $nuh = $who."!".$user."\@".$host;
527 $nuh{lc $who} = $nuh unless (exists $nuh{lc $who});
531 push(@bans, keys %{ $bans{$chan} }) if (exists $bans{$chan});
532 push(@bans, keys %{ $bans{"*"} }) if (exists $bans{"*"});
539 next unless ($nuh =~ /^$mask$/i);
541 ### TODO: check $channels{$chan}{'b'} if ban already exists.
542 foreach (keys %{ $channels{$chan}{'b'} }) {
543 &DEBUG(" bans_on_chan($chan) => $_");
546 my $reason = "no reason";
547 foreach ($chan, "*") {
548 next unless (exists $bans{$_});
549 next unless (exists $bans{$_}{$ban});
551 my @array = @{ $bans{$_}{$ban} };
553 $reason = $array[4] if ($array[4]);
558 &kick($who, $chan, $reason);
563 # no need to go further.
564 return if ($netsplit);
567 if ($who =~ /^\Q$ident\E$/i) {
568 if (defined( my $whojoin = $cache{join}{$chan} )) {
569 &msg($chan, "Okay, I'm here. (courtesy of $whojoin)");
570 delete $cache{join}{$chan};
571 &joinNextChan(); # hack.
574 ### TODO: move this to &joinchan()?
575 $cache{jointime}{$chan} = &timeget();
582 &rootWarn($who,$user,$host,$chan) if (
583 &IsChanConf('RootWarn') &&
584 $user =~ /^~?r(oo|ew|00)t$/i
588 if (&IsChanConf('News') && &IsChanConf('newsKeepRead')) {
589 if (!&loadMyModule('News')) { # just in case.
590 &DEBUG('could not load news.');
592 &News::latest($chan);
597 if (&IsChanConf('botmail')) {
598 &botmail::check(lc $who);
608 my ($chan,$reason) = $event->args;
609 my $kicker = $event->nick;
610 my $kickee = ($event->to)[0];
611 my $uh = $event->userhost();
613 &status(">>> kick/$b_blue$chan$ob [$b$kickee!$uh$ob] by $b_cyan$kicker$ob $b_yellow($ob$reason$b_yellow)$ob");
615 $chan = lc $chan; # forgot about this, found by xsdg, 20001229.
616 $chanstats{$chan}{'Kick'}++;
618 if ($kickee eq $ident) {
619 &clearChanVars($chan);
621 &status("SELF attempting to rejoin lost channel $chan");
624 &delUserInfo($kickee,$chan);
631 my ($user, $host) = split(/\@/, $event->userhost);
632 my @args = $event->args();
633 my $nick = $event->nick();
634 $chan = ($event->to)[0];
636 # last element is empty... so nuke it.
637 pop @args while ($args[$#args] eq "");
639 if ($nick eq $chan) { # UMODE
640 &status(">>> mode $b_yellow\[$ob$b@args$b_yellow\]$ob by $b_cyan$nick$ob");
642 &status(">>> mode/$b_blue$chan$ob $b_yellow\[$ob$b@args$b_yellow\]$ob by $b_cyan$nick$ob");
643 &hookMode($nick, @args);
650 my ($myself, undef,@args) = $event->args();
651 my $nick = $event->nick();
652 $chan = ($event->args())[1];
654 &hookMode($nick, @args);
660 my $nick = $event->nick;
661 my $msg = ($event->args)[0];
663 ($user,$host) = split(/\@/, $event->userhost);
664 $uh = $event->userhost();
665 $nuh = $nick."!".$uh;
669 if ($nick eq $ident) { # hopefully ourselves.
670 if ($msg eq "TEST") {
671 &status("IRCTEST: Yes, we're alive.");
672 delete $cache{connect};
677 &hookMsg('private', undef, $nick, $msg);
686 my @args = $event->args;
687 my $chan = lc $args[2]; # CASING, the last of them!
689 foreach (split / /, @args[3..$#args]) {
690 $channels{$chan}{'o'}{$_}++ if s/\@//;
691 $channels{$chan}{'v'}{$_}++ if s/\+//;
692 $channels{$chan}{''}{$_}++;
699 my $nick = $event->nick();
700 my $newnick = ($event->args)[0];
702 if (exists $netsplit{lc $newnick}) {
703 &status("Netsplit: $newnick/$nick came back from netsplit and changed to original nick! removing from hash.");
704 delete $netsplit{lc $newnick};
705 &netsplitCheck() if (time() != $sched{netsplitCheck}{TIME});
709 foreach $chan (keys %channels) {
710 foreach $mode (keys %{ $channels{$chan} }) {
711 next unless (exists $channels{$chan}{$mode}{$nick});
713 $channels{$chan}{$mode}{$newnick} = $channels{$chan}{$mode}{$nick};
716 # TODO: do %flood* aswell.
718 &delUserInfo($nick, keys %channels);
719 $nuh{lc $newnick} = $nuh{lc $nick};
720 delete $nuh{lc $nick};
722 if ($nick eq $ident) {
723 &status(">>> I materialized into $b_green$newnick$ob from $nick");
726 &status(">>> $b_cyan$nick$ob materializes into $b_green$newnick$ob");
727 my $mynick=$conn->nick();
728 if ($nick =~ /^\Q$mynick\E$/i) {
736 my $nick = $conn->nick();
737 #my $newnick = $nick . int(rand 10);
738 my $newnick = $nick . "_";
740 &DEBUG("on_nick_taken: nick => $nick");
742 &status("nick taken ($nick); preparing nick change.");
745 #$conn->schedule(5, sub {
746 &status("nick taken; changing to temporary nick ($nick -> $newnick).");
754 my $nick = $event->nick();
755 my $chan = ($event->to)[0];
756 my $args = ($event->args)[0];
758 if ($nick =~ /^NickServ$/i) { # nickserv.
759 &status("NickServ: <== '$args'");
762 $check++ if ($args =~ /^This nickname is registered/i);
763 $check++ if ($args =~ /nickname.*owned/i);
766 &status("nickserv told us to register; doing it.");
768 if (&IsParam("nickServ_pass")) {
769 &status("NickServ: ==> Identifying.");
770 &rawout("PRIVMSG NickServ :IDENTIFY $param{'nickServ_pass'}");
773 &status("We can't tell nickserv a passwd ;(");
778 if ($args =~ /^Password a/i) {
781 foreach ( &ChanConfList("chanServ_ops") ) {
782 next unless &chanServCheck($_);
784 &DEBUG("nickserv activated or restarted; doing chanserv check.");
791 } elsif ($nick =~ /^ChanServ$/i) { # chanserv.
792 &status("ChanServ: <== '$args'.");
795 if ($chan =~ /^$mask{chan}$/) { # channel notice.
796 &status("-$nick/$chan- $args");
798 $server = $nick unless (defined $server);
799 &status("-$nick- $args"); # private or server notice.
807 my $chan = ($event->to)[0];
808 my $nick = $event->nick;
810 &status("!!! other called.");
811 &status("!!! $event->args");
817 $chan = lc( ($event->to)[0] ); # CASING!!!
818 my $mynick = $conn->nick();
819 my $nick = $event->nick;
820 my $userhost = $event->userhost;
824 if (!exists $channels{$chan}) {
825 &DEBUG("on_part: found out $mynick is on $chan!");
826 $channels{$chan} = 1;
829 if (exists $floodjoin{$chan}{$nick}{Time}) {
830 delete $floodjoin{$chan}{$nick};
833 $chanstats{$chan}{'Part'}++;
834 &delUserInfo($nick,$chan);
835 if ($nick eq $ident) {
836 &clearChanVars($chan);
839 if (!&IsNickInAnyChan($nick) and &IsChanConf("seenStats") > 0) {
840 delete $userstats{lc $nick};
843 &status(">>> part/$b_blue$chan$ob $b_cyan$nick$ob $b_yellow($ob$userhost$b_yellow)$ob");
849 my $nick = $event->nick;
851 $conn->ctcp_reply($nick, join(' ', ($event->args)));
852 &status(">>> ${b_green}CTCP PING$ob request from $b_cyan$nick$ob received.");
858 my $nick = $event->nick;
859 my $t = ($event->args)[1];
861 &WARN("on_ping_reply: t == undefined.");
865 my $lag = time() - $t;
867 &status(">>> ${b_green}CTCP PING$ob reply from $b_cyan$nick$ob: $lag sec.");
873 my $msg = ($event->args)[0];
874 $chan = lc( ($event->to)[0] ); # CASING.
875 my $nick = $event->nick;
877 $uh = $event->userhost();
878 $nuh = $nick."!".$uh;
880 # TODO: move this out of hookMsg to here?
881 ($user,$host) = split(/\@/, $uh);
884 # rare case should this happen - catch it just in case.
885 if ($bot_pid != $$) {
886 &ERROR("run-away fork; exiting.");
891 $lastWho{$chan} = $nick;
892 ### TODO: use $nick or lc $nick?
893 if (&IsChanConf("seenStats") > 0) {
894 $userstats{lc $nick}{'Count'}++;
895 $userstats{lc $nick}{'Time'} = time();
900 if (!$cache{ircTextCounters}) {
901 &DEBUG("caching ircTextCounters for first time.");
902 my @str = split(/\s+/, &getChanConf("ircTextCounters"));
903 for (@str) { $_ = quotemeta($_); }
904 $cache{ircTextCounters} = join('|', @str);
907 my $str = $cache{ircTextCounters};
908 if ($str && $msg =~ /^($str)[\s!\.]?$/i) {
911 &VERB("textcounters: $x matched for $who",2);
912 my $c = $chan || "PRIVATE";
914 # better to do "counter=counter+1".
915 # but that will avoid time check.
916 my ($v,$t) = &sqlSelect("stats", "counter,time", {
923 # don't allow ppl to cheat the stats :-)
924 if (defined $t && $time - $t > 60) {
925 &sqlReplace("stats", {
935 &hookMsg('public', $chan, $nick, $msg);
936 $chanstats{$chan}{'PublicMsg'}++;
945 my $nick = $event->nick();
946 my $reason = ($event->args)[0];
951 ### $chan = $reason; # no.
954 foreach (grep !/^_default$/, keys %channels) {
955 # fixes inconsistent chanstats bug #1.
956 if (!&IsNickInChan($nick,$_)) {
960 $chanstats{$_}{'SignOff'}++;
963 if ($count == scalar keys %channels) {
964 &DEBUG("on_quit: nick $nick was not found in any chan.");
967 # should fix chanstats inconsistencies bug #2.
968 if ($reason =~ /^($mask{host})\s($mask{host})$/) { # netsplit.
969 $reason = "NETSPLIT: $1 <=> $2";
972 foreach $chan ( &getNickInChans($nick) ) {
973 next unless ( &IsChanConf("chanlimitcheck") );
974 next unless ( exists $channels{$_}{'l'} );
976 &DEBUG("on_quit: netsplit detected on $_; disabling chan limit.");
977 $conn->mode($_, "-l");
980 $netsplit{lc $nick} = time();
981 if (!exists $netsplitservers{$1}{$2}) {
982 &status("netsplit detected between $1 and $2 at [".scalar(gmtime)."]");
983 $netsplitservers{$1}{$2} = time();
987 my $chans = join(' ', &getNickInChans($nick) );
988 &status(">>> $b_cyan$nick$ob has signed off IRC $b_red($ob$reason$b_red)$ob [$chans]");
991 ### ok... lets clear out the cache
993 &delUserInfo($nick, keys %channels);
994 if (exists $nuh{lc $nick}) {
995 delete $nuh{lc $nick};
997 # well.. it's good but weird that this has happened - lets just
1000 delete $userstats{lc $nick} if (&IsChanConf("seenStats") > 0);
1001 delete $chanstats{lc $nick};
1004 # if we have a temp nick, and whoever is camping on our main nick leaves
1005 # revert to main nick. Note that Net::IRC only knows our main nick
1006 if ($nick eq $conn->nick()) {
1007 &status("nickchange: own nick \"$nick\" became free; changing.");
1012 sub on_targettoofast {
1015 my $nick = $event->nick();
1016 my($me,$chan,$why) = $event->args();
1018 ### TODO: incomplete.
1019 if ($why =~ /.* wait (\d+) second/) {
1023 if ($sleep > $max) {
1024 &status("targettoofast: going to sleep for $max ($sleep)...");
1027 &status("targettoofast: going to sleep for $sleep");
1030 my $delta = time() - ($cache{sleepTime} || 0);
1031 if ($delta > $max+2) {
1033 $cache{sleepTime} = time();
1039 if (!exists $cache{TargetTooFast}) {
1040 &DEBUG("on_ttf: failed: $why");
1041 $cache{TargetTooFast}++;
1049 if (scalar($event->args) == 1) { # change.
1050 my $topic = ($event->args)[0];
1051 my $chan = ($event->to)[0];
1052 my $nick = $event->nick();
1056 # race condition here. To fix, change '1' to '0'.
1057 # This will keep track of topics set by bot only.
1060 # this may be fixed at a later date with topic queueing.
1063 $topic{$chan}{'Current'} = $topic if (1);
1064 $chanstats{$chan}{'Topic'}++;
1066 &status(">>> topic/$b_blue$chan$ob by $b_cyan$nick$ob -> $topic");
1068 my ($nick, $chan, $topic) = $event->args;
1069 if (&IsChanConf('Topic')) {
1070 $topic{$chan}{'Current'} = $topic;
1071 &topicAddHistory($chan,$topic);
1074 $topic = &fixString($topic, 1);
1075 &status(">>> topic/$b_blue$chan$ob is $topic");
1082 my ($myself,$chan,$setby,$time) = $event->args();
1085 if (time() - $time > 60*60*24) {
1086 $timestr = "at ". gmtime $time;
1088 $timestr = &Time2String(time() - $time) ." ago";
1091 &status(">>> set by $b_cyan$setby$ob $timestr");
1097 my $nick = $event->nick();
1100 if (scalar $event->args() != 1) { # old.
1101 $ver = join ' ', $event->args();
1102 $ver =~ s/^VERSION //;
1104 $ver = ($event->args())[0];
1107 if (grep /^\Q$nick\E$/i, @vernick) {
1108 &WARN("nick $nick found in vernick ($ver); skipping.");
1111 push(@vernick, $nick);
1113 if ($ver =~ /bitchx/i) {
1114 $ver{bitchx}{$nick} = $ver;
1116 } elsif ($ver =~ /xc\!|xchat/i) {
1117 $ver{xchat}{$nick} = $ver;
1119 } elsif ($ver =~ /irssi/i) {
1120 $ver{irssi}{$nick} = $ver;
1122 } elsif ($ver =~ /epic|(Third Eye)/i) {
1123 $ver{epic}{$nick} = $ver;
1125 } elsif ($ver =~ /ircII|PhoEniX/i) {
1126 $ver{ircII}{$nick} = $ver;
1128 } elsif ($ver =~ /mirc/i) {
1129 # &DEBUG("verstats: mirc: $nick => '$ver'.");
1130 $ver{mirc}{$nick} = $ver;
1132 # ok... then we get to the lesser known/used clients.
1133 } elsif ($ver =~ /ircle/i) {
1134 $ver{ircle}{$nick} = $ver;
1136 } elsif ($ver =~ /chatzilla/i) {
1137 $ver{chatzilla}{$nick} = $ver;
1139 } elsif ($ver =~ /pirch/i) {
1140 $ver{pirch}{$nick} = $ver;
1142 } elsif ($ver =~ /sirc /i) {
1143 $ver{sirc}{$nick} = $ver;
1145 } elsif ($ver =~ /kvirc/i) {
1146 $ver{kvirc}{$nick} = $ver;
1148 } elsif ($ver =~ /eggdrop/i) {
1149 $ver{eggdrop}{$nick} = $ver;
1151 } elsif ($ver =~ /xircon/i) {
1152 $ver{xircon}{$nick} = $ver;
1155 &DEBUG("verstats: other: $nick => '$ver'.");
1156 $ver{other}{$nick} = $ver;
1163 my $nick = $event->nick;
1165 &status(">>> ${b_green}CTCP VERSION$ob request from $b_cyan$nick$ob");
1166 $conn->ctcp_reply($nick, "VERSION $bot_version");
1172 my @args = $event->args;
1173 my $str = $args[5]."!".$args[2]."\@".$args[3];
1175 if ($cache{on_who_Hack}) {
1176 $cache{nuhInfo}{lc $args[5]}{Nick} = $args[5];
1177 $cache{nuhInfo}{lc $args[5]}{User} = $args[2];
1178 $cache{nuhInfo}{lc $args[5]}{Host} = $args[3];
1179 $cache{nuhInfo}{lc $args[5]}{NUH} = "$args[5]!$args[2]\@$args[3]";
1183 if ($args[5] =~ /^nickserv$/i and !$nickserv) {
1184 &DEBUG("ok... we did a who for nickserv.");
1185 &rawout("PRIVMSG NickServ :IDENTIFY $param{'nickServ_pass'}");
1188 $nuh{lc $args[5]} = $args[5]."!".$args[2]."\@".$args[3];
1194 my @args = $event->args;
1196 $nuh{lc $args[1]} = $args[1]."!".$args[2]."\@".$args[3];
1199 sub on_whoischannels {
1202 my @args = $event->args;
1204 &DEBUG("on_whoischannels: @args");
1207 sub on_useronchannel {
1210 my @args = $event->args;
1212 &DEBUG("on_useronchannel: @args");
1217 ### since joinnextchan is hooked onto on_endofnames, these are needed.
1223 my @args = $event->args;
1225 &status(">>> chanfull/$b_blue$args[1]$ob");
1233 my @args = $event->args;
1235 &status(">>> inviteonly/$b_cyan$args[1]$ob");
1243 my @args = $event->args;
1244 my $chan = $args[1];
1246 &status(">>> banned/$b_blue$chan$ob $b_cyan$args[0]$ob, removing autojoin for $chan");
1247 delete $chanconf{$chan}{autojoin};
1254 my @args = $event->args;
1255 my $chan = $args[1];
1257 &DEBUG("on_badchankey: args => @args, removing autojoin for $chan");
1258 delete $chanconf{$chan}{autojoin};
1265 my @args = $event->args;
1267 &DEBUG("on_useronchan: args => @args");
1275 &FIXME("on_stdin: line => \"$line\"");