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 = $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 = $event->nick();
172 # pity Net::IRC doesn't store nuh. Here's a hack :)
173 if (!exists $nuh{lc $nick}) {
175 $nuh{lc $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 = $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{lc $who} = $who."!".$user."\@".$host unless (exists $nuh{lc $who});
423 ### on-join ban. (TODO: kick)
424 if (exists $bans{$chan}) {
425 ### TODO: need to do $chan and _default
426 foreach (keys %{ $bans{$chan} }) {
428 next unless /^\Q$nuh\E$/i;
430 foreach (keys %{ $channels{$chan}{'b'} }) {
431 &DEBUG(" bans_on_chan($chan) => $_");
434 ### TODO: check $channels{$chan}{'b'} if ban already exists.
435 &ban( "*!*@".&makeHostMask($host), $chan);
441 &rootWarn($who,$user,$host,$chan)
442 if (&IsChanConf("rootWarn") &&
443 $user =~ /^r(oo|ew|00)t$/i &&
444 $channels{$chan}{'o'}{$ident});
447 &chanLimitVerify($chan);
449 # used to determine sync time.
450 if ($who =~ /^$ident$/i) {
451 if (defined( my $whojoin = $cache{join}{$chan} )) {
452 &msg($chan, "Okay, I'm here. (courtesy of $whojoin)");
453 delete $cache{join}{$chan};
456 ### TODO: move this to &joinchan()?
457 $cache{jointime}{$chan} = &gettimeofday();
460 ### TODO: this may go wild on a netjoin :)
467 my ($self, $event) = @_;
468 my ($chan,$reason) = $event->args;
469 my $kicker = $event->nick;
470 my $kickee = ($event->to)[0];
471 my $uh = $event->userhost();
473 &status(">>> kick/$b_blue$chan$ob [$b$kickee!$uh$ob] by $b_cyan$kicker$ob $b_yellow($ob$reason$b_yellow)$ob");
475 $chan = lc $chan; # forgot about this, found by xsdg, 20001229.
476 $chanstats{$chan}{'Kick'}++;
478 if ($kickee eq $ident) {
479 &clearChanVars($chan);
481 &status("SELF attempting to rejoin lost channel $chan");
484 &DeleteUserInfo($kickee,$chan);
489 my ($self, $event) = @_;
490 my ($user, $host) = split(/\@/, $event->userhost);
491 my @args = $event->args();
492 my $nick = $event->nick();
493 my $chan = ($event->to)[0];
497 if ($nick eq $chan) { # UMODE
498 &status(">>> mode $b_yellow\[$ob$b@args$b_yellow\]$ob by $b_cyan$nick$ob");
500 &status(">>> mode/$b_blue$chan$ob $b_yellow\[$ob$b@args$b_yellow\]$ob by $b_cyan$nick$ob");
501 &hookMode($chan, @args);
506 my ($self, $event) = @_;
507 my $nick = $event->nick();
508 my ($myself,$chan,@args) = $event->args();
510 &hookMode(lc $chan, @args); # CASING.
514 my ($self, $event) = @_;
515 my $nick = $event->nick;
516 my $msg = ($event->args)[0];
518 ($user,$host) = split(/\@/, $event->userhost);
519 $uh = $event->userhost();
520 $nuh = $nick."!".$uh;
522 &hookMsg('private', undef, $nick, $msg);
526 my ($self, $event) = @_;
527 my @args = $event->args;
528 my $chan = lc $args[2]; # CASING, the last of them!
530 foreach (split / /, @args[3..$#args]) {
531 $channels{$chan}{'o'}{$_}++ if s/\@//;
532 $channels{$chan}{'v'}{$_}++ if s/\+//;
533 $channels{$chan}{''}{$_}++;
538 my ($self, $event) = @_;
539 my $nick = $event->nick();
540 my $newnick = ($event->args)[0];
542 if (exists $netsplit{lc $newnick}) {
543 &status("Netsplit: $newnick/$nick came back from netsplit and changed to original nick! removing from hash.");
544 delete $netsplit{lc $newnick};
548 foreach $chan (keys %channels) {
549 foreach $mode (keys %{$channels{$chan}}) {
550 next unless (exists $channels{$chan}{$mode}{$nick});
552 $channels{$chan}{$mode}{$newnick} = $channels{$chan}{$mode}{$nick};
555 &DeleteUserInfo($nick,keys %channels);
556 $nuh{lc $newnick} = $nuh{lc $nick};
557 delete $nuh{lc $nick};
559 # successful self-nick change.
560 if ($nick eq $ident) {
561 &status(">>> I materialized into $b_green$newnick$ob from $nick");
564 &status(">>> $b_cyan$nick$ob materializes into $b_green$newnick$ob");
570 my $nick = $self->nick;
571 my $newnick = substr($nick,0,7)."-";
573 &status("nick taken; changing to temporary nick.");
579 my ($self, $event) = @_;
580 my $nick = $event->nick();
581 my $chan = ($event->to)[0];
582 my $args = ($event->args)[0];
584 if ($nick =~ /^NickServ$/i) { # nickserv.
585 &status("NickServ: <== '$args'");
587 if ($args =~ /^This nickname is registered/i) {
588 &status("nickserv told us to register; doing it.");
589 if (&IsParam("nickServ_pass")) {
590 &status("NickServ: ==> Identifying.");
591 &rawout("PRIVMSG NickServ :IDENTIFY $param{'nickServ_pass'}");
594 &status("We can't tell nickserv a passwd ;(");
599 if ($args =~ /^Password a/i) {
602 } elsif ($nick =~ /^ChanServ$/i) { # chanserv.
603 &status("ChanServ: <== '$args'.");
605 if ($chan =~ /^$mask{chan}$/) { # channel notice.
606 &status("-$nick/$chan- $args");
608 $server = $nick unless (defined $server);
609 &status("-$nick- $args"); # private or server notice.
615 my ($self, $event) = @_;
616 my $chan = ($event->to)[0];
617 my $nick = $event->nick;
619 &status("!!! other called.");
620 &status("!!! $event->args");
624 my ($self, $event) = @_;
625 my $chan = lc( ($event->to)[0] ); # CASING!!!
626 my $nick = $event->nick;
627 my $userhost = $event->userhost;
629 if (exists $floodjoin{$chan}{$nick}{Time}) {
630 delete $floodjoin{$chan}{$nick};
633 $chanstats{$chan}{'Part'}++;
634 &DeleteUserInfo($nick,$chan);
635 &clearChanVars($chan) if ($nick eq $ident);
636 if (!&IsNickInAnyChan($nick) and &IsChanConf("seenStats")) {
637 delete $userstats{lc $nick};
640 &status(">>> part/$b_blue$chan$ob $b_cyan$nick$ob $b_yellow($ob$userhost$b_yellow)$ob");
644 my ($self, $event) = @_;
645 my $nick = $event->nick;
647 $self->ctcp_reply($nick, join(' ', ($event->args)));
648 &status(">>> ${b_green}CTCP PING$ob request from $b_cyan$nick$ob received.");
652 my ($self, $event) = @_;
653 my $nick = $event->nick;
654 my $lag = time() - ($event->args)[1];
656 &status(">>> ${b_green}CTCP PING$ob reply from $b_cyan$nick$ob: $lag sec.");
660 my ($self, $event) = @_;
661 my $msg = ($event->args)[0];
662 my $chan = lc( ($event->to)[0] ); # CASING.
663 my $nick = $event->nick;
664 $uh = $event->userhost();
665 $nuh = $nick."!".$uh;
666 ($user,$host) = split(/\@/, $uh);
668 if ($bot_pid != $$) {
669 &ERROR("run-away fork; exiting.");
674 if ($statcount < 200) {
675 foreach $chan (grep /[A-Z]/, keys %channels) {
676 &DEBUG("leak: chan => '$chan'.");
678 foreach $i (keys %{$channels{$chan}}) {
679 foreach (keys %{$channels{$chan}{$i}}) {
680 &DEBUG("leak: \$channels{$chan}{$i}{$_} ...");
688 $lastWho{$chan} = $nick;
689 ### TODO: use $nick or lc $nick?
690 if (&IsChanConf("seenStats")) {
691 $userstats{lc $nick}{'Count'}++;
692 $userstats{lc $nick}{'Time'} = time();
695 # if (&IsChanConf("hehCounter")) {
699 &hookMsg('public', $chan, $nick, $msg);
700 $chanstats{$chan}{'PublicMsg'}++;
704 my ($self, $event) = @_;
705 my $nick = $event->nick();
706 my $reason = ($event->args)[0];
709 foreach (keys %channels) {
710 # fixes inconsistent chanstats bug #1.
711 if (!&IsNickInChan($nick,$_)) {
715 $chanstats{$_}{'SignOff'}++;
718 if ($count == scalar keys %channels) {
719 &DEBUG("on_quit: nick $nick was not found in any chan.");
722 &DeleteUserInfo($nick, keys %channels);
724 if (exists $nuh{lc $nick}) {
725 delete $nuh{lc $nick};
727 &DEBUG("on_quit: nuh{lc $nick} does not exist! FIXME");
729 delete $userstats{lc $nick} if (&IsChanConf("seenStats"));
731 # should fix chanstats inconsistencies bug #2.
732 if ($reason=~/^($mask{host})\s($mask{host})$/) { # netsplit.
733 $reason = "NETSPLIT: $1 <=> $2";
735 if (&ChanConfList("chanlimitcheck") and !scalar keys %netsplit) {
736 &DEBUG("on_quit: netsplit detected; disabling chan limit.");
737 &rawout("MODE $chan -l");
740 $netsplit{lc $nick} = time();
741 if (!exists $netsplitservers{$1}{$2}) {
742 &status("netsplit detected between $1 and $2.");
743 $netsplitservers{$1}{$2} = time();
747 &status(">>> $b_cyan$nick$ob has signed off IRC $b_red($ob$reason$b_red)$ob");
748 if ($nick =~ /^\Q$ident\E$/) {
749 &DEBUG("^^^ THIS SHOULD NEVER HAPPEN.");
752 if ($nick !~ /^\Q$ident\E$/ and $nick =~ /^\Q$param{'ircNick'}\E$/i) {
753 &status("own nickname became free; changing.");
754 &nick($param{'ircNick'});
758 sub on_targettoofast {
759 my ($self, $event) = @_;
760 my $nick = $event->nick();
761 my($me,$chan,$why) = $event->args();
763 ### .* wait (\d+) second/) {
766 &status("going to sleep for $sleep...");
773 my ($self, $event) = @_;
775 if (scalar($event->args) == 1) { # change.
776 my $topic = ($event->args)[0];
777 my $chan = ($event->to)[0];
778 my $nick = $event->nick();
782 # race condition here. To fix, change '1' to '0'.
783 # This will keep track of topics set by bot only.
786 # this may be fixed at a later date with topic queueing.
789 $topic{$chan}{'Current'} = $topic if (1);
790 $chanstats{$chan}{'Topic'}++;
792 &status(">>> topic/$b_blue$chan$ob by $b_cyan$nick$ob -> $topic");
794 my ($nick, $chan, $topic) = $event->args;
795 if (&IsChanConf("topic")) {
796 $topic{$chan}{'Current'} = $topic;
797 &topicAddHistory($chan,$topic);
800 $topic = &fixString($topic, 1);
801 &status(">>> topic/$b_blue$chan$ob is $topic");
806 my ($self, $event) = @_;
807 my ($myself,$chan,$setby,$time) = $event->args();
810 if (time() - $time > 60*60*24) {
811 $timestr = "at ". localtime $time;
813 $timestr = &Time2String(time() - $time) ." ago";
816 &status(">>> set by $b_cyan$setby$ob $timestr");
820 my ($self, $event) = @_;
821 my $nick = $event->nick();
824 if (scalar $event->args() != 1) { # old.
825 $ver = join ' ', $event->args();
826 $ver =~ s/^VERSION //;
828 $ver = ($event->args())[0];
831 if (grep /^\Q$nick\E$/i, @vernick) {
832 &WARN("nick $nick found in vernick; skipping.");
835 push(@vernick, $nick);
837 if ($ver =~ /bitchx/i) {
838 $ver{bitchx}{$nick} = $ver;
839 } elsif ($ver =~ /xc\!|xchat/i) {
840 $ver{xchat}{$nick} = $ver;
841 } elsif ($ver =~ /irssi/i) {
842 $ver{irssi}{$nick} = $ver;
843 } elsif ($ver =~ /epic/i) {
844 $ver{epic}{$nick} = $ver;
845 } elsif ($ver =~ /mirc/i) {
846 $ver{mirc}{$nick} = $ver;
847 } elsif ($ver =~ /ircle/i) {
848 $ver{ircle}{$nick} = $ver;
849 } elsif ($ver =~ /ircII/i) {
850 $ver{ircII}{$nick} = $ver;
851 } elsif ($ver =~ /sirc /i) {
852 $ver{sirc}{$nick} = $ver;
853 } elsif ($ver =~ /kvirc/i) {
854 $ver{kvirc}{$nick} = $ver;
855 } elsif ($ver =~ /eggdrop/i) {
856 $ver{eggdrop}{$nick} = $ver;
857 } elsif ($ver =~ /xircon/i) {
858 $ver{xircon}{$nick} = $ver;
860 $ver{other}{$nick} = $ver;
865 my ($self, $event) = @_;
866 my $nick = $event->nick;
868 &status(">>> ${b_green}CTCP VERSION$ob request from $b_cyan$nick$ob");
869 $self->ctcp_reply($nick, "VERSION $bot_version");
873 my ($self, $event) = @_;
874 my @args = $event->args;
876 $nuh{lc $args[5]} = $args[5]."!".$args[2]."\@".$args[3];
880 my ($self, $event) = @_;
881 my @args = $event->args;
883 &DEBUG("on_whoisuser: @args");
885 $nuh{lc $args[1]} = $args[1]."!".$args[2]."\@".$args[3];
888 #######################################################################
889 ####### IRC HOOK HELPERS IRC HOOK HELPERS IRC HOOK HELPERS ########
890 #######################################################################
893 # Usage: &hookMode($chan, $modes, @targets);
895 my ($chan, $modes, @targets) = @_;
898 $chan = lc $chan; # !!!.
901 foreach $mode (split(//, $modes)) {
903 if ($mode =~ /[-+]/) {
904 $parity = 1 if ($mode eq "+");
905 $parity = 0 if ($mode eq "-");
910 if ($mode =~ /[bklov]/) {
911 my $target = shift @targets;
914 $chanstats{$chan}{'Op'}++ if ($mode eq "o");
915 $chanstats{$chan}{'Ban'}++ if ($mode eq "b");
917 $chanstats{$chan}{'Deop'}++ if ($mode eq "o");
918 $chanstats{$chan}{'Unban'}++ if ($mode eq "b");
921 # modes w/ target affecting nick => cache it.
922 if ($mode =~ /[bov]/) {
923 $channels{$chan}{$mode}{$target}++ if $parity;
924 delete $channels{$chan}{$mode}{$target} if !$parity;
927 if ($mode =~ /[l]/) {
928 $channels{$chan}{$mode} = $target if $parity;
929 delete $channels{$chan}{$mode} if !$parity;
933 # important channel modes, targetless.
934 if ($mode =~ /[mt]/) {
935 $channels{$chan}{$mode}++ if $parity;
936 delete $channels{$chan}{$mode} if !$parity;
942 ($msgType, $chan, $who, $message) = @_;
946 $orig{message} = $message;
950 $message =~ s/[\cA-\c_]//ig; # strip control characters
951 $message =~ s/^\s+//; # initial whitespaces.
952 $who =~ tr/A-Z/a-z/; # lowercase.
957 if ($msgType =~ /private/) {
962 # addressing revamped by the xk.
963 ### below needs to be fixed...
964 if (&IsParam("addressCharacter")) {
965 if ($message =~ s/^$param{'addressCharacter'}//) {
971 if ($message =~ /^($mask{nick})([\;\:\>\, ]+) */) {
973 if ($1 =~ /^\Q$ident\E$/i) {
974 $message = $newmessage;
977 # ignore messages addressed to other people or unaddressed.
978 $skipmessage++ if ($2 ne "" and $2 !~ /^ /);
983 # Determine floodwho.
985 if ($msgType =~ /public/i) { # public.
986 $floodwho = $c = lc $chan;
987 } elsif ($msgType =~ /private/i) { # private.
990 &DEBUG("FIXME: floodwho = ???");
993 my $val = &getChanConfDefault("floodRepeat", "2:10", $c);
994 my ($count, $interval) = split /:/, $val;
996 # flood repeat protection.
998 my $time = $flood{$floodwho}{$message};
1000 if (defined $time and (time - $time < $interval)) {
1001 ### public != personal who so the below is kind of pointless.
1003 foreach (keys %flood) {
1004 next if (/^\Q$floodwho\E$/);
1005 next if (defined $chan and /^\Q$chan\E$/);
1007 push(@who, grep /^\Q$message\E$/i, keys %{$flood{$_}});
1011 &msg($who, "you already said what ".
1012 join(' ', @who)." have said.");
1014 &msg($who,"Someone already said that ". (time - $time) ." seconds ago" );
1017 ### TODO: delete old floodwarn{} keys.
1019 if (!exists $floodwarn{$floodwho}) {
1022 $floodwarn++ if (time() - $floodwarn{$floodwho} > $interval);
1026 &status("FLOOD repetition detected from $floodwho.");
1027 $floodwarn{$floodwho} = time();
1034 &status("$b_cyan$who$ob is short-addressing me");
1035 } elsif ($msgType eq "private") { # private.
1036 &status("$b_cyan$who$ob is /msg'ing me");
1038 &status("$b_cyan$who$ob is addressing me");
1041 $flood{$floodwho}{$message} = time();
1044 $val = &getChanConfDefault("floodMessages", "5:30", $c);
1045 ($count, $interval) = split /:/, $val;
1047 # flood overflow protection.
1049 foreach (keys %{$flood{$floodwho}}) {
1050 next unless (time() - $flood{$floodwho}{$_} > $interval);
1051 delete $flood{$floodwho}{$_};
1054 my $i = scalar keys %{$flood{$floodwho}};
1056 &msg($who,"overflow of messages ($i > $count)");
1057 &status("FLOOD overflow detected from $floodwho; ignoring");
1059 my $expire = $param{'ignoreAutoExpire'} || 5;
1060 &ignoreAdd("*!$uh", $chan, $expire, "flood overflow auto-detected.");
1064 $flood{$floodwho}{$message} = time();
1068 if ($msgType =~ /public/i) { # public.
1069 $talkchannel = $chan;
1070 &status("<$orig{who}/$chan> $orig{message}");
1071 @ignore = keys %{ $ignore{$chan} };
1072 } elsif ($msgType =~ /private/i) { # private.
1073 &status("[$orig{who}] $orig{message}");
1074 $talkchannel = undef;
1077 &DEBUG("unknown msgType => $msgType.");
1079 push(@ignore, keys %{ $ignore{"*"} });
1081 if ((!$skipmessage or &IsChanConf("seenStoreAll")) and
1082 &IsChanConf("seen") and
1083 $msgType =~ /public/
1085 $seencache{$who}{'time'} = time();
1086 $seencache{$who}{'nick'} = $orig{who};
1087 $seencache{$who}{'host'} = $uh;
1088 $seencache{$who}{'chan'} = $talkchannel;
1089 $seencache{$who}{'msg'} = $orig{message};
1090 $seencache{$who}{'msgcount'}++;
1093 return if ($skipmessage);
1094 return unless (&IsParam("minVolunteerLength") or $addressed);
1101 next unless ($nuh =~ /^\Q$_\E$/i);
1107 if (!defined $userHandle) {
1108 &DEBUG("line 1074: need verifyUser?");
1109 &verifyUser($who, $nuh);
1112 &DEBUG("hookMsg: 'nuh' not defined?");
1115 ### For extra debugging purposes...
1116 if ($_ = &process()) {
1117 # &DEBUG("IrcHooks: process returned '$_'.");
1123 sub chanLimitVerify {
1125 my $l = $channels{$chan}{'l'};
1127 # only change it if it's not set.
1128 if (defined $l and &IsChanConf("chanlimitcheck")) {
1129 my $plus = &getChanConfDefault("chanlimitcheckPlus", 5, $chan);
1130 my $nowl = scalar(keys %{ $channels{$chan}{''} });
1131 my $delta = $nowl - $l;
1135 &WARN("clc: stupid to have plus at $plus, fix it!");
1138 ### todo: check if we have ops.
1139 ### todo: if not, check if nickserv/chanserv is avail.
1140 ### todo: unify code with chanlimitcheck()
1142 &WARN("clc: nowl($nowl) > l($l) - 3");
1143 &rawout("MODE $chan +l ".($nowl+$plus) );