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{"*"});
432 next unless ($nuh =~ /^$_$/i);
434 ### TODO: check $channels{$chan}{'b'} if ban already exists.
435 foreach (keys %{ $channels{$chan}{'b'} }) {
436 &DEBUG(" bans_on_chan($chan) => $_");
439 &DEBUG("ban($ban, $chan);");
441 ### TODO: get ban message from ban list.
442 &DEBUG("kick($who, $chan, NULL);");
443 &kick($who, $chan, "NULL");
448 &rootWarn($who,$user,$host,$chan)
449 if (&IsChanConf("rootWarn") &&
450 $user =~ /^r(oo|ew|00)t$/i &&
451 $channels{$chan}{'o'}{$ident});
454 &chanLimitVerify($chan);
456 # used to determine sync time.
457 if ($who =~ /^$ident$/i) {
458 if (defined( my $whojoin = $cache{join}{$chan} )) {
459 &msg($chan, "Okay, I'm here. (courtesy of $whojoin)");
460 delete $cache{join}{$chan};
463 ### TODO: move this to &joinchan()?
464 $cache{jointime}{$chan} = &gettimeofday();
467 ### TODO: this may go wild on a netjoin :)
474 my ($self, $event) = @_;
475 my ($chan,$reason) = $event->args;
476 my $kicker = $event->nick;
477 my $kickee = ($event->to)[0];
478 my $uh = $event->userhost();
480 &status(">>> kick/$b_blue$chan$ob [$b$kickee!$uh$ob] by $b_cyan$kicker$ob $b_yellow($ob$reason$b_yellow)$ob");
482 $chan = lc $chan; # forgot about this, found by xsdg, 20001229.
483 $chanstats{$chan}{'Kick'}++;
485 if ($kickee eq $ident) {
486 &clearChanVars($chan);
488 &status("SELF attempting to rejoin lost channel $chan");
491 &DeleteUserInfo($kickee,$chan);
496 my ($self, $event) = @_;
497 my ($user, $host) = split(/\@/, $event->userhost);
498 my @args = $event->args();
499 my $nick = $event->nick();
500 my $chan = ($event->to)[0];
504 if ($nick eq $chan) { # UMODE
505 &status(">>> mode $b_yellow\[$ob$b@args$b_yellow\]$ob by $b_cyan$nick$ob");
507 &status(">>> mode/$b_blue$chan$ob $b_yellow\[$ob$b@args$b_yellow\]$ob by $b_cyan$nick$ob");
508 &hookMode($chan, @args);
513 my ($self, $event) = @_;
514 my $nick = $event->nick();
515 my ($myself,$chan,@args) = $event->args();
517 &hookMode(lc $chan, @args); # CASING.
521 my ($self, $event) = @_;
522 my $nick = $event->nick;
523 my $msg = ($event->args)[0];
525 ($user,$host) = split(/\@/, $event->userhost);
526 $uh = $event->userhost();
527 $nuh = $nick."!".$uh;
529 &hookMsg('private', undef, $nick, $msg);
533 my ($self, $event) = @_;
534 my @args = $event->args;
535 my $chan = lc $args[2]; # CASING, the last of them!
537 foreach (split / /, @args[3..$#args]) {
538 $channels{$chan}{'o'}{$_}++ if s/\@//;
539 $channels{$chan}{'v'}{$_}++ if s/\+//;
540 $channels{$chan}{''}{$_}++;
545 my ($self, $event) = @_;
546 my $nick = $event->nick();
547 my $newnick = ($event->args)[0];
549 if (exists $netsplit{lc $newnick}) {
550 &status("Netsplit: $newnick/$nick came back from netsplit and changed to original nick! removing from hash.");
551 delete $netsplit{lc $newnick};
555 foreach $chan (keys %channels) {
556 foreach $mode (keys %{$channels{$chan}}) {
557 next unless (exists $channels{$chan}{$mode}{$nick});
559 $channels{$chan}{$mode}{$newnick} = $channels{$chan}{$mode}{$nick};
562 &DeleteUserInfo($nick,keys %channels);
563 $nuh{lc $newnick} = $nuh{lc $nick};
564 delete $nuh{lc $nick};
566 # successful self-nick change.
567 if ($nick eq $ident) {
568 &status(">>> I materialized into $b_green$newnick$ob from $nick");
571 &status(">>> $b_cyan$nick$ob materializes into $b_green$newnick$ob");
577 my $nick = $self->nick;
578 my $newnick = substr($nick,0,7)."-";
580 &status("nick taken; changing to temporary nick.");
586 my ($self, $event) = @_;
587 my $nick = $event->nick();
588 my $chan = ($event->to)[0];
589 my $args = ($event->args)[0];
591 if ($nick =~ /^NickServ$/i) { # nickserv.
592 &status("NickServ: <== '$args'");
594 if ($args =~ /^This nickname is registered/i) {
595 &status("nickserv told us to register; doing it.");
596 if (&IsParam("nickServ_pass")) {
597 &status("NickServ: ==> Identifying.");
598 &rawout("PRIVMSG NickServ :IDENTIFY $param{'nickServ_pass'}");
601 &status("We can't tell nickserv a passwd ;(");
606 if ($args =~ /^Password a/i) {
609 } elsif ($nick =~ /^ChanServ$/i) { # chanserv.
610 &status("ChanServ: <== '$args'.");
612 if ($chan =~ /^$mask{chan}$/) { # channel notice.
613 &status("-$nick/$chan- $args");
615 $server = $nick unless (defined $server);
616 &status("-$nick- $args"); # private or server notice.
622 my ($self, $event) = @_;
623 my $chan = ($event->to)[0];
624 my $nick = $event->nick;
626 &status("!!! other called.");
627 &status("!!! $event->args");
631 my ($self, $event) = @_;
632 my $chan = lc( ($event->to)[0] ); # CASING!!!
633 my $nick = $event->nick;
634 my $userhost = $event->userhost;
636 if (exists $floodjoin{$chan}{$nick}{Time}) {
637 delete $floodjoin{$chan}{$nick};
640 $chanstats{$chan}{'Part'}++;
641 &DeleteUserInfo($nick,$chan);
642 &clearChanVars($chan) if ($nick eq $ident);
643 if (!&IsNickInAnyChan($nick) and &IsChanConf("seenStats")) {
644 delete $userstats{lc $nick};
647 &status(">>> part/$b_blue$chan$ob $b_cyan$nick$ob $b_yellow($ob$userhost$b_yellow)$ob");
651 my ($self, $event) = @_;
652 my $nick = $event->nick;
654 $self->ctcp_reply($nick, join(' ', ($event->args)));
655 &status(">>> ${b_green}CTCP PING$ob request from $b_cyan$nick$ob received.");
659 my ($self, $event) = @_;
660 my $nick = $event->nick;
661 my $lag = time() - ($event->args)[1];
663 &status(">>> ${b_green}CTCP PING$ob reply from $b_cyan$nick$ob: $lag sec.");
667 my ($self, $event) = @_;
668 my $msg = ($event->args)[0];
669 my $chan = lc( ($event->to)[0] ); # CASING.
670 my $nick = $event->nick;
671 $uh = $event->userhost();
672 $nuh = $nick."!".$uh;
673 ($user,$host) = split(/\@/, $uh);
675 if ($bot_pid != $$) {
676 &ERROR("run-away fork; exiting.");
681 if ($statcount < 200) {
682 foreach $chan (grep /[A-Z]/, keys %channels) {
683 &DEBUG("leak: chan => '$chan'.");
685 foreach $i (keys %{$channels{$chan}}) {
686 foreach (keys %{$channels{$chan}{$i}}) {
687 &DEBUG("leak: \$channels{$chan}{$i}{$_} ...");
695 $lastWho{$chan} = $nick;
696 ### TODO: use $nick or lc $nick?
697 if (&IsChanConf("seenStats")) {
698 $userstats{lc $nick}{'Count'}++;
699 $userstats{lc $nick}{'Time'} = time();
702 # if (&IsChanConf("hehCounter")) {
706 &hookMsg('public', $chan, $nick, $msg);
707 $chanstats{$chan}{'PublicMsg'}++;
711 my ($self, $event) = @_;
712 my $nick = $event->nick();
713 my $reason = ($event->args)[0];
716 foreach (keys %channels) {
717 # fixes inconsistent chanstats bug #1.
718 if (!&IsNickInChan($nick,$_)) {
722 $chanstats{$_}{'SignOff'}++;
725 if ($count == scalar keys %channels) {
726 &DEBUG("on_quit: nick $nick was not found in any chan.");
729 &DeleteUserInfo($nick, keys %channels);
731 if (exists $nuh{lc $nick}) {
732 delete $nuh{lc $nick};
734 &DEBUG("on_quit: nuh{lc $nick} does not exist! FIXME");
736 delete $userstats{lc $nick} if (&IsChanConf("seenStats"));
738 # should fix chanstats inconsistencies bug #2.
739 if ($reason=~/^($mask{host})\s($mask{host})$/) { # netsplit.
740 $reason = "NETSPLIT: $1 <=> $2";
742 if (&ChanConfList("chanlimitcheck") and !scalar keys %netsplit) {
743 &DEBUG("on_quit: netsplit detected; disabling chan limit.");
744 &rawout("MODE $chan -l");
747 $netsplit{lc $nick} = time();
748 if (!exists $netsplitservers{$1}{$2}) {
749 &status("netsplit detected between $1 and $2.");
750 $netsplitservers{$1}{$2} = time();
754 &status(">>> $b_cyan$nick$ob has signed off IRC $b_red($ob$reason$b_red)$ob");
755 if ($nick =~ /^\Q$ident\E$/) {
756 &DEBUG("^^^ THIS SHOULD NEVER HAPPEN.");
759 if ($nick !~ /^\Q$ident\E$/ and $nick =~ /^\Q$param{'ircNick'}\E$/i) {
760 &status("own nickname became free; changing.");
761 &nick($param{'ircNick'});
765 sub on_targettoofast {
766 my ($self, $event) = @_;
767 my $nick = $event->nick();
768 my($me,$chan,$why) = $event->args();
770 ### TODO: incomplete.
771 ### .* wait (\d+) second/) {
772 &status("on_ttf: X1 $msg") if (defined $msg);
774 &status("going to sleep for $sleep...");
781 my ($self, $event) = @_;
783 if (scalar($event->args) == 1) { # change.
784 my $topic = ($event->args)[0];
785 my $chan = ($event->to)[0];
786 my $nick = $event->nick();
790 # race condition here. To fix, change '1' to '0'.
791 # This will keep track of topics set by bot only.
794 # this may be fixed at a later date with topic queueing.
797 $topic{$chan}{'Current'} = $topic if (1);
798 $chanstats{$chan}{'Topic'}++;
800 &status(">>> topic/$b_blue$chan$ob by $b_cyan$nick$ob -> $topic");
802 my ($nick, $chan, $topic) = $event->args;
803 if (&IsChanConf("topic")) {
804 $topic{$chan}{'Current'} = $topic;
805 &topicAddHistory($chan,$topic);
808 $topic = &fixString($topic, 1);
809 &status(">>> topic/$b_blue$chan$ob is $topic");
814 my ($self, $event) = @_;
815 my ($myself,$chan,$setby,$time) = $event->args();
818 if (time() - $time > 60*60*24) {
819 $timestr = "at ". localtime $time;
821 $timestr = &Time2String(time() - $time) ." ago";
824 &status(">>> set by $b_cyan$setby$ob $timestr");
828 my ($self, $event) = @_;
829 my $nick = $event->nick();
832 if (scalar $event->args() != 1) { # old.
833 $ver = join ' ', $event->args();
834 $ver =~ s/^VERSION //;
836 $ver = ($event->args())[0];
839 if (grep /^\Q$nick\E$/i, @vernick) {
840 &WARN("nick $nick found in vernick; skipping.");
843 push(@vernick, $nick);
845 if ($ver =~ /bitchx/i) {
846 $ver{bitchx}{$nick} = $ver;
847 } elsif ($ver =~ /xc\!|xchat/i) {
848 $ver{xchat}{$nick} = $ver;
849 } elsif ($ver =~ /irssi/i) {
850 $ver{irssi}{$nick} = $ver;
851 } elsif ($ver =~ /epic/i) {
852 $ver{epic}{$nick} = $ver;
853 } elsif ($ver =~ /mirc/i) {
854 $ver{mirc}{$nick} = $ver;
855 } elsif ($ver =~ /ircle/i) {
856 $ver{ircle}{$nick} = $ver;
857 } elsif ($ver =~ /ircII/i) {
858 $ver{ircII}{$nick} = $ver;
859 } elsif ($ver =~ /sirc /i) {
860 $ver{sirc}{$nick} = $ver;
861 } elsif ($ver =~ /kvirc/i) {
862 $ver{kvirc}{$nick} = $ver;
863 } elsif ($ver =~ /eggdrop/i) {
864 $ver{eggdrop}{$nick} = $ver;
865 } elsif ($ver =~ /xircon/i) {
866 $ver{xircon}{$nick} = $ver;
868 $ver{other}{$nick} = $ver;
873 my ($self, $event) = @_;
874 my $nick = $event->nick;
876 &status(">>> ${b_green}CTCP VERSION$ob request from $b_cyan$nick$ob");
877 $self->ctcp_reply($nick, "VERSION $bot_version");
881 my ($self, $event) = @_;
882 my @args = $event->args;
884 $nuh{lc $args[5]} = $args[5]."!".$args[2]."\@".$args[3];
888 my ($self, $event) = @_;
889 my @args = $event->args;
891 &DEBUG("on_whoisuser: @args");
893 $nuh{lc $args[1]} = $args[1]."!".$args[2]."\@".$args[3];
896 #######################################################################
897 ####### IRC HOOK HELPERS IRC HOOK HELPERS IRC HOOK HELPERS ########
898 #######################################################################
901 # Usage: &hookMode($chan, $modes, @targets);
903 my ($chan, $modes, @targets) = @_;
906 $chan = lc $chan; # !!!.
909 foreach $mode (split(//, $modes)) {
911 if ($mode =~ /[-+]/) {
912 $parity = 1 if ($mode eq "+");
913 $parity = 0 if ($mode eq "-");
918 if ($mode =~ /[bklov]/) {
919 my $target = shift @targets;
922 $chanstats{$chan}{'Op'}++ if ($mode eq "o");
923 $chanstats{$chan}{'Ban'}++ if ($mode eq "b");
925 $chanstats{$chan}{'Deop'}++ if ($mode eq "o");
926 $chanstats{$chan}{'Unban'}++ if ($mode eq "b");
929 # modes w/ target affecting nick => cache it.
930 if ($mode =~ /[bov]/) {
931 $channels{$chan}{$mode}{$target}++ if $parity;
932 delete $channels{$chan}{$mode}{$target} if !$parity;
935 if ($mode =~ /[l]/) {
936 $channels{$chan}{$mode} = $target if $parity;
937 delete $channels{$chan}{$mode} if !$parity;
941 # important channel modes, targetless.
942 if ($mode =~ /[mt]/) {
943 $channels{$chan}{$mode}++ if $parity;
944 delete $channels{$chan}{$mode} if !$parity;
950 ($msgType, $chan, $who, $message) = @_;
954 $orig{message} = $message;
958 $message =~ s/[\cA-\c_]//ig; # strip control characters
959 $message =~ s/^\s+//; # initial whitespaces.
960 $who =~ tr/A-Z/a-z/; # lowercase.
965 if ($msgType =~ /private/) {
970 # addressing revamped by the xk.
971 ### below needs to be fixed...
972 if (&IsParam("addressCharacter")) {
973 if ($message =~ s/^$param{'addressCharacter'}//) {
979 if ($message =~ /^($mask{nick})([\;\:\>\, ]+) */) {
981 if ($1 =~ /^\Q$ident\E$/i) {
982 $message = $newmessage;
985 # ignore messages addressed to other people or unaddressed.
986 $skipmessage++ if ($2 ne "" and $2 !~ /^ /);
991 # Determine floodwho.
993 if ($msgType =~ /public/i) { # public.
994 $floodwho = $c = lc $chan;
995 } elsif ($msgType =~ /private/i) { # private.
998 &DEBUG("FIXME: floodwho = ???");
1001 my $val = &getChanConfDefault("floodRepeat", "2:10", $c);
1002 my ($count, $interval) = split /:/, $val;
1004 # flood repeat protection.
1006 my $time = $flood{$floodwho}{$message} || 0;
1008 if ($msgType eq "public" and (time() - $time < $interval)) {
1009 ### public != personal who so the below is kind of pointless.
1011 foreach (keys %flood) {
1012 next if (/^\Q$floodwho\E$/);
1013 next if (defined $chan and /^\Q$chan\E$/);
1015 push(@who, grep /^\Q$message\E$/i, keys %{ $flood{$_} });
1019 &msg($who, "you already said what ".
1020 join(' ', @who)." have said.");
1022 &msg($who,"Someone already said that ". (time - $time) ." seconds ago" );
1025 ### TODO: delete old floodwarn{} keys.
1027 if (!exists $floodwarn{$floodwho}) {
1030 $floodwarn++ if (time() - $floodwarn{$floodwho} > $interval);
1034 &status("FLOOD repetition detected from $floodwho.");
1035 $floodwarn{$floodwho} = time();
1042 &status("$b_cyan$who$ob is short-addressing me");
1043 } elsif ($msgType eq "private") { # private.
1044 &status("$b_cyan$who$ob is /msg'ing me");
1046 &status("$b_cyan$who$ob is addressing me");
1049 $flood{$floodwho}{$message} = time();
1050 } elsif ($msgType eq "public" and &IsChanConf("kickOnRepeat")) {
1051 # unaddressed, public only.
1053 ### TODO: use a separate "short-time" hash.
1055 @data = keys %{ $flood{$floodwho} } if (exists $flood{$floodwho});
1058 $val = &getChanConfDefault("floodMessages", "5:30", $c);
1059 ($count, $interval) = split /:/, $val;
1061 # flood overflow protection.
1063 foreach (keys %{$flood{$floodwho}}) {
1064 next unless (time() - $flood{$floodwho}{$_} > $interval);
1065 delete $flood{$floodwho}{$_};
1068 my $i = scalar keys %{$flood{$floodwho}};
1070 &msg($who,"overflow of messages ($i > $count)");
1071 &status("FLOOD overflow detected from $floodwho; ignoring");
1073 my $expire = $param{'ignoreAutoExpire'} || 5;
1074 &ignoreAdd("*!$uh", $chan, $expire, "flood overflow auto-detected.");
1078 $flood{$floodwho}{$message} = time();
1082 if ($msgType =~ /public/i) { # public.
1083 $talkchannel = $chan;
1084 &status("<$orig{who}/$chan> $orig{message}");
1085 push(@ignore, keys %{ $ignore{$chan} }) if (exists $ignore{$chan});
1086 } elsif ($msgType =~ /private/i) { # private.
1087 &status("[$orig{who}] $orig{message}");
1088 $talkchannel = undef;
1091 &DEBUG("unknown msgType => $msgType.");
1093 push(@ignore, keys %{ $ignore{"*"} }) if (exists $ignore{"*"});
1095 if ((!$skipmessage or &IsChanConf("seenStoreAll")) and
1096 &IsChanConf("seen") and
1097 $msgType =~ /public/
1099 $seencache{$who}{'time'} = time();
1100 $seencache{$who}{'nick'} = $orig{who};
1101 $seencache{$who}{'host'} = $uh;
1102 $seencache{$who}{'chan'} = $talkchannel;
1103 $seencache{$who}{'msg'} = $orig{message};
1104 $seencache{$who}{'msgcount'}++;
1107 return if ($skipmessage);
1108 return unless (&IsParam("minVolunteerLength") or $addressed);
1113 next unless (eval { $nuh =~ /^$_$/i });
1115 &status("IGNORE <$who> $message");
1120 if (!defined $userHandle) {
1121 &DEBUG("line 1074: need verifyUser?");
1122 &verifyUser($who, $nuh);
1125 &DEBUG("hookMsg: 'nuh' not defined?");
1128 ### For extra debugging purposes...
1129 if ($_ = &process()) {
1130 # &DEBUG("IrcHooks: process returned '$_'.");
1136 sub chanLimitVerify {
1138 my $l = $channels{$chan}{'l'};
1140 # only change it if it's not set.
1141 if (defined $l and &IsChanConf("chanlimitcheck")) {
1142 my $plus = &getChanConfDefault("chanlimitcheckPlus", 5, $chan);
1143 my $nowl = scalar(keys %{ $channels{$chan}{''} });
1144 my $delta = $nowl - $l;
1148 &WARN("clc: stupid to have plus at $plus, fix it!");
1151 ### todo: check if we have ops.
1152 ### todo: if not, check if nickserv/chanserv is avail.
1153 ### todo: unify code with chanlimitcheck()
1155 &WARN("clc: nowl($nowl) > l($l) - 3");
1156 &rawout("MODE $chan +l ".($nowl+$plus) );