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("chat: no pass required.");
71 } elsif (&ckpasswd($msg, $crypto)) {
72 # stolen from eggdrop.
73 $self->privmsg($sock, "Connected to $ident");
74 $self->privmsg($sock, "Commands start with '.' (like '.quit' or '.help')");
75 $self->privmsg($sock, "Everything else goes out to the party line.");
77 &dccStatus(2) unless (exists $sched{"dccStatus"}{RUNNING});
82 &status("DCC CHAT: incorrect pass; closing connection.");
83 &DEBUG("chat: sock => '$sock'.");
85 delete $dcc{'CHAT'}{$nick};
86 &DEBUG("chat: after closing sock. FIXME");
87 ### BUG: close seizes bot. why?
91 &status("DCC CHAT: user $nick is here!");
92 &DCCBroadcast("*** $nick ($uh) joined the party line.");
94 $dcc{'CHATvrfy'}{$nick} = $userHandle;
96 return if ($userHandle eq "_default");
98 &dccsay($nick,"Flags: $users{$userHandle}{FLAGS}");
104 &status("$b_red=$b_cyan$who$b_red=$ob $message");
106 if ($message =~ s/^\.//) { # dcc chat commands.
107 ### TODO: make use of &Forker(); here?
108 &loadMyModule( $myModules{'ircdcc'} );
110 &DCCBroadcast("#$who# $message","m");
112 my $retval = &userDCC();
113 return unless (defined $retval);
114 return if ($retval eq $noreply);
116 $conn->privmsg($dcc{'CHAT'}{$who}, "Invalid command.");
118 } else { # dcc chat arena.
120 foreach (keys %{$dcc{'CHAT'}}) {
121 $conn->privmsg($dcc{'CHAT'}{$_}, "<$who> $orig{message}");
125 return 'DCC CHAT MESSAGE';
131 # what's the following for?
132 $ident = $param{'ircNick'};
134 $ircstats{'ConnectTime'} = time();
135 $ircstats{'ConnectCount'}++;
136 $ircstats{'OffTime'} += time() - $ircstats{'DisconnectTime'}
137 if (defined $ircstats{'DisconnectTime'});
140 if (!exists $users{_default}) {
141 &status("First time run... adding _default user.");
142 $users{_default}{FLAGS} = "mrt";
143 $users{_default}{HOSTS} = "*!*@*";
146 if (scalar keys %users < 2) {
147 &status("Ok... now /msg $ident PASS <pass> to get master access through DCC CHAT.");
149 # end of first time run.
151 if (&IsChanConf("wingate")) {
152 my $file = "$bot_base_dir/$param{'ircUser'}.wingate";
156 next unless (/^(\S+)\*$/);
157 push(@wingateBad, $_);
163 &ScheduleThis(1, \&setupSchedulers);
167 if (&IsParam("ircUMode")) {
168 &status("Attempting change of user modes to $param{'ircUMode'}.");
169 &rawout("MODE $ident $param{'ircUMode'}");
172 &status("End of motd. Now lets join some channels...");
173 if (!scalar @joinchan) {
174 &WARN("joinchan array is empty!!!");
175 @joinchan = &getJoinChans();
182 my ($self, $event) = @_;
183 my $type = uc( ($event->args)[1] );
184 my $nick = lc $event->nick();
186 # pity Net::IRC doesn't store nuh. Here's a hack :)
187 if (!exists $nuh{lc $nick}) {
189 $nuh{$nick} = "GETTING-NOW"; # trying.
193 if ($type eq 'SEND') { # GET for us.
194 # incoming DCC SEND. we're receiving a file.
195 my $get = ($event->args)[2];
196 open(DCCGET,">$get");
198 $self->new_get($nick,
205 } elsif ($type eq 'GET') { # SEND for us?
206 &status("DCC: Initializing SEND for $nick.");
207 $self->new_send($event->args);
208 } elsif ($type eq 'CHAT') {
209 &status("DCC: Initializing CHAT for $nick.");
210 $self->new_chat($event);
212 &WARN("${b_green}DCC $type$ob (1)");
217 my ($self, $event) = @_;
218 my $nick = $event->nick();
219 my $sock = ($event->to)[0];
221 # DCC CHAT close on fork exit workaround.
222 if ($bot_pid != $$) {
223 &WARN("run-away fork; exiting.");
227 if (exists $dcc{'SEND'}{$nick} and -f "$param{tempDir}/$nick.txt") {
228 &status("${b_green}DCC SEND$ob close from $b_cyan$nick$ob");
230 &status("dcc_close: purging $nick.txt from Debian.pl");
231 unlink "$param{tempDir}/$nick.txt";
233 delete $dcc{'SEND'}{$nick};
234 } elsif (exists $dcc{'CHAT'}{$nick} and $dcc{'CHAT'}{$nick} eq $sock) {
235 &status("${b_green}DCC CHAT$ob close from $b_cyan$nick$ob");
236 delete $dcc{'CHAT'}{$nick};
237 delete $dcc{'CHATvrfy'}{$nick};
239 &status("${b_green}DCC$ob UNKNOWN close from $b_cyan$nick$ob (2)");
244 my ($self, $event) = @_;
245 my $type = uc( ($event->args)[0] );
246 my $nick = lc $event->nick();
247 my $sock = ($event->to)[0];
251 ### BUG: who is set to bot's nick?
254 if ($type eq 'SEND') {
255 &status("${b_green}DCC lGET$ob established with $b_cyan$nick$ob");
257 } elsif ($type eq 'CHAT') {
259 ### TODO: run ScheduleThis inside on_dcc_open_chat recursively
260 ### 1,3,5,10 seconds then fail.
261 if ($nuh{$nick} eq "GETTING-NOW") {
262 &ScheduleThis(3/60, "on_dcc_open_chat", $nick, $sock);
264 on_dcc_open_chat(undef, $nick, $sock);
267 } elsif ($type eq 'SEND') {
268 &DEBUG("Starting DCC receive.");
269 foreach ($event->args) {
274 &WARN("${b_green}DCC $type$ob (3)");
279 # really custom sub to get NUH since Net::IRC doesn't appear to support
281 sub on_dcc_open_chat {
282 my(undef, $nick, $sock) = @_;
284 if ($nuh{$nick} eq "GETTING-NOW") {
285 &DEBUG("getting nuh for $nick failed. FIXME.");
289 &status("${b_green}DCC CHAT$ob established with $b_cyan$nick$ob $b_yellow($ob$nuh{$nick}$b_yellow)$ob");
291 &verifyUser($nick, $nuh{lc $nick});
293 if (!exists $users{$userHandle}{HOSTS}) {
294 &pSReply("you have no hosts defined in my user file; rejecting.");
295 ### TODO: $sock->close();
299 my $crypto = $users{$userHandle}{PASS};
300 $dcc{'CHAT'}{$nick} = $sock;
302 if (defined $crypto) {
303 &dccsay($nick,"Enter your password.");
305 &dccsay($nick,"Welcome to blootbot DCC CHAT interface, $userHandle.");
310 my ($self, $event) = @_;
311 my $from = $event->from();
312 my $what = ($event->args)[0];
314 &status("disconnect from $from ($what).");
315 $ircstats{'DisconnectTime'} = time();
316 $ircstats{'DisconnectReason'} = $what;
317 $ircstats{'DisconnectCount'}++;
318 $ircstats{'TotalTime'} += time() - $ircstats{'ConnectTime'};
320 # clear any variables on reconnection.
324 if (!$self->connect()) {
325 &WARN("not connected? help me. gonna call ircCheck() in 1800s");
326 &ScheduleThis(30, "ircCheck");
331 my ($self, $event) = @_;
332 my $chan = ($event->args)[1];
334 if (exists $cache{jointime}{$chan}) {
335 my $delta_time = sprintf("%.03f", &gettimeofday() - $cache{jointime}{$chan});
336 $delta_time = 0 if ($delta_time < 0);
338 &status("$b_blue$chan$ob: sync in ${delta_time}s.");
341 rawout("MODE $chan");
345 foreach ("o","v","") {
346 my $count = scalar(keys %{ $channels{$chan}{$_} });
347 next unless ($count);
349 $txt = "total" if ($_ eq "");
350 $txt = "voice" if ($_ eq "v");
351 $txt = "ops" if ($_ eq "o");
353 push(@array, "$count $txt");
355 my $chanstats = join(' || ', @array);
356 &status("$b_blue$chan$ob: [$chanstats]");
358 if (scalar @joinchan) { # remaining channels to join.
362 return unless (&IsChanConf("chanServ_ops") > 0);
363 return unless ($nickserv);
365 if (!exists $channels{$chan}{'o'}{$ident}) {
366 &status("ChanServ ==> Requesting ops for $chan.");
367 &rawout("PRIVMSG ChanServ :OP $chan $ident");
372 my ($self, $event) = @_;
373 my (@args) = ($event->args);
380 my ($self, $event) = @_;
381 my $chan = lc( ($event->args)[0] );
382 my $nick = $event->nick;
384 if ($nick =~ /^\Q$ident\E$/) {
385 &DEBUG("on_invite: self invite.");
390 if (exists $chanconf{$chan}) {
391 if (&validChan($chan)) {
392 &msg($who, "i'm already in \002$chan\002.");
396 &status("invited to $b_blue$_$ob by $b_cyan$who$ob");
397 &joinchan($self, $_);
402 my ($self, $event) = @_;
403 my ($user,$host) = split(/\@/, $event->userhost);
404 $chan = lc( ($event->to)[0] ); # CASING!!!!
405 $who = $event->nick();
407 $chanstats{$chan}{'Join'}++;
408 $userstats{lc $who}{'Join'} = time() if (&IsChanConf("seenStats"));
410 &joinfloodCheck($who, $chan, $event->userhost);
414 if (exists $netsplit{lc $who}) {
415 delete $netsplit{lc $who};
419 if ($netsplit and !$netsplittime) {
420 &DEBUG("on_join: ok.... re-running chanlimitCheck in 60.");
421 $conn->schedule(60, sub {
423 $netsplittime = undef;
426 $netsplittime = time();
429 # how to tell if there's a netjoin???
431 my $netsplitstr = "";
432 $netsplitstr = " $b_yellow\[${ob}NETSPLIT VICTIM$b_yellow]$ob" if ($netsplit);
433 &status(">>> join/$b_blue$chan$ob $b_cyan$who$ob $b_yellow($ob$user\@$host$b_yellow)$ob$netsplitstr");
435 $channels{$chan}{''}{$who}++;
436 $nuh = $who."!".$user."\@".$host;
437 $nuh{lc $who} = $nuh unless (exists $nuh{lc $who});
441 push(@bans, keys %{ $bans{$chan} }) if (exists $bans{$chan});
442 push(@bans, keys %{ $bans{"*"} }) if (exists $bans{"*"});
448 next unless ($nuh =~ /^$mask$/i);
450 ### TODO: check $channels{$chan}{'b'} if ban already exists.
451 foreach (keys %{ $channels{$chan}{'b'} }) {
452 &DEBUG(" bans_on_chan($chan) => $_");
455 my $reason = "no reason";
456 foreach ($chan, "*") {
457 next unless (exists $bans{$_});
458 next unless (exists $bans{$_}{$ban});
460 my @array = @{ $bans{$_}{$ban} };
462 $reason = $array[4] if ($array[4]);
467 &kick($who, $chan, $reason);
473 &rootWarn($who,$user,$host,$chan)
474 if (&IsChanConf("rootWarn") &&
475 $user =~ /^r(oo|ew|00)t$/i &&
476 $channels{$chan}{'o'}{$ident});
479 &chanLimitVerify($chan);
481 # used to determine sync time.
482 if ($who =~ /^$ident$/i) {
483 if (defined( my $whojoin = $cache{join}{$chan} )) {
484 &msg($chan, "Okay, I'm here. (courtesy of $whojoin)");
485 delete $cache{join}{$chan};
488 ### TODO: move this to &joinchan()?
489 $cache{jointime}{$chan} = &gettimeofday();
492 ### TODO: this may go wild on a netjoin :)
499 my ($self, $event) = @_;
500 my ($chan,$reason) = $event->args;
501 my $kicker = $event->nick;
502 my $kickee = ($event->to)[0];
503 my $uh = $event->userhost();
505 &status(">>> kick/$b_blue$chan$ob [$b$kickee!$uh$ob] by $b_cyan$kicker$ob $b_yellow($ob$reason$b_yellow)$ob");
507 $chan = lc $chan; # forgot about this, found by xsdg, 20001229.
508 $chanstats{$chan}{'Kick'}++;
510 if ($kickee eq $ident) {
511 &clearChanVars($chan);
513 &status("SELF attempting to rejoin lost channel $chan");
516 &DeleteUserInfo($kickee,$chan);
521 my ($self, $event) = @_;
522 my ($user, $host) = split(/\@/, $event->userhost);
523 my @args = $event->args();
524 my $nick = $event->nick();
525 my $chan = ($event->to)[0];
529 if ($nick eq $chan) { # UMODE
530 &status(">>> mode $b_yellow\[$ob$b@args$b_yellow\]$ob by $b_cyan$nick$ob");
532 &status(">>> mode/$b_blue$chan$ob $b_yellow\[$ob$b@args$b_yellow\]$ob by $b_cyan$nick$ob");
533 &hookMode($chan, @args);
538 my ($self, $event) = @_;
539 my $nick = $event->nick();
540 my ($myself,$chan,@args) = $event->args();
542 &hookMode(lc $chan, @args); # CASING.
546 my ($self, $event) = @_;
547 my $nick = $event->nick;
548 my $msg = ($event->args)[0];
550 ($user,$host) = split(/\@/, $event->userhost);
551 $uh = $event->userhost();
552 $nuh = $nick."!".$uh;
554 &hookMsg('private', undef, $nick, $msg);
558 my ($self, $event) = @_;
559 my @args = $event->args;
560 my $chan = lc $args[2]; # CASING, the last of them!
562 foreach (split / /, @args[3..$#args]) {
563 $channels{$chan}{'o'}{$_}++ if s/\@//;
564 $channels{$chan}{'v'}{$_}++ if s/\+//;
565 $channels{$chan}{''}{$_}++;
570 my ($self, $event) = @_;
571 my $nick = $event->nick();
572 my $newnick = ($event->args)[0];
574 if (exists $netsplit{lc $newnick}) {
575 &status("Netsplit: $newnick/$nick came back from netsplit and changed to original nick! removing from hash.");
576 delete $netsplit{lc $newnick};
580 foreach $chan (keys %channels) {
581 foreach $mode (keys %{$channels{$chan}}) {
582 next unless (exists $channels{$chan}{$mode}{$nick});
584 $channels{$chan}{$mode}{$newnick} = $channels{$chan}{$mode}{$nick};
587 &DeleteUserInfo($nick,keys %channels);
588 $nuh{lc $newnick} = $nuh{lc $nick};
589 delete $nuh{lc $nick};
591 # successful self-nick change.
592 if ($nick eq $ident) {
593 &status(">>> I materialized into $b_green$newnick$ob from $nick");
596 &status(">>> $b_cyan$nick$ob materializes into $b_green$newnick$ob");
602 my $nick = $self->nick;
603 my $newnick = substr($nick,0,7)."-";
605 &status("nick taken; changing to temporary nick.");
611 my ($self, $event) = @_;
612 my $nick = $event->nick();
613 my $chan = ($event->to)[0];
614 my $args = ($event->args)[0];
616 if ($nick =~ /^NickServ$/i) { # nickserv.
617 &status("NickServ: <== '$args'");
620 $check++ if ($args =~ /^This nickname is registered/i);
621 $check++ if ($args =~ /nickname.*owned/i);
624 &status("nickserv told us to register; doing it.");
625 if (&IsParam("nickServ_pass")) {
626 &status("NickServ: ==> Identifying.");
627 &rawout("PRIVMSG NickServ :IDENTIFY $param{'nickServ_pass'}");
630 &status("We can't tell nickserv a passwd ;(");
635 if ($args =~ /^Password a/i) {
638 } elsif ($nick =~ /^ChanServ$/i) { # chanserv.
639 &status("ChanServ: <== '$args'.");
641 if ($chan =~ /^$mask{chan}$/) { # channel notice.
642 &status("-$nick/$chan- $args");
644 $server = $nick unless (defined $server);
645 &status("-$nick- $args"); # private or server notice.
651 my ($self, $event) = @_;
652 my $chan = ($event->to)[0];
653 my $nick = $event->nick;
655 &status("!!! other called.");
656 &status("!!! $event->args");
660 my ($self, $event) = @_;
661 my $chan = lc( ($event->to)[0] ); # CASING!!!
662 my $nick = $event->nick;
663 my $userhost = $event->userhost;
665 if (exists $floodjoin{$chan}{$nick}{Time}) {
666 delete $floodjoin{$chan}{$nick};
669 $chanstats{$chan}{'Part'}++;
670 &DeleteUserInfo($nick,$chan);
671 &clearChanVars($chan) if ($nick eq $ident);
672 if (!&IsNickInAnyChan($nick) and &IsChanConf("seenStats")) {
673 delete $userstats{lc $nick};
676 &status(">>> part/$b_blue$chan$ob $b_cyan$nick$ob $b_yellow($ob$userhost$b_yellow)$ob");
680 my ($self, $event) = @_;
681 my $nick = $event->nick;
683 $self->ctcp_reply($nick, join(' ', ($event->args)));
684 &status(">>> ${b_green}CTCP PING$ob request from $b_cyan$nick$ob received.");
688 my ($self, $event) = @_;
689 my $nick = $event->nick;
690 my $lag = time() - ($event->args)[1];
692 &status(">>> ${b_green}CTCP PING$ob reply from $b_cyan$nick$ob: $lag sec.");
696 my ($self, $event) = @_;
697 my $msg = ($event->args)[0];
698 my $chan = lc( ($event->to)[0] ); # CASING.
699 my $nick = $event->nick;
700 $uh = $event->userhost();
701 $nuh = $nick."!".$uh;
702 ($user,$host) = split(/\@/, $uh);
704 if ($bot_pid != $$) {
705 &ERROR("run-away fork; exiting.");
710 if ($statcount < 200) {
711 foreach $chan (grep /[A-Z]/, keys %channels) {
712 &DEBUG("leak: chan => '$chan'.");
714 foreach $i (keys %{$channels{$chan}}) {
715 foreach (keys %{$channels{$chan}{$i}}) {
716 &DEBUG("leak: \$channels{$chan}{$i}{$_} ...");
724 $lastWho{$chan} = $nick;
725 ### TODO: use $nick or lc $nick?
726 if (&IsChanConf("seenStats")) {
727 $userstats{lc $nick}{'Count'}++;
728 $userstats{lc $nick}{'Time'} = time();
731 # if (&IsChanConf("hehCounter")) {
735 &hookMsg('public', $chan, $nick, $msg);
736 $chanstats{$chan}{'PublicMsg'}++;
740 my ($self, $event) = @_;
741 my $nick = $event->nick();
742 my $reason = ($event->args)[0];
745 foreach (keys %channels) {
746 # fixes inconsistent chanstats bug #1.
747 if (!&IsNickInChan($nick,$_)) {
751 $chanstats{$_}{'SignOff'}++;
754 if ($count == scalar keys %channels) {
755 &DEBUG("on_quit: nick $nick was not found in any chan.");
758 &DeleteUserInfo($nick, keys %channels);
760 if (exists $nuh{lc $nick}) {
761 delete $nuh{lc $nick};
763 &DEBUG("on_quit: nuh{lc $nick} does not exist! FIXME");
765 delete $userstats{lc $nick} if (&IsChanConf("seenStats"));
767 # should fix chanstats inconsistencies bug #2.
768 if ($reason=~/^($mask{host})\s($mask{host})$/) { # netsplit.
769 $reason = "NETSPLIT: $1 <=> $2";
771 if (&ChanConfList("chanlimitcheck") and !scalar keys %netsplit) {
772 &DEBUG("on_quit: netsplit detected; disabling chan limit.");
773 &rawout("MODE $chan -l");
776 $netsplit{lc $nick} = time();
777 if (!exists $netsplitservers{$1}{$2}) {
778 &status("netsplit detected between $1 and $2.");
779 $netsplitservers{$1}{$2} = time();
783 &status(">>> $b_cyan$nick$ob has signed off IRC $b_red($ob$reason$b_red)$ob");
784 if ($nick =~ /^\Q$ident\E$/) {
785 &DEBUG("^^^ THIS SHOULD NEVER HAPPEN.");
788 if ($nick !~ /^\Q$ident\E$/ and $nick =~ /^\Q$param{'ircNick'}\E$/i) {
789 &status("own nickname became free; changing.");
790 &nick($param{'ircNick'});
794 sub on_targettoofast {
795 my ($self, $event) = @_;
796 my $nick = $event->nick();
797 my($me,$chan,$why) = $event->args();
799 ### TODO: incomplete.
800 ### .* wait (\d+) second/) {
801 &status("on_ttf: X1 $msg") if (defined $msg);
803 &status("going to sleep for $sleep...");
810 my ($self, $event) = @_;
812 if (scalar($event->args) == 1) { # change.
813 my $topic = ($event->args)[0];
814 my $chan = ($event->to)[0];
815 my $nick = $event->nick();
819 # race condition here. To fix, change '1' to '0'.
820 # This will keep track of topics set by bot only.
823 # this may be fixed at a later date with topic queueing.
826 $topic{$chan}{'Current'} = $topic if (1);
827 $chanstats{$chan}{'Topic'}++;
829 &status(">>> topic/$b_blue$chan$ob by $b_cyan$nick$ob -> $topic");
831 my ($nick, $chan, $topic) = $event->args;
832 if (&IsChanConf("topic")) {
833 $topic{$chan}{'Current'} = $topic;
834 &topicAddHistory($chan,$topic);
837 $topic = &fixString($topic, 1);
838 &status(">>> topic/$b_blue$chan$ob is $topic");
843 my ($self, $event) = @_;
844 my ($myself,$chan,$setby,$time) = $event->args();
847 if (time() - $time > 60*60*24) {
848 $timestr = "at ". localtime $time;
850 $timestr = &Time2String(time() - $time) ." ago";
853 &status(">>> set by $b_cyan$setby$ob $timestr");
857 my ($self, $event) = @_;
858 my $nick = $event->nick();
861 if (scalar $event->args() != 1) { # old.
862 $ver = join ' ', $event->args();
863 $ver =~ s/^VERSION //;
865 $ver = ($event->args())[0];
868 if (grep /^\Q$nick\E$/i, @vernick) {
869 &WARN("nick $nick found in vernick; skipping.");
872 push(@vernick, $nick);
874 if ($ver =~ /bitchx/i) {
875 $ver{bitchx}{$nick} = $ver;
876 } elsif ($ver =~ /xc\!|xchat/i) {
877 $ver{xchat}{$nick} = $ver;
878 } elsif ($ver =~ /irssi/i) {
879 $ver{irssi}{$nick} = $ver;
880 } elsif ($ver =~ /epic/i) {
881 $ver{epic}{$nick} = $ver;
882 } elsif ($ver =~ /mirc/i) {
883 $ver{mirc}{$nick} = $ver;
884 } elsif ($ver =~ /ircle/i) {
885 $ver{ircle}{$nick} = $ver;
886 } elsif ($ver =~ /ircII/i) {
887 $ver{ircII}{$nick} = $ver;
888 } elsif ($ver =~ /sirc /i) {
889 $ver{sirc}{$nick} = $ver;
890 } elsif ($ver =~ /kvirc/i) {
891 $ver{kvirc}{$nick} = $ver;
892 } elsif ($ver =~ /eggdrop/i) {
893 $ver{eggdrop}{$nick} = $ver;
894 } elsif ($ver =~ /xircon/i) {
895 $ver{xircon}{$nick} = $ver;
897 $ver{other}{$nick} = $ver;
902 my ($self, $event) = @_;
903 my $nick = $event->nick;
905 &status(">>> ${b_green}CTCP VERSION$ob request from $b_cyan$nick$ob");
906 $self->ctcp_reply($nick, "VERSION $bot_version");
910 my ($self, $event) = @_;
911 my @args = $event->args;
913 $nuh{lc $args[5]} = $args[5]."!".$args[2]."\@".$args[3];
917 my ($self, $event) = @_;
918 my @args = $event->args;
920 &DEBUG("on_whoisuser: @args");
922 $nuh{lc $args[1]} = $args[1]."!".$args[2]."\@".$args[3];
925 #######################################################################
926 ####### IRC HOOK HELPERS IRC HOOK HELPERS IRC HOOK HELPERS ########
927 #######################################################################
930 # Usage: &hookMode($chan, $modes, @targets);
932 my ($chan, $modes, @targets) = @_;
935 $chan = lc $chan; # !!!.
938 foreach $mode (split(//, $modes)) {
940 if ($mode =~ /[-+]/) {
941 $parity = 1 if ($mode eq "+");
942 $parity = 0 if ($mode eq "-");
947 if ($mode =~ /[bklov]/) {
948 my $target = shift @targets;
951 $chanstats{$chan}{'Op'}++ if ($mode eq "o");
952 $chanstats{$chan}{'Ban'}++ if ($mode eq "b");
954 $chanstats{$chan}{'Deop'}++ if ($mode eq "o");
955 $chanstats{$chan}{'Unban'}++ if ($mode eq "b");
958 # modes w/ target affecting nick => cache it.
959 if ($mode =~ /[bov]/) {
960 $channels{$chan}{$mode}{$target}++ if $parity;
961 delete $channels{$chan}{$mode}{$target} if !$parity;
964 if ($mode =~ /[l]/) {
965 $channels{$chan}{$mode} = $target if $parity;
966 delete $channels{$chan}{$mode} if !$parity;
970 # important channel modes, targetless.
971 if ($mode =~ /[mt]/) {
972 $channels{$chan}{$mode}++ if $parity;
973 delete $channels{$chan}{$mode} if !$parity;
979 ($msgType, $chan, $who, $message) = @_;
983 $orig{message} = $message;
987 $message =~ s/[\cA-\c_]//ig; # strip control characters
988 $message =~ s/^\s+//; # initial whitespaces.
989 $who =~ tr/A-Z/a-z/; # lowercase.
994 if ($msgType =~ /private/) {
999 # addressing revamped by the xk.
1000 ### below needs to be fixed...
1001 if (&IsParam("addressCharacter")) {
1002 if ($message =~ s/^$param{'addressCharacter'}//) {
1008 if ($message =~ /^($mask{nick})([\;\:\>\, ]+) */) {
1009 my $newmessage = $';
1010 if ($1 =~ /^\Q$ident\E$/i) {
1011 $message = $newmessage;
1014 # ignore messages addressed to other people or unaddressed.
1015 $skipmessage++ if ($2 ne "" and $2 !~ /^ /);
1020 # Determine floodwho.
1022 if ($msgType =~ /public/i) { # public.
1023 $floodwho = $c = lc $chan;
1024 } elsif ($msgType =~ /private/i) { # private.
1025 $floodwho = lc $who;
1027 &DEBUG("FIXME: floodwho = ???");
1030 my $val = &getChanConfDefault("floodRepeat", "2:10", $c);
1031 my ($count, $interval) = split /:/, $val;
1033 # flood repeat protection.
1035 my $time = $flood{$floodwho}{$message} || 0;
1037 if ($msgType eq "public" and (time() - $time < $interval)) {
1038 ### public != personal who so the below is kind of pointless.
1040 foreach (keys %flood) {
1041 next if (/^\Q$floodwho\E$/);
1042 next if (defined $chan and /^\Q$chan\E$/);
1044 push(@who, grep /^\Q$message\E$/i, keys %{ $flood{$_} });
1047 return if ($lobotomized);
1050 &msg($who, "you already said what ".
1051 join(' ', @who)." have said.");
1053 &msg($who,"Someone already said that ". (time - $time) ." seconds ago" );
1056 ### TODO: delete old floodwarn{} keys.
1058 if (!exists $floodwarn{$floodwho}) {
1061 $floodwarn++ if (time() - $floodwarn{$floodwho} > $interval);
1065 &status("FLOOD repetition detected from $floodwho.");
1066 $floodwarn{$floodwho} = time();
1073 &status("$b_cyan$who$ob is short-addressing me");
1074 } elsif ($msgType eq "private") { # private.
1075 &status("$b_cyan$who$ob is /msg'ing me");
1077 &status("$b_cyan$who$ob is addressing me");
1080 $flood{$floodwho}{$message} = time();
1081 } elsif ($msgType eq "public" and &IsChanConf("kickOnRepeat")) {
1082 # unaddressed, public only.
1084 ### TODO: use a separate "short-time" hash.
1086 @data = keys %{ $flood{$floodwho} } if (exists $flood{$floodwho});
1089 $val = &getChanConfDefault("floodMessages", "5:30", $c);
1090 ($count, $interval) = split /:/, $val;
1092 # flood overflow protection.
1094 foreach (keys %{$flood{$floodwho}}) {
1095 next unless (time() - $flood{$floodwho}{$_} > $interval);
1096 delete $flood{$floodwho}{$_};
1099 my $i = scalar keys %{$flood{$floodwho}};
1101 &msg($who,"overflow of messages ($i > $count)");
1102 &status("FLOOD overflow detected from $floodwho; ignoring");
1104 my $expire = $param{'ignoreAutoExpire'} || 5;
1105 &ignoreAdd("*!$uh", $chan, $expire, "flood overflow auto-detected.");
1109 $flood{$floodwho}{$message} = time();
1113 if ($msgType =~ /public/i) { # public.
1114 $talkchannel = $chan;
1115 &status("<$orig{who}/$chan> $orig{message}");
1116 push(@ignore, keys %{ $ignore{$chan} }) if (exists $ignore{$chan});
1117 } elsif ($msgType =~ /private/i) { # private.
1118 &status("[$orig{who}] $orig{message}");
1119 $talkchannel = undef;
1122 &DEBUG("unknown msgType => $msgType.");
1124 push(@ignore, keys %{ $ignore{"*"} }) if (exists $ignore{"*"});
1126 if ((!$skipmessage or &IsChanConf("seenStoreAll")) and
1127 &IsChanConf("seen") and
1128 $msgType =~ /public/
1130 $seencache{$who}{'time'} = time();
1131 $seencache{$who}{'nick'} = $orig{who};
1132 $seencache{$who}{'host'} = $uh;
1133 $seencache{$who}{'chan'} = $talkchannel;
1134 $seencache{$who}{'msg'} = $orig{message};
1135 $seencache{$who}{'msgcount'}++;
1138 return if ($skipmessage);
1139 return unless (&IsParam("minVolunteerLength") or $addressed);
1144 next unless (eval { $nuh =~ /^$_$/i });
1146 &status("IGNORE <$who> $message");
1151 if (!defined $userHandle) {
1152 &DEBUG("line 1074: need verifyUser?");
1153 &verifyUser($who, $nuh);
1156 &DEBUG("hookMsg: 'nuh' not defined?");
1159 ### For extra debugging purposes...
1160 if ($_ = &process()) {
1161 # &DEBUG("IrcHooks: process returned '$_'.");
1167 sub chanLimitVerify {
1169 my $l = $channels{$chan}{'l'};
1171 # only change it if it's not set.
1172 if (defined $l and &IsChanConf("chanlimitcheck")) {
1173 my $plus = &getChanConfDefault("chanlimitcheckPlus", 5, $chan);
1174 my $nowl = scalar(keys %{ $channels{$chan}{''} });
1175 my $delta = $nowl - $l;
1179 &WARN("clc: stupid to have plus at $plus, fix it!");
1182 ### todo: check if we have ops.
1183 ### todo: if not, check if nickserv/chanserv is avail.
1184 ### todo: unify code with chanlimitcheck()
1186 &WARN("clc: nowl($nowl) > l($l) - 3");
1187 &rawout("MODE $chan +l ".($nowl+$plus) );