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'}++;
137 if (&IsChanConf("wingate")) {
138 my $file = "$bot_base_dir/$param{'ircUser'}.wingate";
142 next unless (/^(\S+)\*$/);
143 push(@wingateBad, $_);
149 &ScheduleThis(1, \&setupSchedulers);
153 if (&IsParam("ircUMode")) {
154 &status("Attempting change of user modes to $param{'ircUMode'}.");
155 &rawout("MODE $ident $param{'ircUMode'}");
158 &status("End of motd. Now lets join some channels...");
159 if (!scalar @joinchan) {
160 &WARN("joinchan array is empty!!!");
161 @joinchan = &getJoinChans();
168 my ($self, $event) = @_;
169 my $type = uc( ($event->args)[1] );
170 my $nick = lc $event->nick();
172 # pity Net::IRC doesn't store nuh. Here's a hack :)
173 if (!exists $nuh{lc $nick}) {
175 $nuh{$nick} = "GETTING-NOW"; # trying.
179 if ($type eq 'SEND') { # GET for us.
180 # incoming DCC SEND. we're receiving a file.
181 my $get = ($event->args)[2];
182 open(DCCGET,">$get");
184 $self->new_get($nick,
191 } elsif ($type eq 'GET') { # SEND for us?
192 &status("DCC: Initializing SEND for $nick.");
193 $self->new_send($event->args);
194 } elsif ($type eq 'CHAT') {
195 &status("DCC: Initializing CHAT for $nick.");
196 $self->new_chat($event);
198 &WARN("${b_green}DCC $type$ob (1)");
203 my ($self, $event) = @_;
204 my $nick = $event->nick();
205 my $sock = ($event->to)[0];
207 # DCC CHAT close on fork exit workaround.
208 if ($bot_pid != $$) {
209 &WARN("run-away fork; exiting.");
213 if (exists $dcc{'SEND'}{$nick} and -f "$param{tempDir}/$nick.txt") {
214 &status("${b_green}DCC SEND$ob close from $b_cyan$nick$ob");
216 &status("dcc_close: purging $nick.txt from Debian.pl");
217 unlink "$param{tempDir}/$nick.txt";
219 delete $dcc{'SEND'}{$nick};
220 } elsif (exists $dcc{'CHAT'}{$nick} and $dcc{'CHAT'}{$nick} eq $sock) {
221 &status("${b_green}DCC CHAT$ob close from $b_cyan$nick$ob");
222 delete $dcc{'CHAT'}{$nick};
223 delete $dcc{'CHATvrfy'}{$nick};
225 &status("${b_green}DCC$ob UNKNOWN close from $b_cyan$nick$ob (2)");
230 my ($self, $event) = @_;
231 my $type = uc( ($event->args)[0] );
232 my $nick = lc $event->nick();
233 my $sock = ($event->to)[0];
237 ### BUG: who is set to bot's nick?
240 if ($type eq 'SEND') {
241 &status("${b_green}DCC lGET$ob established with $b_cyan$nick$ob");
243 } elsif ($type eq 'CHAT') {
245 ### TODO: run ScheduleThis inside on_dcc_open_chat recursively
246 ### 1,3,5,10 seconds then fail.
247 if ($nuh{$nick} eq "GETTING-NOW") {
248 &ScheduleThis(3/60, "on_dcc_open_chat", $nick, $sock);
250 on_dcc_open_chat(undef, $nick, $sock);
253 } elsif ($type eq 'SEND') {
254 &DEBUG("Starting DCC receive.");
255 foreach ($event->args) {
260 &WARN("${b_green}DCC $type$ob (3)");
265 # really custom sub to get NUH since Net::IRC doesn't appear to support
267 sub on_dcc_open_chat {
268 my(undef, $nick, $sock) = @_;
270 if ($nuh{$nick} eq "GETTING-NOW") {
271 &DEBUG("getting nuh for $nick failed. FIXME.");
275 &status("${b_green}DCC CHAT$ob established with $b_cyan$nick$ob $b_yellow($ob$nuh{$nick}$b_yellow)$ob");
277 &verifyUser($nick, $nuh{lc $nick});
279 if (!exists $users{$userHandle}{HOSTS}) {
280 &pSReply("you have no hosts defined in my user file; rejecting.");
281 ### TODO: $sock->close();
285 my $crypto = $users{$userHandle}{PASS};
286 $dcc{'CHAT'}{$nick} = $sock;
288 if (defined $crypto) {
289 &dccsay($nick,"Enter your password.");
291 &dccsay($nick,"Welcome to blootbot DCC CHAT interface, $userHandle.");
296 my ($self, $event) = @_;
297 my $from = $event->from();
298 my $what = ($event->args)[0];
300 &status("disconnect from $from ($what).");
301 $ircstats{'DisconnectTime'} = time();
302 $ircstats{'DisconnectReason'} = $what;
303 $ircstats{'DisconnectCount'}++;
305 # clear any variables on reconnection.
309 if (!$self->connect()) {
310 &WARN("not connected? help me. gonna call ircCheck() in 1800s");
311 &ScheduleThis(30, "ircCheck");
316 my ($self, $event) = @_;
317 my $chan = ($event->args)[1];
319 if (exists $cache{jointime}{$chan}) {
320 my $delta_time = sprintf("%.03f", &gettimeofday() - $cache{jointime}{$chan});
321 $delta_time = 0 if ($delta_time < 0);
323 &status("$b_blue$chan$ob: sync in ${delta_time}s.");
326 rawout("MODE $chan");
330 foreach ("o","v","") {
331 my $count = scalar(keys %{ $channels{$chan}{$_} });
332 next unless ($count);
334 $txt = "total" if ($_ eq "");
335 $txt = "voice" if ($_ eq "v");
336 $txt = "ops" if ($_ eq "o");
338 push(@array, "$count $txt");
340 my $chanstats = join(' || ', @array);
341 &status("$b_blue$chan$ob: [$chanstats]");
343 if (scalar @joinchan) { # remaining channels to join.
347 return unless (&IsChanConf("chanServ_ops") > 0);
348 return unless ($nickserv);
350 if (!exists $channels{$chan}{'o'}{$ident}) {
351 &status("ChanServ ==> Requesting ops for $chan.");
352 &rawout("PRIVMSG ChanServ :OP $chan $ident");
357 my ($self, $event) = @_;
358 my (@args) = ($event->args);
365 my ($self, $event) = @_;
366 my $chan = lc( ($event->args)[0] );
367 my $nick = $event->nick;
369 if ($nick =~ /^\Q$ident\E$/) {
370 &DEBUG("on_invite: self invite.");
375 if (exists $chanconf{$chan}) {
376 if (&validChan($chan)) {
377 &msg($who, "i'm already in \002$chan\002.");
381 &status("invited to $b_blue$_$ob by $b_cyan$who$ob");
382 &joinchan($self, $_);
387 my ($self, $event) = @_;
388 my ($user,$host) = split(/\@/, $event->userhost);
389 $chan = lc( ($event->to)[0] ); # CASING!!!!
390 $who = $event->nick();
392 $chanstats{$chan}{'Join'}++;
393 $userstats{lc $who}{'Join'} = time() if (&IsChanConf("seenStats"));
395 &joinfloodCheck($who, $chan, $event->userhost);
399 if (exists $netsplit{lc $who}) {
400 delete $netsplit{lc $who};
404 if ($netsplit and !$netsplittime) {
405 &DEBUG("on_join: ok.... re-running chanlimitCheck in 60.");
406 $conn->schedule(60, sub {
408 $netsplittime = undef;
411 $netsplittime = time();
414 # how to tell if there's a netjoin???
416 my $netsplitstr = "";
417 $netsplitstr = " $b_yellow\[${ob}NETSPLIT VICTIM$b_yellow]$ob" if ($netsplit);
418 &status(">>> join/$b_blue$chan$ob $b_cyan$who$ob $b_yellow($ob$user\@$host$b_yellow)$ob$netsplitstr");
420 $channels{$chan}{''}{$who}++;
421 $nuh = $who."!".$user."\@".$host;
422 $nuh{lc $who} = $nuh unless (exists $nuh{lc $who});
426 push(@bans, keys %{ $bans{$chan} }) if (exists $bans{$chan});
427 push(@bans, keys %{ $bans{"*"} }) if (exists $bans{"*"});
433 next unless ($nuh =~ /^$mask$/i);
435 ### TODO: check $channels{$chan}{'b'} if ban already exists.
436 foreach (keys %{ $channels{$chan}{'b'} }) {
437 &DEBUG(" bans_on_chan($chan) => $_");
440 my $reason = "no reason";
441 foreach ($chan, "*") {
442 next unless (exists $bans{$_});
443 next unless (exists $bans{$_}{$mask});
445 my @array = @{ $bans{$_}{$mask} };
447 &DEBUG("on_join: ban: array => '$_'");
449 $reason ||= $array[4];
452 &DEBUG("on_join: ban: reason => '$reason'.");
455 &kick($who, $chan, $reason);
461 &rootWarn($who,$user,$host,$chan)
462 if (&IsChanConf("rootWarn") &&
463 $user =~ /^r(oo|ew|00)t$/i &&
464 $channels{$chan}{'o'}{$ident});
467 &chanLimitVerify($chan);
469 # used to determine sync time.
470 if ($who =~ /^$ident$/i) {
471 if (defined( my $whojoin = $cache{join}{$chan} )) {
472 &msg($chan, "Okay, I'm here. (courtesy of $whojoin)");
473 delete $cache{join}{$chan};
476 ### TODO: move this to &joinchan()?
477 $cache{jointime}{$chan} = &gettimeofday();
480 ### TODO: this may go wild on a netjoin :)
487 my ($self, $event) = @_;
488 my ($chan,$reason) = $event->args;
489 my $kicker = $event->nick;
490 my $kickee = ($event->to)[0];
491 my $uh = $event->userhost();
493 &status(">>> kick/$b_blue$chan$ob [$b$kickee!$uh$ob] by $b_cyan$kicker$ob $b_yellow($ob$reason$b_yellow)$ob");
495 $chan = lc $chan; # forgot about this, found by xsdg, 20001229.
496 $chanstats{$chan}{'Kick'}++;
498 if ($kickee eq $ident) {
499 &clearChanVars($chan);
501 &status("SELF attempting to rejoin lost channel $chan");
504 &DeleteUserInfo($kickee,$chan);
509 my ($self, $event) = @_;
510 my ($user, $host) = split(/\@/, $event->userhost);
511 my @args = $event->args();
512 my $nick = $event->nick();
513 my $chan = ($event->to)[0];
517 if ($nick eq $chan) { # UMODE
518 &status(">>> mode $b_yellow\[$ob$b@args$b_yellow\]$ob by $b_cyan$nick$ob");
520 &status(">>> mode/$b_blue$chan$ob $b_yellow\[$ob$b@args$b_yellow\]$ob by $b_cyan$nick$ob");
521 &hookMode($chan, @args);
526 my ($self, $event) = @_;
527 my $nick = $event->nick();
528 my ($myself,$chan,@args) = $event->args();
530 &hookMode(lc $chan, @args); # CASING.
534 my ($self, $event) = @_;
535 my $nick = $event->nick;
536 my $msg = ($event->args)[0];
538 ($user,$host) = split(/\@/, $event->userhost);
539 $uh = $event->userhost();
540 $nuh = $nick."!".$uh;
542 &hookMsg('private', undef, $nick, $msg);
546 my ($self, $event) = @_;
547 my @args = $event->args;
548 my $chan = lc $args[2]; # CASING, the last of them!
550 foreach (split / /, @args[3..$#args]) {
551 $channels{$chan}{'o'}{$_}++ if s/\@//;
552 $channels{$chan}{'v'}{$_}++ if s/\+//;
553 $channels{$chan}{''}{$_}++;
558 my ($self, $event) = @_;
559 my $nick = $event->nick();
560 my $newnick = ($event->args)[0];
562 if (exists $netsplit{lc $newnick}) {
563 &status("Netsplit: $newnick/$nick came back from netsplit and changed to original nick! removing from hash.");
564 delete $netsplit{lc $newnick};
568 foreach $chan (keys %channels) {
569 foreach $mode (keys %{$channels{$chan}}) {
570 next unless (exists $channels{$chan}{$mode}{$nick});
572 $channels{$chan}{$mode}{$newnick} = $channels{$chan}{$mode}{$nick};
575 &DeleteUserInfo($nick,keys %channels);
576 $nuh{lc $newnick} = $nuh{lc $nick};
577 delete $nuh{lc $nick};
579 # successful self-nick change.
580 if ($nick eq $ident) {
581 &status(">>> I materialized into $b_green$newnick$ob from $nick");
584 &status(">>> $b_cyan$nick$ob materializes into $b_green$newnick$ob");
590 my $nick = $self->nick;
591 my $newnick = substr($nick,0,7)."-";
593 &status("nick taken; changing to temporary nick.");
599 my ($self, $event) = @_;
600 my $nick = $event->nick();
601 my $chan = ($event->to)[0];
602 my $args = ($event->args)[0];
604 if ($nick =~ /^NickServ$/i) { # nickserv.
605 &status("NickServ: <== '$args'");
607 if ($args =~ /^This nickname is registered/i) {
608 &status("nickserv told us to register; doing it.");
609 if (&IsParam("nickServ_pass")) {
610 &status("NickServ: ==> Identifying.");
611 &rawout("PRIVMSG NickServ :IDENTIFY $param{'nickServ_pass'}");
614 &status("We can't tell nickserv a passwd ;(");
619 if ($args =~ /^Password a/i) {
622 } elsif ($nick =~ /^ChanServ$/i) { # chanserv.
623 &status("ChanServ: <== '$args'.");
625 if ($chan =~ /^$mask{chan}$/) { # channel notice.
626 &status("-$nick/$chan- $args");
628 $server = $nick unless (defined $server);
629 &status("-$nick- $args"); # private or server notice.
635 my ($self, $event) = @_;
636 my $chan = ($event->to)[0];
637 my $nick = $event->nick;
639 &status("!!! other called.");
640 &status("!!! $event->args");
644 my ($self, $event) = @_;
645 my $chan = lc( ($event->to)[0] ); # CASING!!!
646 my $nick = $event->nick;
647 my $userhost = $event->userhost;
649 if (exists $floodjoin{$chan}{$nick}{Time}) {
650 delete $floodjoin{$chan}{$nick};
653 $chanstats{$chan}{'Part'}++;
654 &DeleteUserInfo($nick,$chan);
655 &clearChanVars($chan) if ($nick eq $ident);
656 if (!&IsNickInAnyChan($nick) and &IsChanConf("seenStats")) {
657 delete $userstats{lc $nick};
660 &status(">>> part/$b_blue$chan$ob $b_cyan$nick$ob $b_yellow($ob$userhost$b_yellow)$ob");
664 my ($self, $event) = @_;
665 my $nick = $event->nick;
667 $self->ctcp_reply($nick, join(' ', ($event->args)));
668 &status(">>> ${b_green}CTCP PING$ob request from $b_cyan$nick$ob received.");
672 my ($self, $event) = @_;
673 my $nick = $event->nick;
674 my $lag = time() - ($event->args)[1];
676 &status(">>> ${b_green}CTCP PING$ob reply from $b_cyan$nick$ob: $lag sec.");
680 my ($self, $event) = @_;
681 my $msg = ($event->args)[0];
682 my $chan = lc( ($event->to)[0] ); # CASING.
683 my $nick = $event->nick;
684 $uh = $event->userhost();
685 $nuh = $nick."!".$uh;
686 ($user,$host) = split(/\@/, $uh);
688 if ($bot_pid != $$) {
689 &ERROR("run-away fork; exiting.");
694 if ($statcount < 200) {
695 foreach $chan (grep /[A-Z]/, keys %channels) {
696 &DEBUG("leak: chan => '$chan'.");
698 foreach $i (keys %{$channels{$chan}}) {
699 foreach (keys %{$channels{$chan}{$i}}) {
700 &DEBUG("leak: \$channels{$chan}{$i}{$_} ...");
708 $lastWho{$chan} = $nick;
709 ### TODO: use $nick or lc $nick?
710 if (&IsChanConf("seenStats")) {
711 $userstats{lc $nick}{'Count'}++;
712 $userstats{lc $nick}{'Time'} = time();
715 # if (&IsChanConf("hehCounter")) {
719 &hookMsg('public', $chan, $nick, $msg);
720 $chanstats{$chan}{'PublicMsg'}++;
724 my ($self, $event) = @_;
725 my $nick = $event->nick();
726 my $reason = ($event->args)[0];
729 foreach (keys %channels) {
730 # fixes inconsistent chanstats bug #1.
731 if (!&IsNickInChan($nick,$_)) {
735 $chanstats{$_}{'SignOff'}++;
738 if ($count == scalar keys %channels) {
739 &DEBUG("on_quit: nick $nick was not found in any chan.");
742 &DeleteUserInfo($nick, keys %channels);
744 if (exists $nuh{lc $nick}) {
745 delete $nuh{lc $nick};
747 &DEBUG("on_quit: nuh{lc $nick} does not exist! FIXME");
749 delete $userstats{lc $nick} if (&IsChanConf("seenStats"));
751 # should fix chanstats inconsistencies bug #2.
752 if ($reason=~/^($mask{host})\s($mask{host})$/) { # netsplit.
753 $reason = "NETSPLIT: $1 <=> $2";
755 if (&ChanConfList("chanlimitcheck") and !scalar keys %netsplit) {
756 &DEBUG("on_quit: netsplit detected; disabling chan limit.");
757 &rawout("MODE $chan -l");
760 $netsplit{lc $nick} = time();
761 if (!exists $netsplitservers{$1}{$2}) {
762 &status("netsplit detected between $1 and $2.");
763 $netsplitservers{$1}{$2} = time();
767 &status(">>> $b_cyan$nick$ob has signed off IRC $b_red($ob$reason$b_red)$ob");
768 if ($nick =~ /^\Q$ident\E$/) {
769 &DEBUG("^^^ THIS SHOULD NEVER HAPPEN.");
772 if ($nick !~ /^\Q$ident\E$/ and $nick =~ /^\Q$param{'ircNick'}\E$/i) {
773 &status("own nickname became free; changing.");
774 &nick($param{'ircNick'});
778 sub on_targettoofast {
779 my ($self, $event) = @_;
780 my $nick = $event->nick();
781 my($me,$chan,$why) = $event->args();
783 ### TODO: incomplete.
784 ### .* wait (\d+) second/) {
785 &status("on_ttf: X1 $msg") if (defined $msg);
787 &status("going to sleep for $sleep...");
794 my ($self, $event) = @_;
796 if (scalar($event->args) == 1) { # change.
797 my $topic = ($event->args)[0];
798 my $chan = ($event->to)[0];
799 my $nick = $event->nick();
803 # race condition here. To fix, change '1' to '0'.
804 # This will keep track of topics set by bot only.
807 # this may be fixed at a later date with topic queueing.
810 $topic{$chan}{'Current'} = $topic if (1);
811 $chanstats{$chan}{'Topic'}++;
813 &status(">>> topic/$b_blue$chan$ob by $b_cyan$nick$ob -> $topic");
815 my ($nick, $chan, $topic) = $event->args;
816 if (&IsChanConf("topic")) {
817 $topic{$chan}{'Current'} = $topic;
818 &topicAddHistory($chan,$topic);
821 $topic = &fixString($topic, 1);
822 &status(">>> topic/$b_blue$chan$ob is $topic");
827 my ($self, $event) = @_;
828 my ($myself,$chan,$setby,$time) = $event->args();
831 if (time() - $time > 60*60*24) {
832 $timestr = "at ". localtime $time;
834 $timestr = &Time2String(time() - $time) ." ago";
837 &status(">>> set by $b_cyan$setby$ob $timestr");
841 my ($self, $event) = @_;
842 my $nick = $event->nick();
845 if (scalar $event->args() != 1) { # old.
846 $ver = join ' ', $event->args();
847 $ver =~ s/^VERSION //;
849 $ver = ($event->args())[0];
852 if (grep /^\Q$nick\E$/i, @vernick) {
853 &WARN("nick $nick found in vernick; skipping.");
856 push(@vernick, $nick);
858 if ($ver =~ /bitchx/i) {
859 $ver{bitchx}{$nick} = $ver;
860 } elsif ($ver =~ /xc\!|xchat/i) {
861 $ver{xchat}{$nick} = $ver;
862 } elsif ($ver =~ /irssi/i) {
863 $ver{irssi}{$nick} = $ver;
864 } elsif ($ver =~ /epic/i) {
865 $ver{epic}{$nick} = $ver;
866 } elsif ($ver =~ /mirc/i) {
867 $ver{mirc}{$nick} = $ver;
868 } elsif ($ver =~ /ircle/i) {
869 $ver{ircle}{$nick} = $ver;
870 } elsif ($ver =~ /ircII/i) {
871 $ver{ircII}{$nick} = $ver;
872 } elsif ($ver =~ /sirc /i) {
873 $ver{sirc}{$nick} = $ver;
874 } elsif ($ver =~ /kvirc/i) {
875 $ver{kvirc}{$nick} = $ver;
876 } elsif ($ver =~ /eggdrop/i) {
877 $ver{eggdrop}{$nick} = $ver;
878 } elsif ($ver =~ /xircon/i) {
879 $ver{xircon}{$nick} = $ver;
881 $ver{other}{$nick} = $ver;
886 my ($self, $event) = @_;
887 my $nick = $event->nick;
889 &status(">>> ${b_green}CTCP VERSION$ob request from $b_cyan$nick$ob");
890 $self->ctcp_reply($nick, "VERSION $bot_version");
894 my ($self, $event) = @_;
895 my @args = $event->args;
897 $nuh{lc $args[5]} = $args[5]."!".$args[2]."\@".$args[3];
901 my ($self, $event) = @_;
902 my @args = $event->args;
904 &DEBUG("on_whoisuser: @args");
906 $nuh{lc $args[1]} = $args[1]."!".$args[2]."\@".$args[3];
909 #######################################################################
910 ####### IRC HOOK HELPERS IRC HOOK HELPERS IRC HOOK HELPERS ########
911 #######################################################################
914 # Usage: &hookMode($chan, $modes, @targets);
916 my ($chan, $modes, @targets) = @_;
919 $chan = lc $chan; # !!!.
922 foreach $mode (split(//, $modes)) {
924 if ($mode =~ /[-+]/) {
925 $parity = 1 if ($mode eq "+");
926 $parity = 0 if ($mode eq "-");
931 if ($mode =~ /[bklov]/) {
932 my $target = shift @targets;
935 $chanstats{$chan}{'Op'}++ if ($mode eq "o");
936 $chanstats{$chan}{'Ban'}++ if ($mode eq "b");
938 $chanstats{$chan}{'Deop'}++ if ($mode eq "o");
939 $chanstats{$chan}{'Unban'}++ if ($mode eq "b");
942 # modes w/ target affecting nick => cache it.
943 if ($mode =~ /[bov]/) {
944 $channels{$chan}{$mode}{$target}++ if $parity;
945 delete $channels{$chan}{$mode}{$target} if !$parity;
948 if ($mode =~ /[l]/) {
949 $channels{$chan}{$mode} = $target if $parity;
950 delete $channels{$chan}{$mode} if !$parity;
954 # important channel modes, targetless.
955 if ($mode =~ /[mt]/) {
956 $channels{$chan}{$mode}++ if $parity;
957 delete $channels{$chan}{$mode} if !$parity;
963 ($msgType, $chan, $who, $message) = @_;
967 $orig{message} = $message;
971 $message =~ s/[\cA-\c_]//ig; # strip control characters
972 $message =~ s/^\s+//; # initial whitespaces.
973 $who =~ tr/A-Z/a-z/; # lowercase.
978 if ($msgType =~ /private/) {
983 # addressing revamped by the xk.
984 ### below needs to be fixed...
985 if (&IsParam("addressCharacter")) {
986 if ($message =~ s/^$param{'addressCharacter'}//) {
992 if ($message =~ /^($mask{nick})([\;\:\>\, ]+) */) {
994 if ($1 =~ /^\Q$ident\E$/i) {
995 $message = $newmessage;
998 # ignore messages addressed to other people or unaddressed.
999 $skipmessage++ if ($2 ne "" and $2 !~ /^ /);
1004 # Determine floodwho.
1006 if ($msgType =~ /public/i) { # public.
1007 $floodwho = $c = lc $chan;
1008 } elsif ($msgType =~ /private/i) { # private.
1009 $floodwho = lc $who;
1011 &DEBUG("FIXME: floodwho = ???");
1014 my $val = &getChanConfDefault("floodRepeat", "2:10", $c);
1015 my ($count, $interval) = split /:/, $val;
1017 # flood repeat protection.
1019 my $time = $flood{$floodwho}{$message} || 0;
1021 if ($msgType eq "public" and (time() - $time < $interval)) {
1022 ### public != personal who so the below is kind of pointless.
1024 foreach (keys %flood) {
1025 next if (/^\Q$floodwho\E$/);
1026 next if (defined $chan and /^\Q$chan\E$/);
1028 push(@who, grep /^\Q$message\E$/i, keys %{ $flood{$_} });
1032 &msg($who, "you already said what ".
1033 join(' ', @who)." have said.");
1035 &msg($who,"Someone already said that ". (time - $time) ." seconds ago" );
1038 ### TODO: delete old floodwarn{} keys.
1040 if (!exists $floodwarn{$floodwho}) {
1043 $floodwarn++ if (time() - $floodwarn{$floodwho} > $interval);
1047 &status("FLOOD repetition detected from $floodwho.");
1048 $floodwarn{$floodwho} = time();
1055 &status("$b_cyan$who$ob is short-addressing me");
1056 } elsif ($msgType eq "private") { # private.
1057 &status("$b_cyan$who$ob is /msg'ing me");
1059 &status("$b_cyan$who$ob is addressing me");
1062 $flood{$floodwho}{$message} = time();
1063 } elsif ($msgType eq "public" and &IsChanConf("kickOnRepeat")) {
1064 # unaddressed, public only.
1066 ### TODO: use a separate "short-time" hash.
1068 @data = keys %{ $flood{$floodwho} } if (exists $flood{$floodwho});
1071 $val = &getChanConfDefault("floodMessages", "5:30", $c);
1072 ($count, $interval) = split /:/, $val;
1074 # flood overflow protection.
1076 foreach (keys %{$flood{$floodwho}}) {
1077 next unless (time() - $flood{$floodwho}{$_} > $interval);
1078 delete $flood{$floodwho}{$_};
1081 my $i = scalar keys %{$flood{$floodwho}};
1083 &msg($who,"overflow of messages ($i > $count)");
1084 &status("FLOOD overflow detected from $floodwho; ignoring");
1086 my $expire = $param{'ignoreAutoExpire'} || 5;
1087 &ignoreAdd("*!$uh", $chan, $expire, "flood overflow auto-detected.");
1091 $flood{$floodwho}{$message} = time();
1095 if ($msgType =~ /public/i) { # public.
1096 $talkchannel = $chan;
1097 &status("<$orig{who}/$chan> $orig{message}");
1098 push(@ignore, keys %{ $ignore{$chan} }) if (exists $ignore{$chan});
1099 } elsif ($msgType =~ /private/i) { # private.
1100 &status("[$orig{who}] $orig{message}");
1101 $talkchannel = undef;
1104 &DEBUG("unknown msgType => $msgType.");
1106 push(@ignore, keys %{ $ignore{"*"} }) if (exists $ignore{"*"});
1108 if ((!$skipmessage or &IsChanConf("seenStoreAll")) and
1109 &IsChanConf("seen") and
1110 $msgType =~ /public/
1112 $seencache{$who}{'time'} = time();
1113 $seencache{$who}{'nick'} = $orig{who};
1114 $seencache{$who}{'host'} = $uh;
1115 $seencache{$who}{'chan'} = $talkchannel;
1116 $seencache{$who}{'msg'} = $orig{message};
1117 $seencache{$who}{'msgcount'}++;
1120 return if ($skipmessage);
1121 return unless (&IsParam("minVolunteerLength") or $addressed);
1126 next unless (eval { $nuh =~ /^$_$/i });
1128 &status("IGNORE <$who> $message");
1133 if (!defined $userHandle) {
1134 &DEBUG("line 1074: need verifyUser?");
1135 &verifyUser($who, $nuh);
1138 &DEBUG("hookMsg: 'nuh' not defined?");
1141 ### For extra debugging purposes...
1142 if ($_ = &process()) {
1143 # &DEBUG("IrcHooks: process returned '$_'.");
1149 sub chanLimitVerify {
1151 my $l = $channels{$chan}{'l'};
1153 # only change it if it's not set.
1154 if (defined $l and &IsChanConf("chanlimitcheck")) {
1155 my $plus = &getChanConfDefault("chanlimitcheckPlus", 5, $chan);
1156 my $nowl = scalar(keys %{ $channels{$chan}{''} });
1157 my $delta = $nowl - $l;
1161 &WARN("clc: stupid to have plus at $plus, fix it!");
1164 ### todo: check if we have ops.
1165 ### todo: if not, check if nickserv/chanserv is avail.
1166 ### todo: unify code with chanlimitcheck()
1168 &WARN("clc: nowl($nowl) > l($l) - 3");
1169 &rawout("MODE $chan +l ".($nowl+$plus) );