X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2FIRC%2FIrcHooks.pl;h=9c9d87c06f70531924671117d36234add002135f;hb=f7cae48a17d6decd0a9bd997188271daa0a885b1;hp=1a77e32a3ce2ee3480072faaa030b8cdde51dfd6;hpb=c7f705958b79e5a22564aa9525817a029adaeeca;p=infobot.git diff --git a/src/IRC/IrcHooks.pl b/src/IRC/IrcHooks.pl index 1a77e32..9c9d87c 100644 --- a/src/IRC/IrcHooks.pl +++ b/src/IRC/IrcHooks.pl @@ -5,8 +5,6 @@ # NOTE: Based on code by Kevin Lenzo & Patrick Cole (c) 1997 # -if (&IsParam("useStrict")) { use strict; } - # GENERIC. TO COPY. sub on_generic { my ($self, $event) = @_; @@ -55,6 +53,7 @@ sub on_chat { $orig{message} = $msg; $nuh = $nuh{$who}; $uh = (split /\!/, $nuh)[1]; + $h = (split /\@/, $uh)[1]; $addressed = 1; $msgType = 'chat'; @@ -90,7 +89,7 @@ sub on_chat { &DEBUG("chat: sock => '$sock'."); ### $sock->close(); delete $dcc{'CHAT'}{$nick}; - &DEBUG("chat: after closing sock. FIXME"); + &FIXME("chat: after closing sock."); ### BUG: close seizes bot. why? } @@ -132,15 +131,28 @@ sub on_chat { return 'DCC CHAT MESSAGE'; } +# is there isoff? how do we know if someone signs off? +sub on_ison { + my ($self, $event) = @_; + my $x1 = ($event->args)[0]; + my $x2 = ($event->args)[1]; + $x2 =~ s/\s$//; + +# &nick( $param{'ircNick'} ); + + &DEBUG("on_ison: x1 = '$x1', x2 => '$x2'"); +} + sub on_endofmotd { my ($self) = @_; # update IRCStats. - $ident ||= $param{'ircNick'}; # hack. + $ident = $param{'ircNick'}; $ircstats{'ConnectTime'} = time(); $ircstats{'ConnectCount'}++; - $ircstats{'OffTime'} += time() - $ircstats{'DisconnectTime'} - if (defined $ircstats{'DisconnectTime'}); + if (defined $ircstats{'DisconnectTime'}) { + $ircstats{'OffTime'} += time() - $ircstats{'DisconnectTime'}; + } # first time run. if (!exists $users{_default}) { @@ -184,14 +196,21 @@ sub on_endofmotd { &status("End of motd. Now lets join some channels..."); if (!scalar @joinchan) { - &WARN("joinchan array is empty!!!"); + &WARN("joinchan array is empty!"); @joinchan = &getJoinChans(1); } - # unfortunately, Net::IRC does not implement this :( - # invalid command... what is it? -# &rawout("NOTIFY $ident"); -# &DEBUG("adding self to NOTIFY list."); + # ok, we're free to do whatever we want now. go for it! + $running = 1; + + # add ourself to notify. + $conn->ison( $param{'ircNick'} ); + + # Q, as on quakenet.org. + if (&IsParam("Q_pass")) { + &status("Authing to Q..."); + &rawout("PRIVMSG Q\@CServe.quakenet.org :AUTH $param{'Q_user'} $param{'Q_pass'}"); + } &joinNextChan(); } @@ -224,13 +243,8 @@ sub on_dcc { my $get = ($event->args)[2]; open(DCCGET,">$get"); - $self->new_get($nick, - ($event->args)[2], - ($event->args)[3], - ($event->args)[4], - ($event->args)[5], - \*DCCGET - ); + $self->new_get($event, \*DCCGET); + } elsif ($type eq 'GET') { # SEND for us? &status("DCC: Initializing SEND for $nick."); $self->new_send($event->args); @@ -238,6 +252,7 @@ sub on_dcc { } elsif ($type eq 'CHAT') { &status("DCC: Initializing CHAT for $nick."); $self->new_chat($event); +# $self->new_chat(1, $nick, $event->host); } else { &WARN("${b_green}DCC $type$ob (1)"); @@ -312,7 +327,7 @@ sub on_dcc_open_chat { my(undef, $nick, $sock) = @_; if ($nuh{$nick} eq "GETTING-NOW") { - &DEBUG("getting nuh for $nick failed. FIXME."); + &FIXME("getting nuh for $nick failed."); return; } @@ -360,12 +375,19 @@ sub on_disconnect { $nickserv = 0; &clearIRCVars(); + + if (!defined $self) { + &WARN("on_disconnect: self is undefined! WTF"); + &DEBUG("running function irc... lets hope this works."); + &irc(); + return; + } + if (!$self->connect()) { + &DEBUG("on_disconnect: 3"); &WARN("not connected? help me. gonna call ircCheck() in 60s"); &clearIRCVars(); &ScheduleThis(1, "ircCheck"); -# &ScheduleThis(10, "ircCheck"); -# &ScheduleThis(30, "ircCheck"); } } @@ -384,7 +406,7 @@ sub on_endofnames { &status("$b_blue$chan$ob: sync in ${delta_time}s."); } - &rawout("MODE $chan"); + $conn->mode($chan); my $txt; my @array; @@ -426,9 +448,10 @@ sub on_invite { ### TODO: join key. if (exists $chanconf{$chan}) { + # it's still buggy :/ if (&validChan($chan)) { &msg($who, "i'm already in \002$chan\002."); - next; +# return; } &status("invited to $b_blue$chan$ob by $b_cyan$nick$ob"); @@ -445,8 +468,13 @@ sub on_join { my $i = scalar(keys %{ $channels{$chan} }); my $j = $cache{maxpeeps}{$chan} || 0; + if (!&IsParam("noSHM") && time() > ($sched{shmFlush}{TIME} || time()) + 3600) { + &DEBUG("looks like schedulers died somewhere... restarting..."); + &setupSchedulers(); + } + $chanstats{$chan}{'Join'}++; - $userstats{lc $who}{'Join'} = time() if (&IsChanConf("seenStats")); + $userstats{lc $who}{'Join'} = time() if (&IsChanConf("seenStats") > 0); $cache{maxpeeps}{$chan} = $i if ($i > $j); &joinfloodCheck($who, $chan, $event->userhost); @@ -527,11 +555,12 @@ sub on_join { if (defined( my $whojoin = $cache{join}{$chan} )) { &msg($chan, "Okay, I'm here. (courtesy of $whojoin)"); delete $cache{join}{$chan}; + &joinNextChan(); # hack. } ### TODO: move this to &joinchan()? $cache{jointime}{$chan} = &timeget(); - rawout("WHO $chan"); + $conn->who($chan); return; } @@ -539,7 +568,7 @@ sub on_join { ### ROOTWARN: &rootWarn($who,$user,$host,$chan) if ( &IsChanConf("rootWarn") && - $user =~ /^r(oo|ew|00)t$/i + $user =~ /^~?r(oo|ew|00)t$/i ); ### NEWS: @@ -551,8 +580,10 @@ sub on_join { } } - ### chanlimit check. -# &chanLimitVerify($chan); + ### botmail: + if (&IsChanConf("botmail")) { + &botmail::check(lc $who); + } ### wingate: &wingateCheck(); @@ -587,7 +618,8 @@ sub on_mode { my $nick = $event->nick(); $chan = ($event->to)[0]; - $args[0] =~ s/\s$//; + # last element is empty... so nuke it. + pop @args while ($args[$#args] eq ""); if ($nick eq $chan) { # UMODE &status(">>> mode $b_yellow\[$ob$b@args$b_yellow\]$ob by $b_cyan$nick$ob"); @@ -615,6 +647,7 @@ sub on_msg { $uh = $event->userhost(); $nuh = $nick."!".$uh; $msgtime = time(); + $h = $host; if ($nick eq $ident) { # hopefully ourselves. if ($msg eq "TEST") { @@ -644,7 +677,7 @@ sub on_names { sub on_nick { my ($self, $event) = @_; - my $nick = $event->nick(); + my $nick = $event->nick(); my $newnick = ($event->args)[0]; if (exists $netsplit{lc $newnick}) { @@ -681,8 +714,15 @@ sub on_nick { sub on_nick_taken { my ($self) = @_; - my $nick = $self->nick; - my $newnick = $nick."-"; + my $nick = $self->nick(); + my $newnick = $nick.int(rand 10); + + if ($nick eq $ident) { + &DEBUG("on_nick_tane: nick eq ident... wtf?"); + return; + } + + &DEBUG("on_nick_taken: ident => $ident"); &status("nick taken ($nick); preparing nick change."); @@ -731,6 +771,7 @@ sub on_notice { $nickserv++; } + } elsif ($nick =~ /^ChanServ$/i) { # chanserv. &status("ChanServ: <== '$args'."); @@ -773,11 +814,10 @@ sub on_part { $chanstats{$chan}{'Part'}++; &delUserInfo($nick,$chan); if ($nick eq $ident) { - &DEBUG("on_part: ok, I left $chan... clearChanVars..."); &clearChanVars($chan); } - if (!&IsNickInAnyChan($nick) and &IsChanConf("seenStats")) { + if (!&IsNickInAnyChan($nick) and &IsChanConf("seenStats") > 0) { delete $userstats{lc $nick}; } @@ -794,8 +834,14 @@ sub on_ping { sub on_ping_reply { my ($self, $event) = @_; - my $nick = $event->nick; - my $lag = time() - ($event->args)[1]; + my $nick = $event->nick; + my $t = ($event->args)[1]; + if (!defined $t) { + &WARN("on_ping_reply: t == undefined."); + return; + } + + my $lag = time() - $t; &status(">>> ${b_green}CTCP PING$ob reply from $b_cyan$nick$ob: $lag sec."); } @@ -811,6 +857,7 @@ sub on_public { $msgType = "public"; # todo: move this out of hookMsg to here? ($user,$host) = split(/\@/, $uh); + $h = $host; # rare case should this happen - catch it just in case. if ($bot_pid != $$) { @@ -821,47 +868,45 @@ sub on_public { $msgtime = time(); $lastWho{$chan} = $nick; ### TODO: use $nick or lc $nick? - if (&IsChanConf("seenStats")) { + if (&IsChanConf("seenStats") > 0) { $userstats{lc $nick}{'Count'}++; $userstats{lc $nick}{'Time'} = time(); } - # would this slow things down? - if ($_ = &getChanConf("ircTextCounters")) { - my $time = time(); - - foreach (split /[\s]+/) { - my $x = $_; - - # either full word or ends with a space, etc... - next unless ($msg =~ /^\Q$x\E[\$\s!.]/i); + # cache it. + my $time = time(); + if (!$cache{ircTextCounters}) { + &DEBUG("caching ircTextCounters for first time."); + my @str = split(/\s+/, &getChanConf("ircTextCounters")); + for (@str) { $_ = quotemeta($_); } + $cache{ircTextCounters} = join('|', @str); + } - &VERB("textcounters: $x matched for $who",2); - my $c = $chan || "PRIVATE"; + my $str = $cache{ircTextCounters}; + if ($str && $msg =~ /^($str)[\s!\.]?$/i) { + my $x = $1; - my ($v,$t) = &dbGet("stats", "counter,time", - "nick=". &dbQuote($who) - ." AND type=".&dbQuote($x) - ." AND channel=".&dbQuote($c) - ); - $v++; + &VERB("textcounters: $x matched for $who",2); + my $c = $chan || "PRIVATE"; - # don't allow ppl to cheat the stats :-) - next unless ($time - $t > 10); + # better to do "counter=counter+1". + # but that will avoid time check. + my ($v,$t) = &sqlSelect("stats", "counter,time", { + nick => $who, + type => $x, + channel => $c, + } ); + $v++; - my %hash = ( + # don't allow ppl to cheat the stats :-) + if (defined $t && $time - $t > 60) { + &sqlReplace("stats", { nick => $who, type => $x, channel => $c, - time => $time, counter => $v, - ); - - - &dbReplace("stats", "nick", %hash); - # does not work, atleast with old mysql!!! :( -# &dbReplace("stats", (nick => $who, type => $x, -counter => "counter+1") ); + } ); } } @@ -883,7 +928,7 @@ sub on_quit { ### $chan = $reason; # no. my $count = 0; - foreach (keys %channels) { + foreach (grep !/^_default$/, keys %channels) { # fixes inconsistent chanstats bug #1. if (!&IsNickInChan($nick,$_)) { $count++; @@ -906,12 +951,12 @@ sub on_quit { next unless ( exists $channels{$_}{'l'} ); &DEBUG("on_quit: netsplit detected on $_; disabling chan limit."); - &rawout("MODE $_ -l"); + $conn->mode($_, "-l"); } $netsplit{lc $nick} = time(); if (!exists $netsplitservers{$1}{$2}) { - &status("netsplit detected between $1 and $2 at [".scalar(localtime)."]"); + &status("netsplit detected between $1 and $2 at [".scalar(gmtime)."]"); $netsplitservers{$1}{$2} = time(); } } @@ -932,14 +977,14 @@ sub on_quit { # well.. it's good but weird that this has happened - lets just # be quiet about it. } - delete $userstats{lc $nick} if (&IsChanConf("seenStats")); + delete $userstats{lc $nick} if (&IsChanConf("seenStats") > 0); delete $chanstats{lc $nick}; ### # does this work? if ($nick !~ /^\Q$ident\E$/ and $nick =~ /^\Q$param{'ircNick'}\E$/i) { &status("nickchange: own nickname became free; changing."); - &nick($param{'ircNick'}); + &nick( $param{'ircNick'} ); } } @@ -1014,7 +1059,7 @@ sub on_topicinfo { my $timestr; if (time() - $time > 60*60*24) { - $timestr = "at ". localtime $time; + $timestr = "at ". gmtime $time; } else { $timestr = &Time2String(time() - $time) ." ago"; } @@ -1035,7 +1080,7 @@ sub on_crversion { } if (grep /^\Q$nick\E$/i, @vernick) { - &WARN("nick $nick found in vernick; skipping."); + &WARN("nick $nick found in vernick ($ver); skipping."); return; } push(@vernick, $nick); @@ -1049,18 +1094,25 @@ sub on_crversion { } elsif ($ver =~ /irssi/i) { $ver{irssi}{$nick} = $ver; - } elsif ($ver =~ /epic/i) { + } elsif ($ver =~ /epic|(Third Eye)/i) { $ver{epic}{$nick} = $ver; + } elsif ($ver =~ /ircII|PhoEniX/i) { + $ver{ircII}{$nick} = $ver; + } elsif ($ver =~ /mirc/i) { - &DEBUG("verstats: mirc: $nick => '$ver'."); +# &DEBUG("verstats: mirc: $nick => '$ver'."); $ver{mirc}{$nick} = $ver; +# ok... then we get to the lesser known/used clients. } elsif ($ver =~ /ircle/i) { $ver{ircle}{$nick} = $ver; - } elsif ($ver =~ /ircII/i) { - $ver{ircII}{$nick} = $ver; + } elsif ($ver =~ /chatzilla/i) { + $ver{chatzilla}{$nick} = $ver; + + } elsif ($ver =~ /pirch/i) { + $ver{pirch}{$nick} = $ver; } elsif ($ver =~ /sirc /i) { $ver{sirc}{$nick} = $ver; @@ -1139,7 +1191,8 @@ sub on_chanfull { my ($self, $event) = @_; my @args = $event->args; - &DEBUG("on_chanfull: args => @args"); + &status(">>> chanfull/$b_blue$args[1]$ob"); + &joinNextChan(); } @@ -1147,15 +1200,18 @@ sub on_inviteonly { my ($self, $event) = @_; my @args = $event->args; - &DEBUG("on_inviteonly: args => @args"); + &status(">>> inviteonly/$b_cyan$args[1]$ob"); + &joinNextChan(); } sub on_banned { my ($self, $event) = @_; my @args = $event->args; + my $chan = $args[1]; + + &status(">>> banned/$b_blue$chan$ob $b_cyan$args[0]$ob"); - &DEBUG("on_banned: args => @args"); &joinNextChan(); } @@ -1167,4 +1223,12 @@ sub on_badchankey { &joinNextChan(); } +sub on_useronchan { + my ($self, $event) = @_; + my @args = $event->args; + + &DEBUG("on_useronchan: args => @args"); + &joinNextChan(); +} + 1;