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 $userHandle = ""; # reset.
46 # who is set to bot's name, why?
48 if (!exists $nuh{$who}) {
49 &DEBUG("chat: nuh{$who} (nick => $nick) doesn't exist; trying WHOIS .");
57 $orig{message} = $msg;
59 $uh = (split /\!/, $nuh)[1];
64 if (!exists $dcc{'CHATvrfy'}{$nick}) {
65 $userHandle = &verifyUser($who, $nuh);
66 my $crypto = $users{$userHandle}{PASS};
69 ### TODO: prevent users without CRYPT chatting.
70 if (!defined $crypto) {
71 &DEBUG("chat: no pass required.");
74 } elsif (&ckpasswd($msg, $crypto)) {
75 # stolen from eggdrop.
76 $self->privmsg($sock, "Connected to $ident");
77 $self->privmsg($sock, "Commands start with '.' (like '.quit' or '.help')");
78 $self->privmsg($sock, "Everything else goes out to the party line.");
80 &dccStatus(2) unless (exists $sched{"dccStatus"}{RUNNING});
85 &status("DCC CHAT: incorrect pass; closing connection.");
86 &DEBUG("chat: sock => '$sock'.");
88 delete $dcc{'CHAT'}{$nick};
89 &DEBUG("chat: after closing sock. FIXME");
90 ### BUG: close seizes bot. why?
94 &status("DCC CHAT: user $nick is here!");
95 &DCCBroadcast("*** $nick ($uh) joined the party line.");
97 $dcc{'CHATvrfy'}{$nick} = $userHandle;
99 return if ($userHandle eq "_default");
101 &dccsay($nick,"Flags: $users{$userHandle}{FLAGS}");
107 &status("$b_red=$b_cyan$who$b_red=$ob $message");
109 if ($message =~ s/^\.//) { # dcc chat commands.
110 ### TODO: make use of &Forker(); here?
111 &loadMyModule( $myModules{'ircdcc'} );
113 &DCCBroadcast("#$who# $message","m");
115 my $retval = &userDCC();
116 return unless (defined $retval);
117 return if ($retval eq $noreply);
119 $conn->privmsg($dcc{'CHAT'}{$who}, "Invalid command.");
121 } else { # dcc chat arena.
123 foreach (keys %{$dcc{'CHAT'}}) {
124 $conn->privmsg($dcc{'CHAT'}{$_}, "<$who> $orig{message}");
128 return 'DCC CHAT MESSAGE';
134 # what's the following for?
135 $ident = $param{'ircNick'};
137 $ircstats{'ConnectTime'} = time();
138 $ircstats{'ConnectCount'}++;
140 if (&IsChanConf("wingate")) {
141 my $file = "$bot_base_dir/$param{'ircUser'}.wingate";
145 next unless (/^(\S+)\*$/);
146 push(@wingateBad, $_);
152 &ScheduleThis(1, \&setupSchedulers);
156 if (&IsParam("ircUMode")) {
157 &status("Attempting change of user modes to $param{'ircUMode'}.");
158 &rawout("MODE $ident $param{'ircUMode'}");
161 &status("End of motd. Now lets join some channels...");
162 if (!scalar @joinchan) {
163 &WARN("joinchan array is empty!!!");
164 @joinchan = &getJoinChans();
171 my ($self, $event) = @_;
172 my $type = uc( ($event->args)[1] );
173 my $nick = $event->nick();
175 # pity Net::IRC doesn't store nuh. Here's a hack :)
177 $nuh{lc $nick} = "GETTING-NOW"; # trying.
179 &DEBUG("on_dcc: nuh => GETTING-NOW.");
181 if ($type eq 'SEND') { # GET for us.
182 # incoming DCC SEND. we're receiving a file.
183 my $get = ($event->args)[2];
184 open(DCCGET,">$get");
186 $self->new_get($nick,
193 } elsif ($type eq 'GET') { # SEND for us?
194 &status("DCC: Initializing SEND for $nick.");
195 $self->new_send($event->args);
196 } elsif ($type eq 'CHAT') {
197 &status("DCC: Initializing CHAT for $nick.");
198 $self->new_chat($event);
200 &WARN("${b_green}DCC $type$ob (1)");
205 my ($self, $event) = @_;
206 my $nick = $event->nick();
207 my $sock = ($event->to)[0];
209 # DCC CHAT close on fork exit workaround.
210 if ($bot_pid != $$) {
211 &WARN("run-away fork; exiting.");
215 if (exists $dcc{'SEND'}{$nick} and -f "$param{tempDir}/$nick.txt") {
216 &status("${b_green}DCC SEND$ob close from $b_cyan$nick$ob");
218 &status("dcc_close: purging $nick.txt from Debian.pl");
219 unlink "$param{tempDir}/$nick.txt";
221 delete $dcc{'SEND'}{$nick};
222 } elsif (exists $dcc{'CHAT'}{$nick} and $dcc{'CHAT'}{$nick} eq $sock) {
223 &status("${b_green}DCC CHAT$ob close from $b_cyan$nick$ob");
224 delete $dcc{'CHAT'}{$nick};
225 delete $dcc{'CHATvrfy'}{$nick};
227 &status("${b_green}DCC$ob UNKNOWN close from $b_cyan$nick$ob (2)");
232 my ($self, $event) = @_;
233 my $type = uc( ($event->args)[0] );
234 my $nick = $event->nick();
235 my $sock = ($event->to)[0];
239 ### BUG: who is set to bot's nick?
242 if ($type eq 'SEND') {
243 &status("${b_green}DCC lGET$ob established with $b_cyan$nick$ob");
245 } elsif ($type eq 'CHAT') {
247 ### TODO: run ScheduleThis inside on_dcc_open_chat recursively
248 ### 1,3,5,10 seconds then fail.
249 if ($nuh{$nick} eq "GETTING-NOW") {
250 &ScheduleThis(3/60, "on_dcc_open_chat", $nick, $sock);
252 on_dcc_open_chat(undef, $nick, $sock);
255 } elsif ($type eq 'SEND') {
256 &DEBUG("Starting DCC receive.");
257 foreach ($event->args) {
262 &WARN("${b_green}DCC $type$ob (3)");
267 # really custom sub to get NUH since Net::IRC doesn't appear to support
269 sub on_dcc_open_chat {
270 my(undef, $nick,$sock) = @_;
272 &DEBUG("nuh{$nick} => $nuh{$nick}.");
273 if ($nuh{$nick} =~ /^(\S+)(\d+)$/) {
277 &DEBUG("getting nuh for $nick failed. FIXME.");
281 &status("${b_green}DCC CHAT$ob established with $b_cyan$nick$ob $b_yellow($ob$nuh{$nick}$b_yellow)$ob");
283 &verifyUser($nick, $nuh{lc $nick});
285 if (!exists $users{$userHandle}{HOSTS}) {
286 &pSReply("you have no hosts defined in my user file; rejecting.");
287 ### TODO: $sock->close();
291 my $crypto = $users{$userHandle}{PASS};
292 $dcc{'CHAT'}{$nick} = $sock;
294 if (defined $crypto) {
295 &dccsay($nick,"Enter your password.");
297 &dccsay($nick,"Welcome to blootbot DCC CHAT interface, $userHandle.");
302 my ($self, $event) = @_;
303 my $from = $event->from();
304 my $what = ($event->args)[0];
306 &status("disconnect from $from ($what).");
307 $ircstats{'DisconnectTime'} = time();
308 $ircstats{'DisconnectReason'} = $what;
309 $ircstats{'DisconnectCount'}++;
311 # clear any variables on reconnection.
315 if (!$self->connect()) {
316 &WARN("not connected? help me. gonna call ircCheck() in 1800s");
317 &ScheduleThis(30, "ircCheck");
322 my ($self, $event) = @_;
323 my $chan = ($event->args)[1];
325 if (exists $jointime{$chan}) {
326 my $delta_time = sprintf("%.03f", &gettimeofday() - $jointime{$chan});
327 $delta_time = 0 if ($delta_time < 0);
329 &status("$b_blue$chan$ob: sync in ${delta_time}s.");
332 rawout("MODE $chan");
336 foreach ("o","v","") {
337 my $count = scalar(keys %{$channels{$chan}{$_}});
338 next unless ($count);
340 $txt = "total" if ($_ eq "");
341 $txt = "voice" if ($_ eq "v");
342 $txt = "ops" if ($_ eq "o");
344 push(@array, "$count $txt");
346 my $chanstats = join(' || ', @array);
347 &status("$b_blue$chan$ob: [$chanstats]");
349 if (scalar @joinchan) { # remaining channels to join.
353 return unless (&IsChanConf("chanServ_ops") > 0);
354 return unless ($nickserv);
356 if (!exists $channels{$chan}{'o'}{$ident}) {
357 &status("ChanServ ==> Requesting ops for $chan.");
358 &rawout("PRIVMSG ChanServ :OP $chan $ident");
363 my ($self, $event) = @_;
364 my (@args) = ($event->args);
371 my ($self, $event) = @_;
372 my $chan = lc( ($event->args)[0] );
373 my $nick = $event->nick;
375 if ($nick =~ /^\Q$ident\E$/) {
376 &DEBUG("on_invite: self invite.");
381 if (exists $chanconf{$chan}) {
382 if (&validChan($chan)) {
383 &msg($who, "i'm already in \002$chan\002.");
387 &status("invited to $b_blue$_$ob by $b_cyan$who$ob");
388 &joinchan($self, $_);
393 my ($self, $event) = @_;
394 my ($user,$host) = split(/\@/, $event->userhost);
395 $chan = lc( ($event->to)[0] ); # CASING!!!!
396 $who = $event->nick();
398 $chanstats{$chan}{'Join'}++;
399 $userstats{lc $who}{'Join'} = time() if (&IsChanConf("seenStats"));
401 &joinfloodCheck($who, $chan, $event->userhost);
405 if (exists $netsplit{lc $who}) {
406 delete $netsplit{lc $who};
410 if ($netsplit and !$netsplittime) {
411 &status("ok.... re-running chanlimitCheck in 60.");
412 $conn->schedule(60, sub {
414 $netsplittime = undef;
417 $netsplittime = time();
420 # how to tell if there's a netjoin???
422 my $netsplitstr = "";
423 $netsplitstr = " $b_yellow\[${ob}NETSPLIT VICTIM$b_yellow]$ob" if ($netsplit);
424 &status(">>> join/$b_blue$chan$ob $b_cyan$who$ob $b_yellow($ob$user\@$host$b_yellow)$ob$netsplitstr");
426 $channels{$chan}{''}{$who}++;
427 $nuh{lc $who} = $who."!".$user."\@".$host unless (exists $nuh{lc $who});
429 ### on-join ban. (TODO: kick)
430 if (exists $bans{$chan}) {
431 ### TODO: need to do $chan and _default
432 foreach (keys %{ $bans{$chan} }) {
434 next unless /^\Q$nuh\E$/i;
436 foreach (keys %{ $channels{$chan}{'b'} }) {
437 &DEBUG(" bans_on_chan($chan) => $_");
440 ### TODO: check $channels{$chan}{'b'} if ban already exists.
441 &ban( "*!*@".&makeHostMask($host), $chan);
447 &rootWarn($who,$user,$host,$chan)
448 if (&IsChanConf("rootWarn") &&
449 $user =~ /^r(oo|ew|00)t$/i &&
450 $channels{$chan}{'o'}{$ident});
452 # used to determine sync time.
453 if ($who =~ /^$ident$/i) {
454 if (defined( my $whojoin = $joinverb{$chan} )) {
455 &msg($chan, "Okay, I'm here. (courtesy of $whojoin)");
456 delete $joinverb{$chan};
459 ### TODO: move this to &joinchan()?
460 $jointime{$chan} = &gettimeofday();
463 ### TODO: this may go wild on a netjoin :)
470 my ($self, $event) = @_;
471 my ($chan,$reason) = $event->args;
472 my $kicker = $event->nick;
473 my $kickee = ($event->to)[0];
474 my $uh = $event->userhost();
476 &status(">>> kick/$b_blue$chan$ob [$b$kickee!$uh$ob] by $b_cyan$kicker$ob $b_yellow($ob$reason$b_yellow)$ob");
478 $chan = lc $chan; # forgot about this, found by xsdg, 20001229.
479 $chanstats{$chan}{'Kick'}++;
481 if ($kickee eq $ident) {
482 &clearChanVars($chan);
484 &status("SELF attempting to rejoin lost channel $chan");
487 &DeleteUserInfo($kickee,$chan);
492 my ($self, $event) = @_;
493 my ($user, $host) = split(/\@/, $event->userhost);
494 my @args = $event->args();
495 my $nick = $event->nick();
496 my $chan = ($event->to)[0];
500 if ($nick eq $chan) { # UMODE
501 &status(">>> mode $b_yellow\[$ob$b@args$b_yellow\]$ob by $b_cyan$nick$ob");
503 &status(">>> mode/$b_blue$chan$ob $b_yellow\[$ob$b@args$b_yellow\]$ob by $b_cyan$nick$ob");
504 &hookMode($chan, @args);
509 my ($self, $event) = @_;
510 my $nick = $event->nick();
511 my ($myself,$chan,@args) = $event->args();
513 &hookMode(lc $chan, @args); # CASING.
517 my ($self, $event) = @_;
518 my $nick = $event->nick;
519 my $msg = ($event->args)[0];
521 ($user,$host) = split(/\@/, $event->userhost);
522 $uh = $event->userhost();
523 $nuh = $nick."!".$uh;
525 &hookMsg('private', undef, $nick, $msg);
529 my ($self, $event) = @_;
530 my @args = $event->args;
531 my $chan = lc $args[2]; # CASING, the last of them!
533 foreach (split / /, @args[3..$#args]) {
534 $channels{$chan}{'o'}{$_}++ if s/\@//;
535 $channels{$chan}{'v'}{$_}++ if s/\+//;
536 $channels{$chan}{''}{$_}++;
541 my ($self, $event) = @_;
542 my $nick = $event->nick();
543 my $newnick = ($event->args)[0];
545 if (exists $netsplit{lc $newnick}) {
546 &status("Netsplit: $newnick/$nick came back from netsplit and changed to original nick! removing from hash.");
547 delete $netsplit{lc $newnick};
551 foreach $chan (keys %channels) {
552 foreach $mode (keys %{$channels{$chan}}) {
553 next unless (exists $channels{$chan}{$mode}{$nick});
555 $channels{$chan}{$mode}{$newnick} = $channels{$chan}{$mode}{$nick};
558 &DeleteUserInfo($nick,keys %channels);
559 $nuh{lc $newnick} = $nuh{lc $nick};
560 delete $nuh{lc $nick};
562 # successful self-nick change.
563 if ($nick eq $ident) {
564 &status(">>> I materialized into $b_green$newnick$ob from $nick");
567 &status(">>> $b_cyan$nick$ob materializes into $b_green$newnick$ob");
573 my $nick = $self->nick;
574 my $newnick = substr($nick,0,7)."-";
576 &status("nick taken; changing to temporary nick.");
582 my ($self, $event) = @_;
583 my $nick = $event->nick();
584 my $chan = ($event->to)[0];
585 my $args = ($event->args)[0];
587 if ($nick =~ /^NickServ$/i) { # nickserv.
588 &status("NickServ: <== '$args'");
590 if ($args =~ /^This nickname is registered/i) {
591 &status("nickserv told us to register; doing it.");
592 if (&IsParam("nickServ_pass")) {
593 &status("NickServ: ==> Identifying.");
594 &rawout("PRIVMSG NickServ :IDENTIFY $param{'nickServ_pass'}");
597 &status("We can't tell nickserv a passwd ;(");
602 if ($args =~ /^Password a/i) {
605 } elsif ($nick =~ /^ChanServ$/i) { # chanserv.
606 &status("ChanServ: <== '$args'.");
608 if ($chan =~ /^$mask{chan}$/) { # channel notice.
609 &status("-$nick/$chan- $args");
611 $server = $nick unless (defined $server);
612 &status("-$nick- $args"); # private or server notice.
618 my ($self, $event) = @_;
619 my $chan = ($event->to)[0];
620 my $nick = $event->nick;
622 &status("!!! other called.");
623 &status("!!! $event->args");
627 my ($self, $event) = @_;
628 my $chan = lc( ($event->to)[0] ); # CASING!!!
629 my $nick = $event->nick;
630 my $userhost = $event->userhost;
632 if (exists $floodjoin{$chan}{$nick}{Time}) {
633 delete $floodjoin{$chan}{$nick};
636 $chanstats{$chan}{'Part'}++;
637 &DeleteUserInfo($nick,$chan);
638 &clearChanVars($chan) if ($nick eq $ident);
639 if (!&IsNickInAnyChan($nick) and &IsChanConf("seenStats")) {
640 delete $userstats{lc $nick};
643 &status(">>> part/$b_blue$chan$ob $b_cyan$nick$ob $b_yellow($ob$userhost$b_yellow)$ob");
647 my ($self, $event) = @_;
648 my $nick = $event->nick;
650 $self->ctcp_reply($nick, join(' ', ($event->args)));
651 &status(">>> ${b_green}CTCP PING$ob request from $b_cyan$nick$ob received.");
655 my ($self, $event) = @_;
656 my $nick = $event->nick;
657 my $lag = time() - ($event->args)[1];
659 &status(">>> ${b_green}CTCP PING$ob reply from $b_cyan$nick$ob: $lag sec.");
663 my ($self, $event) = @_;
664 my $msg = ($event->args)[0];
665 my $chan = lc( ($event->to)[0] ); # CASING.
666 my $nick = $event->nick;
667 $uh = $event->userhost();
668 $nuh = $nick."!".$uh;
669 ($user,$host) = split(/\@/, $uh);
671 if ($bot_pid != $$) {
672 &ERROR("run-away fork; exiting.");
677 if ($statcount < 200) {
678 foreach $chan (grep /[A-Z]/, keys %channels) {
679 &DEBUG("leak: chan => '$chan'.");
681 foreach $i (keys %{$channels{$chan}}) {
682 foreach (keys %{$channels{$chan}{$i}}) {
683 &DEBUG("leak: \$channels{$chan}{$i}{$_} ...");
691 $lastWho{$chan} = $nick;
692 ### TODO: use $nick or lc $nick?
693 if (&IsChanConf("seenStats")) {
694 $userstats{lc $nick}{'Count'}++;
695 $userstats{lc $nick}{'Time'} = time();
698 # if (&IsChanConf("hehCounter")) {
702 &hookMsg('public', $chan, $nick, $msg);
703 $chanstats{$chan}{'PublicMsg'}++;
707 my ($self, $event) = @_;
708 my $nick = $event->nick();
709 my $reason = ($event->args)[0];
711 foreach (keys %channels) {
712 # fixes inconsistent chanstats bug #1.
713 next unless (&IsNickInChan($nick,$_));
714 $chanstats{$_}{'SignOff'}++;
716 &DeleteUserInfo($nick, keys %channels);
717 if (exists $nuh{lc $nick}) {
718 delete $nuh{lc $nick};
720 &DEBUG("on_quit: nuh{lc $nick} does not exist! FIXME");
722 delete $userstats{lc $nick} if (&IsChanConf("seenStats"));
724 # should fix chanstats inconsistencies bug #2.
725 if ($reason=~/^($mask{host})\s($mask{host})$/) { # netsplit.
726 $reason = "NETSPLIT: $1 <=> $2";
728 $netsplit{lc $nick} = time();
729 if (!exists $netsplitservers{$1}{$2}) {
730 &status("netsplit detected between $1 and $2.");
731 $netsplitservers{$1}{$2} = time();
735 &status(">>> $b_cyan$nick$ob has signed off IRC $b_red($ob$reason$b_red)$ob");
736 if ($nick =~ /^\Q$ident\E$/) {
737 &DEBUG("^^^ THIS SHOULD NEVER HAPPEN.");
740 if ($nick !~ /^\Q$ident\E$/ and $nick =~ /^\Q$param{'ircNick'}\E$/i) {
741 &status("own nickname became free; changing.");
742 &nick($param{'ircNick'});
746 sub on_targettoofast {
747 my ($self, $event) = @_;
748 my $nick = $event->nick();
749 my($me,$chan,$why) = $event->args();
751 ### .* wait (\d+) second/) {
754 &status("going to sleep for $sleep...");
761 my ($self, $event) = @_;
763 if (scalar($event->args) == 1) { # change.
764 my $topic = ($event->args)[0];
765 my $chan = ($event->to)[0];
766 my $nick = $event->nick();
770 # race condition here. To fix, change '1' to '0'.
771 # This will keep track of topics set by bot only.
774 # this may be fixed at a later date with topic queueing.
777 $topic{$chan}{'Current'} = $topic if (1);
778 $chanstats{$chan}{'Topic'}++;
780 &status(">>> topic/$b_blue$chan$ob by $b_cyan$nick$ob -> $topic");
782 my ($nick, $chan, $topic) = $event->args;
783 if (&IsChanConf("topic")) {
784 $topic{$chan}{'Current'} = $topic;
785 &topicAddHistory($chan,$topic);
788 $topic = &fixString($topic, 1);
789 &status(">>> topic/$b_blue$chan$ob is $topic");
794 my ($self, $event) = @_;
795 my ($myself,$chan,$setby,$time) = $event->args();
798 if (time() - $time > 60*60*24) {
799 $timestr = "at ". localtime $time;
801 $timestr = &Time2String(time() - $time) ." ago";
804 &status(">>> set by $b_cyan$setby$ob $timestr");
808 my ($self, $event) = @_;
809 my $nick = $event->nick();
812 if (scalar $event->args() != 1) { # old.
813 $ver = join ' ', $event->args();
814 $ver =~ s/^VERSION //;
816 $ver = ($event->args())[0];
819 if (grep /^\Q$nick\E$/i, @vernick) {
820 &WARN("nick $nick found in vernick; skipping.");
823 push(@vernick, $nick);
825 if ($ver =~ /bitchx/i) {
826 $ver{bitchx}{$nick} = $ver;
827 } elsif ($ver =~ /xc\!|xchat/i) {
828 $ver{xchat}{$nick} = $ver;
829 } elsif ($ver =~ /irssi/i) {
830 $ver{irssi}{$nick} = $ver;
831 } elsif ($ver =~ /epic/i) {
832 $ver{epic}{$nick} = $ver;
833 } elsif ($ver =~ /mirc/i) {
834 $ver{mirc}{$nick} = $ver;
835 } elsif ($ver =~ /ircle/i) {
836 $ver{ircle}{$nick} = $ver;
837 } elsif ($ver =~ /ircII/i) {
838 $ver{ircII}{$nick} = $ver;
839 } elsif ($ver =~ /sirc /i) {
840 $ver{sirc}{$nick} = $ver;
841 } elsif ($ver =~ /kvirc/i) {
842 $ver{kvirc}{$nick} = $ver;
843 } elsif ($ver =~ /eggdrop/i) {
844 $ver{eggdrop}{$nick} = $ver;
845 } elsif ($ver =~ /xircon/i) {
846 $ver{xircon}{$nick} = $ver;
848 $ver{other}{$nick} = $ver;
853 my ($self, $event) = @_;
854 my $nick = $event->nick;
856 &status(">>> ${b_green}CTCP VERSION$ob request from $b_cyan$nick$ob");
857 $self->ctcp_reply($nick, "VERSION $bot_version");
861 my ($self, $event) = @_;
862 my @args = $event->args;
864 $nuh{lc $args[5]} = $args[5]."!".$args[2]."\@".$args[3];
868 my ($self, $event) = @_;
869 my @args = $event->args;
871 &DEBUG("on_whoisuser: @args");
873 $nuh{lc $args[1]} = $args[1]."!".$args[2]."\@".$args[3];
876 #######################################################################
877 ####### IRC HOOK HELPERS IRC HOOK HELPERS IRC HOOK HELPERS ########
878 #######################################################################
881 # Usage: &hookMode($chan, $modes, @targets);
883 my ($chan, $modes, @targets) = @_;
886 $chan = lc $chan; # !!!.
889 foreach $mode (split(//, $modes)) {
891 if ($mode =~ /[-+]/) {
892 $parity = 1 if ($mode eq "+");
893 $parity = 0 if ($mode eq "-");
898 if ($mode =~ /[bklov]/) {
899 my $target = shift @targets;
902 $chanstats{$chan}{'Op'}++ if ($mode eq "o");
903 $chanstats{$chan}{'Ban'}++ if ($mode eq "b");
905 $chanstats{$chan}{'Deop'}++ if ($mode eq "o");
906 $chanstats{$chan}{'Unban'}++ if ($mode eq "b");
909 # modes w/ target affecting nick => cache it.
910 if ($mode =~ /[bov]/) {
911 $channels{$chan}{$mode}{$target}++ if $parity;
912 delete $channels{$chan}{$mode}{$target} if !$parity;
915 if ($mode =~ /[l]/) {
916 $channels{$chan}{$mode} = $target if $parity;
917 delete $channels{$chan}{$mode} if !$parity;
921 # important channel modes, targetless.
922 if ($mode =~ /[mt]/) {
923 $channels{$chan}{$mode}++ if $parity;
924 delete $channels{$chan}{$mode} if !$parity;
930 ($msgType, $chan, $who, $message) = @_;
934 $orig{message} = $message;
938 $message =~ s/[\cA-\c_]//ig; # strip control characters
939 $message =~ s/^\s+//; # initial whitespaces.
940 $who =~ tr/A-Z/a-z/; # lowercase.
945 if ($msgType =~ /private/) {
950 # addressing revamped by the xk.
951 ### below needs to be fixed...
952 if (&IsParam("addressCharacter")) {
953 if ($message =~ s/^$param{'addressCharacter'}//) {
959 if ($message =~ /^($mask{nick})([\;\:\>\, ]+) */) {
961 if ($1 =~ /^\Q$ident\E$/i) {
962 $message = $newmessage;
965 # ignore messages addressed to other people or unaddressed.
966 $skipmessage++ if ($2 ne "" and $2 !~ /^ /);
971 # Determine floodwho.
973 if ($msgType =~ /public/i) { # public.
974 $floodwho = $c = lc $chan;
975 } elsif ($msgType =~ /private/i) { # private.
978 &DEBUG("FIXME: floodwho = ???");
981 my $val = &getChanConfDefault("floodRepeat", "2:10", $c);
982 my ($count, $interval) = split /:/, $val;
984 # flood repeat protection.
986 my $time = $flood{$floodwho}{$message};
988 if (defined $time and (time - $time < $interval)) {
989 ### public != personal who so the below is kind of pointless.
991 foreach (keys %flood) {
992 next if (/^\Q$floodwho\E$/);
993 next if (defined $chan and /^\Q$chan\E$/);
995 push(@who, grep /^\Q$message\E$/i, keys %{$flood{$_}});
999 &msg($who, "you already said what ".
1000 join(' ', @who)." have said.");
1002 &msg($who,"Someone already said that ". (time - $time) ." seconds ago" );
1005 ### TODO: delete old floodwarn{} keys.
1007 if (!exists $floodwarn{$floodwho}) {
1010 $floodwarn++ if (time() - $floodwarn{$floodwho} > $interval);
1014 &status("FLOOD repetition detected from $floodwho.");
1015 $floodwarn{$floodwho} = time();
1022 &status("$b_cyan$who$ob is short-addressing me");
1023 } elsif ($msgType eq "private") { # private.
1024 &status("$b_cyan$who$ob is /msg'ing me");
1026 &status("$b_cyan$who$ob is addressing me");
1029 $flood{$floodwho}{$message} = time();
1032 $val = &getChanConfDefault("floodMessages", "5:30", $c);
1033 ($count, $interval) = split /:/, $val;
1035 # flood overflow protection.
1037 foreach (keys %{$flood{$floodwho}}) {
1038 next unless (time() - $flood{$floodwho}{$_} > $interval);
1039 delete $flood{$floodwho}{$_};
1042 my $i = scalar keys %{$flood{$floodwho}};
1044 &msg($who,"overflow of messages ($i > $count)");
1045 &status("FLOOD overflow detected from $floodwho; ignoring");
1047 my $expire = $param{'ignoreAutoExpire'} || 5;
1048 &ignoreAdd("*!$uh", $chan, $expire, "flood overflow auto-detected.");
1052 $flood{$floodwho}{$message} = time();
1055 if ($msgType =~ /public/i) { # public.
1056 $talkchannel = $chan;
1057 &status("<$orig{who}/$chan> $orig{message}");
1058 } elsif ($msgType =~ /private/i) { # private.
1059 &status("[$orig{who}] $orig{message}");
1060 $talkchannel = undef;
1063 &DEBUG("unknown msgType => $msgType.");
1066 if ((!$skipmessage or &IsChanConf("seenStoreAll")) and
1067 &IsChanConf("seen") and
1068 $msgType =~ /public/
1070 $seencache{$who}{'time'} = time();
1071 $seencache{$who}{'nick'} = $orig{who};
1072 $seencache{$who}{'host'} = $uh;
1073 $seencache{$who}{'chan'} = $talkchannel;
1074 $seencache{$who}{'msg'} = $orig{message};
1075 $seencache{$who}{'msgcount'}++;
1078 return if ($skipmessage);
1079 return unless (&IsParam("minVolunteerLength") or $addressed);
1082 if (exists $ignore{lc $chan}) {
1083 foreach (keys %{ $ignore{lc $chan} }) {
1086 next unless ($nuh =~ /^\Q$_\E$/i);
1093 if (!defined $userHandle) {
1094 &DEBUG("line 1074: need verifyUser?");
1095 &verifyUser($who, $nuh);
1098 &DEBUG("hookMsg: 'nuh' not defined?");
1101 ### For extra debugging purposes...
1102 if ($_ = &process()) {
1103 # &DEBUG("IrcHooks: process returned '$_'.");