]> git.donarmstrong.com Git - infobot.git/blobdiff - blootbot/src/IRC/Irc.pl
- updates to DEBUG/WARN/ERROR or the result of looking at them
[infobot.git] / blootbot / src / IRC / Irc.pl
index 18ae6ef6225e443263c2541e93d3c6d9c5314b56..e8a3a9243534cac1ebd6f15533103f43df038286 100644 (file)
@@ -97,6 +97,7 @@ sub irc {
                Ircname => $param{'ircName'},
     );
     $args{'LocalAddr'} = $param{'ircHost'} if ($param{'ircHost'});
+    $args{'Password'} = $param{'ircPasswd'} if ($param{'ircPasswd'});
 
     $conn = $irc->newconn(%args);
 
@@ -135,12 +136,15 @@ sub irc {
        $conn->add_handler('nick',      \&on_nick);
        $conn->add_handler('quit',      \&on_quit);
        $conn->add_handler('notice',    \&on_notice);
-       $conn->add_handler('whoisuser', \&on_whoisuser);
+       $conn->add_handler('whoischannels', \&on_whoischannels);
+       $conn->add_handler('useronchannel', \&on_useronchannel);
+       $conn->add_handler('whois',     \&on_whois);
        $conn->add_handler('other',     \&on_other);
        $conn->add_global_handler('disconnect', \&on_disconnect);
        $conn->add_global_handler([251,252,253,254,255], \&on_init);
 ###    $conn->add_global_handler([251,252,253,254,255,302], \&on_init);
        $conn->add_global_handler(315, \&on_endofwho);
+       $conn->add_global_handler(422, \&on_endofwho); # nomotd.
        $conn->add_global_handler(324, \&on_modeis);
        $conn->add_global_handler(333, \&on_topicinfo);
        $conn->add_global_handler(352, \&on_who);
@@ -229,6 +233,13 @@ sub msg {
        return;
     }
 
+    if ($msgType =~ /chat/i) {
+       # todo: warn that we're using msg() to do DCC CHAT?
+       &dccsay($nick, $msg);
+       # todo: make dccsay deal with flood protection?
+       return;
+    }
+
     &status(">$nick< $msg");
 
     if (&whatInterface() =~ /IRC/) {
@@ -349,7 +360,7 @@ sub performReply {
        &msg($who, $reply);
     } elsif ($msgType eq 'chat') {
        if (!exists $dcc{'CHAT'}{$who}) {
-           &WARN("pSR: dcc{'CHAT'}{$who} does not exist.");
+           &VERB("pSR: dcc{'CHAT'}{$who} does not exist.",2);
            return;
        }
        $conn->privmsg($dcc{'CHAT'}{$who}, $reply);
@@ -379,17 +390,23 @@ sub performStrictReply {
     } elsif ($msgType eq 'public') {
        &say($reply);
     } elsif ($msgType eq 'chat') {
-       &dccsay(lc $who,$reply);
+       &dccsay(lc $who, $reply);
     } else {
        &ERROR("pSR: msgType invalid? ($msgType).");
     }
 }
 
 sub dccsay {
-    my ($who, $reply) = @_;
+    my($who, $reply) = @_;
+
+    if (!defined $reply or $reply =~ /^\s*$/) {
+       &WARN("dccsay: reply == NULL.");
+       return;
+    }
+
     if (!exists $dcc{'CHAT'}{$who}) {
-       &WARN("pSR: dcc{'CHAT'}{$who} does not exist.");
-       return '';
+       &VERB("pSR: dcc{'CHAT'}{$who} does not exist. (2)",2);
+       return;
     }
 
     &status("=>$who<= $reply");                # dcc chat.
@@ -405,6 +422,7 @@ sub dcc_close {
        my @who = grep /^\Q$who\E$/i, keys %{ $dcc{$type} };
        next unless (scalar @who);
        $who = $who[0];
+       &DEBUG("dcc_close... close $who!");
     }
 }
 
@@ -416,13 +434,14 @@ sub joinchan {
        $chan = lc $1;
     }
 
-    &status("joining $b_blue$chan$ob");
-
+    # hopefully validChan is right.
     if (&validChan($chan)) {
        &status("join: already on $chan");
     } else {
+       &status("joining $b_blue$chan$ob");
        if (!$conn->join($chan)) {
            &DEBUG("joinchan: join failed. trying connect!");
+           &clearIRCVars();
            $conn->connect();
        }
     }
@@ -435,6 +454,11 @@ sub part {
        next if ($chan eq "");
        $chan =~ tr/A-Z/a-z/;   # lowercase.
 
+       if ($chan !~ /^$mask{chan}$/) {
+           &WARN("part: chan is invalid ($chan)");
+           next;
+       }
+
        &status("parting $chan");
        if (!&validChan($chan)) {
            &WARN("part: not on $chan; doing anyway");
@@ -630,7 +654,7 @@ sub joinNextChan {
        my $rate        = sprintf("%.1f", $delta / @c);
        delete $cache{joinTime};
 
-       &DEBUG("time taken to join all chans: $timestr; rate: $rate sec/join");
+       &status("time taken to join all chans: $timestr; rate: $rate sec/join");
     }
 
     # chanserv check: global channels, in case we missed one.
@@ -701,6 +725,11 @@ sub validChan {
     }
 
     if (exists $channels{$chan}) {
+       if ($chan eq "_default") {
+#          &WARN("validC: chan cannot be _default! returning 0!");
+           return 0;
+       }
+
        return 1;
     } else {
        return 0;
@@ -730,7 +759,7 @@ sub clearChanVars {
 }
 
 sub clearIRCVars {
-#    &DEBUG("clearIRCVars() called!");
+    &DEBUG("clearIRCVars() called!");
     undef %channels;
     undef %floodjoin;
 
@@ -776,21 +805,23 @@ sub getJoinChans {
 }
 
 sub closeDCC {
-###    &DEBUG("closeDCC called.");
+#    &DEBUG("closeDCC called.");
 
     foreach $type (keys %dcc) {
        next if ($type ne uc($type));
  
        foreach $nick (keys %{ $dcc{$type} }) {
            next unless (defined $nick);
-           &DEBUG("closing DCC $type to $nick (FIXME).");
+           &status("DCC CHAT: closing DCC $type to $nick.");
            next unless (defined $dcc{$type}{$nick});
 
            my $ref = $dcc{$type}{$nick};
-           &DEBUG("ref => $ref");
-
-#          $dcc{$type}{$nick}->close();
+           &dccsay($nick, "bye bye, $nick") if ($type =~ /^chat$/i);
+           $dcc{$type}{$nick}->close();
+           delete $dcc{$type}{$nick};
+           &DEBUG("after close for $nick");
        }
+       delete $dcc{$type};
     }
 }
 
@@ -829,10 +860,15 @@ sub joinfloodCheck {
 
     ### Clean it up.
     my $delete = 0;
+    my $time = time();
     foreach $chan (keys %floodjoin) {
        foreach $who (keys %{ $floodjoin{$chan} }) {
-           my $time = time() - $floodjoin{$chan}{$who}{Time};
-           next unless ($time > 10);
+           my $t       = $floodjoin{$chan}{$who}{Time};
+           next unless (defined $t);
+
+           my $delta   = $time - $t;
+           next unless ($delta > 10);
+
            delete $floodjoin{$chan}{$who};
            $delete++;
        }
@@ -844,7 +880,12 @@ sub joinfloodCheck {
 sub getHostMask {
     my($n) = @_;
 
-    &FIXME("getHostMask($n) called...");
+    if (exists $nuh{$n}) {
+       return &makeHostMask($nuh{$n});
+    } else {
+       $cache{on_who_Hack} = 1;
+       &rawout("WHO $n");
+    }
 }
 
 1;