]> git.donarmstrong.com Git - infobot.git/blobdiff - src/IRC/IrcHooks.pl
- pointless regex in on_dcc_chat_open that I was going to deal with on
[infobot.git] / src / IRC / IrcHooks.pl
index 382d745f781a5c58152984d5aeb12ac0cc7f4353..7362033ac5fa37ede17a96fdaa9fbe6107d20053 100644 (file)
@@ -41,24 +41,23 @@ sub on_chat {
     my $sock = ($event->to)[0];
     my $nick = $event->nick();
 
-    $userHandle                = "";   # reset.
-
-    # who is set to bot's name, why?
-
-    if (!exists $nuh{$who}) {
-       &DEBUG("chat: nuh{$who} doesn't exist; hrm should retry.");
+    if (!exists $nuh{$nick}) {
+       &DEBUG("chat: nuh{$nick} doesn't exist; trying WHOIS .");
+       $self->whois($nick);
        return;
-    } else {
-       $message        = $msg;
-       $who            = lc $nick;
-       $orig{who}      = $nick;
-       $orig{message}  = $msg;
-       $nuh            = $nuh{$who};
-       $uh             = (split /\!/, $nuh)[1];
-       $addressed      = 1;
-       $msgType        = 'chat';
     }
 
+    ### set vars that would have been set in hookMsg.
+    $userHandle                = "";   # reset.
+    $who               = lc $nick;
+    $message           = $msg;
+    $orig{who}         = $nick;
+    $orig{message}     = $msg;
+    $nuh               = $nuh{$who};
+    $uh                        = (split /\!/, $nuh)[1];
+    $addressed         = 1;
+    $msgType           = 'chat';
+
     if (!exists $dcc{'CHATvrfy'}{$nick}) {
        $userHandle     = &verifyUser($who, $nuh);
        my $crypto      = $users{$userHandle}{PASS};
@@ -171,10 +170,11 @@ sub on_dcc {
     my $nick = $event->nick();
 
     # pity Net::IRC doesn't store nuh. Here's a hack :)
-    $self->whois($nick);
-    $nuh{lc $nick}     = "GETTING-NOW";        # trying.
+    if (!exists $nuh{lc $nick}) {
+       $self->whois($nick);
+       $nuh{lc $nick}  = "GETTING-NOW";        # trying.
+    }
     $type ||= "???";
-    &DEBUG("on_dcc: nuh => GETTING-NOW.");
 
     if ($type eq 'SEND') {     # GET for us.
        # incoming DCC SEND. we're receiving a file.
@@ -267,11 +267,7 @@ sub on_dcc_open {
 sub on_dcc_open_chat {
     my(undef, $nick,$sock) = @_;
 
-    &DEBUG("nuh{$nick} => $nuh{$nick}.");
-    if ($nuh{$nick} =~ /^(\S+)(\d+)$/) {
-       my $i = $2;
-       $i++;
-       $nuh{$nick} = $1.$i;
+    if ($nuh{$nick} eq "GETTING-NOW") {
        &DEBUG("getting nuh for $nick failed. FIXME.");
        return;
     }
@@ -320,8 +316,8 @@ sub on_endofnames {
     my ($self, $event) = @_;
     my $chan = ($event->args)[1];
 
-    if (exists $jointime{$chan}) {
-       my $delta_time = sprintf("%.03f", &gettimeofday() - $jointime{$chan});
+    if (exists $cache{jointime}{$chan}) {
+       my $delta_time = sprintf("%.03f", &gettimeofday() - $cache{jointime}{$chan});
        $delta_time    = 0      if ($delta_time < 0);
 
        &status("$b_blue$chan$ob: sync in ${delta_time}s.");
@@ -346,17 +342,14 @@ sub on_endofnames {
 
     if (scalar @joinchan) {    # remaining channels to join.
        &joinNextChan();
-    } else {
-       ### chanserv support.
-       ### TODO: what if we rejoin a channel.. need to set a var that
-       ###       we've done the request-for-ops-on-join.
-       return unless (&IsChanConf("chanServ_ops") > 0);
-       return unless ($nickserv);
-
-       if (!exists $channels{$chan}{'o'}{$ident}) {
-           &status("ChanServ ==> Requesting ops for $chan.");
-           &rawout("PRIVMSG ChanServ :OP $chan $ident");
-       }
+    }
+
+    return unless (&IsChanConf("chanServ_ops") > 0);
+    return unless ($nickserv);
+
+    if (!exists $channels{$chan}{'o'}{$ident}) {
+       &status("ChanServ ==> Requesting ops for $chan.");
+       &rawout("PRIVMSG ChanServ :OP $chan $ident");
     }
 }
 
@@ -409,7 +402,7 @@ sub on_join {
     }
 
     if ($netsplit and !$netsplittime) {
-       &status("ok.... re-running chanlimitCheck in 60.");
+       &DEBUG("on_join: ok.... re-running chanlimitCheck in 60.");
        $conn->schedule(60, sub {
                &chanlimitCheck();
                $netsplittime = undef;
@@ -450,15 +443,18 @@ sub on_join {
                    $user =~ /^r(oo|ew|00)t$/i &&
                    $channels{$chan}{'o'}{$ident});
 
+    ### chanlimit check.
+    &chanLimitVerify($chan);
+
     # used to determine sync time.
     if ($who =~ /^$ident$/i) {
-       if (defined( my $whojoin = $joinverb{$chan} )) {
+       if (defined( my $whojoin = $cache{join}{$chan} )) {
            &msg($chan, "Okay, I'm here. (courtesy of $whojoin)");
-           delete $joinverb{$chan};
+           delete $cache{join}{$chan};
        }
 
        ### TODO: move this to &joinchan()?
-       $jointime{$chan} = &gettimeofday();
+       $cache{jointime}{$chan} = &gettimeofday();
        rawout("WHO $chan");
     } else {
        ### TODO: this may go wild on a netjoin :)
@@ -709,12 +705,22 @@ sub on_quit {
     my $nick = $event->nick();
     my $reason = ($event->args)[0];
 
+    my $count  = 0;
     foreach (keys %channels) {
        # fixes inconsistent chanstats bug #1.
-       next unless (&IsNickInChan($nick,$_));
+       if (!&IsNickInChan($nick,$_)) {
+           $count++;
+           next;
+       }
        $chanstats{$_}{'SignOff'}++;
     }
+
+    if ($count == scalar keys %channels) {
+       &DEBUG("on_quit: nick $nick was not found in any chan.");
+    }
+
     &DeleteUserInfo($nick, keys %channels);
+
     if (exists $nuh{lc $nick}) {
        delete $nuh{lc $nick};
     } else {
@@ -726,6 +732,11 @@ sub on_quit {
     if ($reason=~/^($mask{host})\s($mask{host})$/) {   # netsplit.
        $reason = "NETSPLIT: $1 <=> $2";
 
+       if (&ChanConfList("chanlimitcheck") and !scalar keys %netsplit) {
+           &DEBUG("on_quit: netsplit detected; disabling chan limit.");
+           &rawout("MODE $chan -l");
+       }
+
        $netsplit{lc $nick} = time();
        if (!exists $netsplitservers{$1}{$2}) {
            &status("netsplit detected between $1 and $2.");
@@ -775,7 +786,7 @@ sub on_topic {
        #       this may be fixed at a later date with topic queueing.
        ###
 
-       $topic{$chan}{'Current'} = $topic if (1 and &IsChanConf("topic") == 1);
+       $topic{$chan}{'Current'} = $topic if (1);
        $chanstats{$chan}{'Topic'}++;
 
        &status(">>> topic/$b_blue$chan$ob by $b_cyan$nick$ob -> $topic");
@@ -1107,4 +1118,29 @@ sub hookMsg {
     return;
 }
 
+sub chanLimitVerify {
+    my($chan)  = @_;
+    my $l      = $channels{$chan}{'l'};
+
+    # only change it if it's not set.
+    if (defined $l and &IsChanConf("chanlimitcheck")) {
+       my $plus = &getChanConfDefault("chanlimitcheckPlus", 5, $chan);
+       my $nowl = scalar(keys %{ $channels{$chan}{''} });
+       my $delta       = $nowl - $l;
+       $delta          =~ s/^\-//;
+
+       if ($plus <= 3) {
+           &WARN("clc: stupid to have plus at $plus, fix it!");
+       }
+
+       ### todo: check if we have ops.
+       ### todo: if not, check if nickserv/chanserv is avail.
+       ### todo: unify code with chanlimitcheck()
+       if ($delta > 3) {
+           &WARN("clc: nowl($nowl) > l($l) - 3");
+           &rawout("MODE $chan +l ".($nowl+$plus) );
+       }
+    }
+}
+
 1;