2 # IrcHooks.pl: IRC Hooks stuff.
5 # NOTE: Based on code by Kevin Lenzo & Patrick Cole (c) 1997
8 if (&IsParam("useStrict")) { use strict; }
12 my ($self, $event) = @_;
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 => '$_'.");
25 my ($self, $event) = @_;
26 my ($nick, @args) = ($event->nick, $event->args);
27 my $chan = ($event->to)[0];
31 if ($chan eq $ident) {
32 &status("* [$nick] @args");
34 &status("* $nick/$chan @args");
39 my ($self, $event) = @_;
40 my $msg = ($event->args)[0];
41 my $sock = ($event->to)[0];
42 my $nick = lc $event->nick();
44 if (!exists $nuh{$nick}) {
45 &DEBUG("chat: nuh{$nick} doesn't exist; trying WHOIS .");
50 ### set vars that would have been set in hookMsg.
51 $userHandle = ""; # reset.
55 $orig{message} = $msg;
57 $uh = (split /\!/, $nuh)[1];
61 if (!exists $dcc{'CHATvrfy'}{$nick}) {
62 $userHandle = &verifyUser($who, $nuh);
63 my $crypto = $users{$userHandle}{PASS};
66 ### TODO: prevent users without CRYPT chatting.
67 if (!defined $crypto) {
68 &DEBUG("todo: dcc close chat");
69 &msg($who, "nope, no guest logins allowed...");
73 if (&ckpasswd($msg, $crypto)) {
74 # stolen from eggdrop.
75 $self->privmsg($sock, "Connected to $ident");
76 $self->privmsg($sock, "Commands start with '.' (like '.quit' or '.help')");
77 $self->privmsg($sock, "Everything else goes out to the party line.");
79 &dccStatus(2) unless (exists $sched{"dccStatus"}{RUNNING});
84 &status("DCC CHAT: incorrect pass; closing connection.");
85 &DEBUG("chat: sock => '$sock'.");
87 delete $dcc{'CHAT'}{$nick};
88 &DEBUG("chat: after closing sock. FIXME");
89 ### BUG: close seizes bot. why?
93 &status("DCC CHAT: user $nick is here!");
94 &DCCBroadcast("*** $nick ($uh) joined the party line.");
96 $dcc{'CHATvrfy'}{$nick} = $userHandle;
98 return if ($userHandle eq "_default");
100 &dccsay($nick,"Flags: $users{$userHandle}{FLAGS}");
106 &status("$b_red=$b_cyan$who$b_red=$ob $message");
108 if ($message =~ s/^\.//) { # dcc chat commands.
109 ### TODO: make use of &Forker(); here?
110 &loadMyModule( $myModules{'ircdcc'} );
112 &DCCBroadcast("#$who# $message","m");
114 my $retval = &userDCC();
115 return unless (defined $retval);
116 return if ($retval eq $noreply);
118 $conn->privmsg($dcc{'CHAT'}{$who}, "Invalid command.");
120 } else { # dcc chat arena.
122 foreach (keys %{$dcc{'CHAT'}}) {
123 $conn->privmsg($dcc{'CHAT'}{$_}, "<$who> $orig{message}");
127 return 'DCC CHAT MESSAGE';
133 # what's the following for?
134 $ident = $param{'ircNick'};
136 $ircstats{'ConnectTime'} = time();
137 $ircstats{'ConnectCount'}++;
138 $ircstats{'OffTime'} += time() - $ircstats{'DisconnectTime'}
139 if (defined $ircstats{'DisconnectTime'});
142 if (!exists $users{_default}) {
143 &status("First time run... adding _default user.");
144 $users{_default}{FLAGS} = "mrt";
145 $users{_default}{HOSTS} = "*!*@*";
148 if (scalar keys %users < 2) {
149 &status("Ok... now /msg $ident PASS <pass> to get master access through DCC CHAT.");
151 # end of first time run.
153 if (&IsChanConf("wingate")) {
154 my $file = "$bot_base_dir/$param{'ircUser'}.wingate";
158 next unless (/^(\S+)\*$/);
159 push(@wingateBad, $_);
165 &ScheduleThis(1, \&setupSchedulers);
169 if (&IsParam("ircUMode")) {
170 &status("Attempting change of user modes to $param{'ircUMode'}.");
171 &rawout("MODE $ident $param{'ircUMode'}");
174 &status("End of motd. Now lets join some channels...");
175 if (!scalar @joinchan) {
176 &WARN("joinchan array is empty!!!");
177 @joinchan = &getJoinChans();
184 my ($self, $event) = @_;
185 my $type = uc( ($event->args)[1] );
186 my $nick = lc $event->nick();
188 # pity Net::IRC doesn't store nuh. Here's a hack :)
189 if (!exists $nuh{lc $nick}) {
191 $nuh{$nick} = "GETTING-NOW"; # trying.
195 if ($type eq 'SEND') { # GET for us.
196 # incoming DCC SEND. we're receiving a file.
197 my $get = ($event->args)[2];
198 open(DCCGET,">$get");
200 $self->new_get($nick,
207 } elsif ($type eq 'GET') { # SEND for us?
208 &status("DCC: Initializing SEND for $nick.");
209 $self->new_send($event->args);
210 } elsif ($type eq 'CHAT') {
211 &status("DCC: Initializing CHAT for $nick.");
212 $self->new_chat($event);
214 &WARN("${b_green}DCC $type$ob (1)");
219 my ($self, $event) = @_;
220 my $nick = $event->nick();
221 my $sock = ($event->to)[0];
223 # DCC CHAT close on fork exit workaround.
224 if ($bot_pid != $$) {
225 &WARN("run-away fork; exiting.");
229 if (exists $dcc{'SEND'}{$nick} and -f "$param{tempDir}/$nick.txt") {
230 &status("${b_green}DCC SEND$ob close from $b_cyan$nick$ob");
232 &status("dcc_close: purging $nick.txt from Debian.pl");
233 unlink "$param{tempDir}/$nick.txt";
235 delete $dcc{'SEND'}{$nick};
236 } elsif (exists $dcc{'CHAT'}{$nick} and $dcc{'CHAT'}{$nick} eq $sock) {
237 &status("${b_green}DCC CHAT$ob close from $b_cyan$nick$ob");
238 delete $dcc{'CHAT'}{$nick};
239 delete $dcc{'CHATvrfy'}{$nick};
241 &status("${b_green}DCC$ob UNKNOWN close from $b_cyan$nick$ob (2)");
246 my ($self, $event) = @_;
247 my $type = uc( ($event->args)[0] );
248 my $nick = lc $event->nick();
249 my $sock = ($event->to)[0];
253 ### BUG: who is set to bot's nick?
256 if ($type eq 'SEND') {
257 &status("${b_green}DCC lGET$ob established with $b_cyan$nick$ob");
259 } elsif ($type eq 'CHAT') {
261 ### TODO: run ScheduleThis inside on_dcc_open_chat recursively
262 ### 1,3,5,10 seconds then fail.
263 if ($nuh{$nick} eq "GETTING-NOW") {
264 &ScheduleThis(3/60, "on_dcc_open_chat", $nick, $sock);
266 on_dcc_open_chat(undef, $nick, $sock);
269 } elsif ($type eq 'SEND') {
270 &DEBUG("Starting DCC receive.");
271 foreach ($event->args) {
276 &WARN("${b_green}DCC $type$ob (3)");
281 # really custom sub to get NUH since Net::IRC doesn't appear to support
283 sub on_dcc_open_chat {
284 my(undef, $nick, $sock) = @_;
286 if ($nuh{$nick} eq "GETTING-NOW") {
287 &DEBUG("getting nuh for $nick failed. FIXME.");
291 &status("${b_green}DCC CHAT$ob established with $b_cyan$nick$ob $b_yellow($ob$nuh{$nick}$b_yellow)$ob");
293 &verifyUser($nick, $nuh{lc $nick});
295 if (!exists $users{$userHandle}{HOSTS}) {
296 &pSReply("you have no hosts defined in my user file; rejecting.");
297 ### TODO: $sock->close();
301 my $crypto = $users{$userHandle}{PASS};
302 $dcc{'CHAT'}{$nick} = $sock;
304 if (defined $crypto) {
305 &dccsay($nick,"Enter your password.");
307 &dccsay($nick,"Welcome to blootbot DCC CHAT interface, $userHandle.");
312 my ($self, $event) = @_;
313 my $from = $event->from();
314 my $what = ($event->args)[0];
316 &status("disconnect from $from ($what).");
317 $ircstats{'DisconnectTime'} = time();
318 $ircstats{'DisconnectReason'} = $what;
319 $ircstats{'DisconnectCount'}++;
320 $ircstats{'TotalTime'} += time() - $ircstats{'ConnectTime'};
322 # clear any variables on reconnection.
326 if (!$self->connect()) {
327 &WARN("not connected? help me. gonna call ircCheck() in 1800s");
328 &ScheduleThis(30, "ircCheck");
333 my ($self, $event) = @_;
334 my $chan = ($event->args)[1];
336 if (exists $cache{jointime}{$chan}) {
337 my $delta_time = sprintf("%.03f", &gettimeofday() - $cache{jointime}{$chan});
338 $delta_time = 0 if ($delta_time < 0);
340 &status("$b_blue$chan$ob: sync in ${delta_time}s.");
343 rawout("MODE $chan");
347 foreach ("o","v","") {
348 my $count = scalar(keys %{ $channels{$chan}{$_} });
349 next unless ($count);
351 $txt = "total" if ($_ eq "");
352 $txt = "voice" if ($_ eq "v");
353 $txt = "ops" if ($_ eq "o");
355 push(@array, "$count $txt");
357 my $chanstats = join(' || ', @array);
358 &status("$b_blue$chan$ob: [$chanstats]");
360 if (scalar @joinchan) { # remaining channels to join.
364 return unless (&IsChanConf("chanServ_ops") > 0);
365 return unless ($nickserv);
367 if (!exists $channels{$chan}{'o'}{$ident}) {
368 &status("ChanServ ==> Requesting ops for $chan.");
369 &rawout("PRIVMSG ChanServ :OP $chan $ident");
374 my ($self, $event) = @_;
375 my (@args) = ($event->args);
382 my ($self, $event) = @_;
383 my $chan = lc( ($event->args)[0] );
384 my $nick = $event->nick;
386 if ($nick =~ /^\Q$ident\E$/) {
387 &DEBUG("on_invite: self invite.");
392 if (exists $chanconf{$chan}) {
393 if (&validChan($chan)) {
394 &msg($who, "i'm already in \002$chan\002.");
398 &status("invited to $b_blue$_$ob by $b_cyan$who$ob");
399 &joinchan($self, $_);
404 my ($self, $event) = @_;
405 my ($user,$host) = split(/\@/, $event->userhost);
406 $chan = lc( ($event->to)[0] ); # CASING!!!!
407 $who = $event->nick();
409 $chanstats{$chan}{'Join'}++;
410 $userstats{lc $who}{'Join'} = time() if (&IsChanConf("seenStats"));
412 &joinfloodCheck($who, $chan, $event->userhost);
416 if (exists $netsplit{lc $who}) {
417 delete $netsplit{lc $who};
421 if ($netsplit and !$netsplittime) {
422 &DEBUG("on_join: ok.... re-running chanlimitCheck in 60.");
423 $conn->schedule(60, sub {
425 $netsplittime = undef;
428 $netsplittime = time();
431 # how to tell if there's a netjoin???
433 my $netsplitstr = "";
434 $netsplitstr = " $b_yellow\[${ob}NETSPLIT VICTIM$b_yellow]$ob" if ($netsplit);
435 &status(">>> join/$b_blue$chan$ob $b_cyan$who$ob $b_yellow($ob$user\@$host$b_yellow)$ob$netsplitstr");
437 $channels{$chan}{''}{$who}++;
438 $nuh = $who."!".$user."\@".$host;
439 $nuh{lc $who} = $nuh unless (exists $nuh{lc $who});
443 push(@bans, keys %{ $bans{$chan} }) if (exists $bans{$chan});
444 push(@bans, keys %{ $bans{"*"} }) if (exists $bans{"*"});
450 next unless ($nuh =~ /^$mask$/i);
452 ### TODO: check $channels{$chan}{'b'} if ban already exists.
453 foreach (keys %{ $channels{$chan}{'b'} }) {
454 &DEBUG(" bans_on_chan($chan) => $_");
457 my $reason = "no reason";
458 foreach ($chan, "*") {
459 next unless (exists $bans{$_});
460 next unless (exists $bans{$_}{$ban});
462 my @array = @{ $bans{$_}{$ban} };
464 $reason = $array[4] if ($array[4]);
469 &kick($who, $chan, $reason);
475 &rootWarn($who,$user,$host,$chan)
476 if (&IsChanConf("rootWarn") &&
477 $user =~ /^r(oo|ew|00)t$/i &&
478 $channels{$chan}{'o'}{$ident});
481 if (&IsChanConf("news") && &IsChanConf("newsKeepRead")) {
483 foreach (keys %{ $::news{$chan} }) {
484 my $t = $::newsuser{$chan}{$who};
485 next if (!defined $t);
486 next if ($t > $::news{$chan}{$_}{Time});
492 &msg($who, "+==== New news for $chan (".scalar(@new)."):");
493 # todo: show how many sec/min/etc ago?
494 my $timestr = &Time2String( time() - $::newsuser{$chan}{$who} );
495 &msg($who, "|= Last time read $timestr ago");
498 my $i = &News::getNewsItem($_);
499 my $age = time() - $::news{$chan}{$_}{Time};
500 &msg($who, sprintf("\002[\002%2d\002]\002 %s (%s)",
501 $i, $_, &Time2String($age) ) );
503 &msg($who, "to read, do 'news read <#>' or 'news read <keyword>'");
505 # lame hack to prevent dupes if we just ignore it.
506 $::newsuser{$chan}{$who} = time();
511 &chanLimitVerify($chan);
513 # used to determine sync time.
514 if ($who =~ /^$ident$/i) {
515 if (defined( my $whojoin = $cache{join}{$chan} )) {
516 &msg($chan, "Okay, I'm here. (courtesy of $whojoin)");
517 delete $cache{join}{$chan};
520 ### TODO: move this to &joinchan()?
521 $cache{jointime}{$chan} = &gettimeofday();
524 ### TODO: this may go wild on a netjoin :)
531 my ($self, $event) = @_;
532 my ($chan,$reason) = $event->args;
533 my $kicker = $event->nick;
534 my $kickee = ($event->to)[0];
535 my $uh = $event->userhost();
537 &status(">>> kick/$b_blue$chan$ob [$b$kickee!$uh$ob] by $b_cyan$kicker$ob $b_yellow($ob$reason$b_yellow)$ob");
539 $chan = lc $chan; # forgot about this, found by xsdg, 20001229.
540 $chanstats{$chan}{'Kick'}++;
542 if ($kickee eq $ident) {
543 &clearChanVars($chan);
545 &status("SELF attempting to rejoin lost channel $chan");
548 &DeleteUserInfo($kickee,$chan);
553 my ($self, $event) = @_;
554 my ($user, $host) = split(/\@/, $event->userhost);
555 my @args = $event->args();
556 my $nick = $event->nick();
557 my $chan = ($event->to)[0];
561 if ($nick eq $chan) { # UMODE
562 &status(">>> mode $b_yellow\[$ob$b@args$b_yellow\]$ob by $b_cyan$nick$ob");
564 &status(">>> mode/$b_blue$chan$ob $b_yellow\[$ob$b@args$b_yellow\]$ob by $b_cyan$nick$ob");
565 &hookMode($chan, @args);
570 my ($self, $event) = @_;
571 my $nick = $event->nick();
572 my ($myself,$chan,@args) = $event->args();
574 &hookMode(lc $chan, @args); # CASING.
578 my ($self, $event) = @_;
579 my $nick = $event->nick;
580 my $msg = ($event->args)[0];
582 ($user,$host) = split(/\@/, $event->userhost);
583 $uh = $event->userhost();
584 $nuh = $nick."!".$uh;
587 if ($nick eq $ident) { # hopefully ourselves.
588 if ($msg eq "TEST") {
589 &status("Local: Yes, we're alive.");
590 delete $cache{connect};
595 &hookMsg('private', undef, $nick, $msg);
599 my ($self, $event) = @_;
600 my @args = $event->args;
601 my $chan = lc $args[2]; # CASING, the last of them!
603 foreach (split / /, @args[3..$#args]) {
604 $channels{$chan}{'o'}{$_}++ if s/\@//;
605 $channels{$chan}{'v'}{$_}++ if s/\+//;
606 $channels{$chan}{''}{$_}++;
611 my ($self, $event) = @_;
612 my $nick = $event->nick();
613 my $newnick = ($event->args)[0];
615 if (exists $netsplit{lc $newnick}) {
616 &status("Netsplit: $newnick/$nick came back from netsplit and changed to original nick! removing from hash.");
617 delete $netsplit{lc $newnick};
621 foreach $chan (keys %channels) {
622 foreach $mode (keys %{$channels{$chan}}) {
623 next unless (exists $channels{$chan}{$mode}{$nick});
625 $channels{$chan}{$mode}{$newnick} = $channels{$chan}{$mode}{$nick};
628 &DeleteUserInfo($nick,keys %channels);
629 $nuh{lc $newnick} = $nuh{lc $nick};
630 delete $nuh{lc $nick};
632 # successful self-nick change.
633 if ($nick eq $ident) {
634 &status(">>> I materialized into $b_green$newnick$ob from $nick");
637 &status(">>> $b_cyan$nick$ob materializes into $b_green$newnick$ob");
643 my $nick = $self->nick;
644 my $newnick = substr($nick,0,7)."-";
646 &status("nick taken; changing to temporary nick.");
652 my ($self, $event) = @_;
653 my $nick = $event->nick();
654 my $chan = ($event->to)[0];
655 my $args = ($event->args)[0];
657 if ($nick =~ /^NickServ$/i) { # nickserv.
658 &status("NickServ: <== '$args'");
661 $check++ if ($args =~ /^This nickname is registered/i);
662 $check++ if ($args =~ /nickname.*owned/i);
665 &status("nickserv told us to register; doing it.");
666 if (&IsParam("nickServ_pass")) {
667 &status("NickServ: ==> Identifying.");
668 &rawout("PRIVMSG NickServ :IDENTIFY $param{'nickServ_pass'}");
671 &status("We can't tell nickserv a passwd ;(");
676 if ($args =~ /^Password a/i) {
679 } elsif ($nick =~ /^ChanServ$/i) { # chanserv.
680 &status("ChanServ: <== '$args'.");
682 if ($chan =~ /^$mask{chan}$/) { # channel notice.
683 &status("-$nick/$chan- $args");
685 $server = $nick unless (defined $server);
686 &status("-$nick- $args"); # private or server notice.
692 my ($self, $event) = @_;
693 my $chan = ($event->to)[0];
694 my $nick = $event->nick;
696 &status("!!! other called.");
697 &status("!!! $event->args");
701 my ($self, $event) = @_;
702 my $chan = lc( ($event->to)[0] ); # CASING!!!
703 my $nick = $event->nick;
704 my $userhost = $event->userhost;
706 if (exists $floodjoin{$chan}{$nick}{Time}) {
707 delete $floodjoin{$chan}{$nick};
710 $chanstats{$chan}{'Part'}++;
711 &DeleteUserInfo($nick,$chan);
712 &clearChanVars($chan) if ($nick eq $ident);
713 if (!&IsNickInAnyChan($nick) and &IsChanConf("seenStats")) {
714 delete $userstats{lc $nick};
717 &status(">>> part/$b_blue$chan$ob $b_cyan$nick$ob $b_yellow($ob$userhost$b_yellow)$ob");
721 my ($self, $event) = @_;
722 my $nick = $event->nick;
724 $self->ctcp_reply($nick, join(' ', ($event->args)));
725 &status(">>> ${b_green}CTCP PING$ob request from $b_cyan$nick$ob received.");
729 my ($self, $event) = @_;
730 my $nick = $event->nick;
731 my $lag = time() - ($event->args)[1];
733 &status(">>> ${b_green}CTCP PING$ob reply from $b_cyan$nick$ob: $lag sec.");
737 my ($self, $event) = @_;
738 my $msg = ($event->args)[0];
739 my $chan = lc( ($event->to)[0] ); # CASING.
740 my $nick = $event->nick;
741 $uh = $event->userhost();
742 $nuh = $nick."!".$uh;
743 ($user,$host) = split(/\@/, $uh);
745 if ($bot_pid != $$) {
746 &ERROR("run-away fork; exiting.");
751 if ($statcount < 200) {
752 foreach $chan (grep /[A-Z]/, keys %channels) {
753 &DEBUG("leak: chan => '$chan'.");
755 foreach $i (keys %{$channels{$chan}}) {
756 foreach (keys %{$channels{$chan}{$i}}) {
757 &DEBUG("leak: \$channels{$chan}{$i}{$_} ...");
764 $lastWho{$chan} = $nick;
765 ### TODO: use $nick or lc $nick?
766 if (&IsChanConf("seenStats")) {
767 $userstats{lc $nick}{'Count'}++;
768 $userstats{lc $nick}{'Time'} = time();
771 # if (&IsChanConf("hehCounter")) {
775 &hookMsg('public', $chan, $nick, $msg);
776 $chanstats{$chan}{'PublicMsg'}++;
780 my ($self, $event) = @_;
781 my $nick = $event->nick();
782 my $reason = ($event->args)[0];
785 foreach (keys %channels) {
786 # fixes inconsistent chanstats bug #1.
787 if (!&IsNickInChan($nick,$_)) {
791 $chanstats{$_}{'SignOff'}++;
794 if ($count == scalar keys %channels) {
795 &DEBUG("on_quit: nick $nick was not found in any chan.");
798 &DeleteUserInfo($nick, keys %channels);
800 if (exists $nuh{lc $nick}) {
801 delete $nuh{lc $nick};
803 &DEBUG("on_quit: nuh{lc $nick} does not exist! FIXME");
805 delete $userstats{lc $nick} if (&IsChanConf("seenStats"));
807 # should fix chanstats inconsistencies bug #2.
808 if ($reason=~/^($mask{host})\s($mask{host})$/) { # netsplit.
809 $reason = "NETSPLIT: $1 <=> $2";
811 if (&ChanConfList("chanlimitcheck") and !scalar keys %netsplit) {
812 &DEBUG("on_quit: netsplit detected; disabling chan limit.");
813 &rawout("MODE $chan -l");
816 $netsplit{lc $nick} = time();
817 if (!exists $netsplitservers{$1}{$2}) {
818 &status("netsplit detected between $1 and $2.");
819 $netsplitservers{$1}{$2} = time();
823 &status(">>> $b_cyan$nick$ob has signed off IRC $b_red($ob$reason$b_red)$ob");
824 if ($nick =~ /^\Q$ident\E$/) {
825 &DEBUG("^^^ THIS SHOULD NEVER HAPPEN.");
828 if ($nick !~ /^\Q$ident\E$/ and $nick =~ /^\Q$param{'ircNick'}\E$/i) {
829 &status("own nickname became free; changing.");
830 &nick($param{'ircNick'});
834 sub on_targettoofast {
835 my ($self, $event) = @_;
836 my $nick = $event->nick();
837 my($me,$chan,$why) = $event->args();
839 ### TODO: incomplete.
840 ### .* wait (\d+) second/) {
841 &status("on_ttf: X1 $msg") if (defined $msg);
843 &status("going to sleep for $sleep...");
850 my ($self, $event) = @_;
852 if (scalar($event->args) == 1) { # change.
853 my $topic = ($event->args)[0];
854 my $chan = ($event->to)[0];
855 my $nick = $event->nick();
859 # race condition here. To fix, change '1' to '0'.
860 # This will keep track of topics set by bot only.
863 # this may be fixed at a later date with topic queueing.
866 $topic{$chan}{'Current'} = $topic if (1);
867 $chanstats{$chan}{'Topic'}++;
869 &status(">>> topic/$b_blue$chan$ob by $b_cyan$nick$ob -> $topic");
871 my ($nick, $chan, $topic) = $event->args;
872 if (&IsChanConf("topic")) {
873 $topic{$chan}{'Current'} = $topic;
874 &topicAddHistory($chan,$topic);
877 $topic = &fixString($topic, 1);
878 &status(">>> topic/$b_blue$chan$ob is $topic");
883 my ($self, $event) = @_;
884 my ($myself,$chan,$setby,$time) = $event->args();
887 if (time() - $time > 60*60*24) {
888 $timestr = "at ". localtime $time;
890 $timestr = &Time2String(time() - $time) ." ago";
893 &status(">>> set by $b_cyan$setby$ob $timestr");
897 my ($self, $event) = @_;
898 my $nick = $event->nick();
901 if (scalar $event->args() != 1) { # old.
902 $ver = join ' ', $event->args();
903 $ver =~ s/^VERSION //;
905 $ver = ($event->args())[0];
908 if (grep /^\Q$nick\E$/i, @vernick) {
909 &WARN("nick $nick found in vernick; skipping.");
912 push(@vernick, $nick);
914 if ($ver =~ /bitchx/i) {
915 $ver{bitchx}{$nick} = $ver;
916 } elsif ($ver =~ /xc\!|xchat/i) {
917 $ver{xchat}{$nick} = $ver;
918 } elsif ($ver =~ /irssi/i) {
919 $ver{irssi}{$nick} = $ver;
920 } elsif ($ver =~ /epic/i) {
921 $ver{epic}{$nick} = $ver;
922 } elsif ($ver =~ /mirc/i) {
923 $ver{mirc}{$nick} = $ver;
924 } elsif ($ver =~ /ircle/i) {
925 $ver{ircle}{$nick} = $ver;
926 } elsif ($ver =~ /ircII/i) {
927 $ver{ircII}{$nick} = $ver;
928 } elsif ($ver =~ /sirc /i) {
929 $ver{sirc}{$nick} = $ver;
930 } elsif ($ver =~ /kvirc/i) {
931 $ver{kvirc}{$nick} = $ver;
932 } elsif ($ver =~ /eggdrop/i) {
933 $ver{eggdrop}{$nick} = $ver;
934 } elsif ($ver =~ /xircon/i) {
935 $ver{xircon}{$nick} = $ver;
937 $ver{other}{$nick} = $ver;
942 my ($self, $event) = @_;
943 my $nick = $event->nick;
945 &status(">>> ${b_green}CTCP VERSION$ob request from $b_cyan$nick$ob");
946 $self->ctcp_reply($nick, "VERSION $bot_version");
950 my ($self, $event) = @_;
951 my @args = $event->args;
953 $nuh{lc $args[5]} = $args[5]."!".$args[2]."\@".$args[3];
957 my ($self, $event) = @_;
958 my @args = $event->args;
960 &DEBUG("on_whoisuser: @args");
962 $nuh{lc $args[1]} = $args[1]."!".$args[2]."\@".$args[3];
965 #######################################################################
966 ####### IRC HOOK HELPERS IRC HOOK HELPERS IRC HOOK HELPERS ########
967 #######################################################################
970 # Usage: &hookMode($chan, $modes, @targets);
972 my ($chan, $modes, @targets) = @_;
975 $chan = lc $chan; # !!!.
978 foreach $mode (split(//, $modes)) {
980 if ($mode =~ /[-+]/) {
981 $parity = 1 if ($mode eq "+");
982 $parity = 0 if ($mode eq "-");
987 if ($mode =~ /[bklov]/) {
988 my $target = shift @targets;
991 $chanstats{$chan}{'Op'}++ if ($mode eq "o");
992 $chanstats{$chan}{'Ban'}++ if ($mode eq "b");
994 $chanstats{$chan}{'Deop'}++ if ($mode eq "o");
995 $chanstats{$chan}{'Unban'}++ if ($mode eq "b");
998 # modes w/ target affecting nick => cache it.
999 if ($mode =~ /[bov]/) {
1000 $channels{$chan}{$mode}{$target}++ if $parity;
1001 delete $channels{$chan}{$mode}{$target} if !$parity;
1004 if ($mode =~ /[l]/) {
1005 $channels{$chan}{$mode} = $target if $parity;
1006 delete $channels{$chan}{$mode} if !$parity;
1010 # important channel modes, targetless.
1011 if ($mode =~ /[mt]/) {
1012 $channels{$chan}{$mode}++ if $parity;
1013 delete $channels{$chan}{$mode} if !$parity;
1019 ($msgType, $chan, $who, $message) = @_;
1020 my $skipmessage = 0;
1022 $addressedother = 0;
1023 $orig{message} = $message;
1027 $message =~ s/[\cA-\c_]//ig; # strip control characters
1028 $message =~ s/^\s+//; # initial whitespaces.
1029 $who =~ tr/A-Z/a-z/; # lowercase.
1034 if ($msgType =~ /private/) {
1039 # addressing revamped by the xk.
1040 ### below needs to be fixed...
1041 if (&IsParam("addressCharacter")) {
1042 if ($message =~ s/^$param{'addressCharacter'}//) {
1048 if ($message =~ /^($mask{nick})([\;\:\>\, ]+) */) {
1049 my $newmessage = $';
1050 if ($1 =~ /^\Q$ident\E$/i) {
1051 $message = $newmessage;
1054 # ignore messages addressed to other people or unaddressed.
1055 $skipmessage++ if ($2 ne "" and $2 !~ /^ /);
1060 # Determine floodwho.
1062 if ($msgType =~ /public/i) { # public.
1063 $floodwho = $c = lc $chan;
1064 } elsif ($msgType =~ /private/i) { # private.
1065 $floodwho = lc $who;
1067 &DEBUG("FIXME: floodwho = ???");
1070 my $val = &getChanConfDefault("floodRepeat", "2:10", $c);
1071 my ($count, $interval) = split /:/, $val;
1073 # flood repeat protection.
1075 my $time = $flood{$floodwho}{$message} || 0;
1077 if ($msgType eq "public" and (time() - $time < $interval)) {
1078 ### public != personal who so the below is kind of pointless.
1080 foreach (keys %flood) {
1081 next if (/^\Q$floodwho\E$/);
1082 next if (defined $chan and /^\Q$chan\E$/);
1084 push(@who, grep /^\Q$message\E$/i, keys %{ $flood{$_} });
1087 return if ($lobotomized);
1090 &msg($who, "you already said what ".
1091 join(' ', @who)." have said.");
1093 &msg($who,"Someone already said that ". (time - $time) ." seconds ago" );
1096 ### TODO: delete old floodwarn{} keys.
1098 if (!exists $floodwarn{$floodwho}) {
1101 $floodwarn++ if (time() - $floodwarn{$floodwho} > $interval);
1105 &status("FLOOD repetition detected from $floodwho.");
1106 $floodwarn{$floodwho} = time();
1113 &status("$b_cyan$who$ob is short-addressing me");
1114 } elsif ($msgType eq "private") { # private.
1115 &status("$b_cyan$who$ob is /msg'ing me");
1117 &status("$b_cyan$who$ob is addressing me");
1120 $flood{$floodwho}{$message} = time();
1121 } elsif ($msgType eq "public" and &IsChanConf("kickOnRepeat")) {
1122 # unaddressed, public only.
1124 ### TODO: use a separate "short-time" hash.
1126 @data = keys %{ $flood{$floodwho} } if (exists $flood{$floodwho});
1129 $val = &getChanConfDefault("floodMessages", "5:30", $c);
1130 ($count, $interval) = split /:/, $val;
1132 # flood overflow protection.
1134 foreach (keys %{$flood{$floodwho}}) {
1135 next unless (time() - $flood{$floodwho}{$_} > $interval);
1136 delete $flood{$floodwho}{$_};
1139 my $i = scalar keys %{$flood{$floodwho}};
1141 &msg($who,"overflow of messages ($i > $count)");
1142 &status("FLOOD overflow detected from $floodwho; ignoring");
1144 my $expire = $param{'ignoreAutoExpire'} || 5;
1145 &ignoreAdd("*!$uh", $chan, $expire, "flood overflow auto-detected.");
1149 $flood{$floodwho}{$message} = time();
1153 if ($msgType =~ /public/i) { # public.
1154 $talkchannel = $chan;
1155 &status("<$orig{who}/$chan> $orig{message}");
1156 push(@ignore, keys %{ $ignore{$chan} }) if (exists $ignore{$chan});
1157 } elsif ($msgType =~ /private/i) { # private.
1158 &status("[$orig{who}] $orig{message}");
1159 $talkchannel = undef;
1162 &DEBUG("unknown msgType => $msgType.");
1164 push(@ignore, keys %{ $ignore{"*"} }) if (exists $ignore{"*"});
1166 if ((!$skipmessage or &IsChanConf("seenStoreAll")) and
1167 &IsChanConf("seen") and
1168 $msgType =~ /public/
1170 $seencache{$who}{'time'} = time();
1171 $seencache{$who}{'nick'} = $orig{who};
1172 $seencache{$who}{'host'} = $uh;
1173 $seencache{$who}{'chan'} = $talkchannel;
1174 $seencache{$who}{'msg'} = $orig{message};
1175 $seencache{$who}{'msgcount'}++;
1178 return if ($skipmessage);
1179 return unless (&IsParam("minVolunteerLength") or $addressed);
1184 next unless (eval { $nuh =~ /^$_$/i });
1186 &status("IGNORE <$who> $message");
1191 if (!defined $userHandle) {
1192 &DEBUG("line 1074: need verifyUser?");
1193 &verifyUser($who, $nuh);
1196 &DEBUG("hookMsg: 'nuh' not defined?");
1199 ### For extra debugging purposes...
1200 if ($_ = &process()) {
1201 # &DEBUG("IrcHooks: process returned '$_'.");
1207 sub chanLimitVerify {
1209 my $l = $channels{$chan}{'l'};
1211 # only change it if it's not set.
1212 if (defined $l and &IsChanConf("chanlimitcheck")) {
1213 my $plus = &getChanConfDefault("chanlimitcheckPlus", 5, $chan);
1214 my $nowl = scalar(keys %{ $channels{$chan}{''} });
1215 my $delta = $nowl - $l;
1219 &WARN("clc: stupid to have plus at $plus, fix it!");
1222 ### todo: check if we have ops.
1223 ### todo: if not, check if nickserv/chanserv is avail.
1224 ### todo: unify code with chanlimitcheck()
1226 &WARN("clc: nowl($nowl) > l($l) - 3");
1227 &rawout("MODE $chan +l ".($nowl+$plus) );