]> git.donarmstrong.com Git - infobot.git/blobdiff - src/IRC/Irc.pl
ignore case on autojoin
[infobot.git] / src / IRC / Irc.pl
index d359f303fe3a02e93baa4b5588a17317cccdcdb7..7eecd58ac8f43eeb89b972e60e1c5849bc5fcb70 100644 (file)
@@ -6,17 +6,22 @@
 #
 
 use strict;
+
 no strict 'refs';
+no strict 'subs'; # IN/STDIN
 
 use vars qw(%floodjoin %nuh %dcc %cache %conns %channels %param %mask
        %chanconf %orig %ircPort %ircstats %last %netsplit);
 use vars qw($irc $nickserv $conn $msgType $who $talkchannel
-       $addressed);
+       $addressed $postprocess);
 use vars qw($notcount $nottime $notsize $msgcount $msgtime $msgsize
                $pubcount $pubtime $pubsize);
 use vars qw($b_blue $ob);
 use vars qw(@ircServers);
 
+#use open ':utf8';
+#use open ':std';
+
 $nickserv      = 0;
 my $maxlinelen = 400;
 
@@ -170,6 +175,12 @@ sub irc {
 
     $ircstats{'Server'}        = "$server:$port";
 
+    # works? needs to actually do something
+    # should likely listen on a tcp port instead
+    #$irc->addfh(STDIN, \&on_stdin, "r");
+
+    &status("starting main loop");
+
     $irc->start;
 }
 
@@ -201,34 +212,44 @@ sub say {
        return;
     }
 
+    if ( $postprocess ) {
+       undef $postprocess;
+    } elsif ($postprocess = &getChanConf('postprocess', $talkchannel)) {
+       &DEBUG("say: $postprocess $msg");
+       &parseCmdHook($postprocess . ' ' . $msg);
+       undef $postprocess;
+       return;
+    }
 
     &status("<$mynick/$talkchannel> $msg");
-    if (&whatInterface() =~ /IRC/) {
-       $msg    = "zero" if ($msg =~ /^0+$/);
-       my $t   = time();
-
-       if ($t == $pubtime) {
-           $pubcount++;
-           $pubsize += length $msg;
-
-           my $i = &getChanConfDefault("sendPublicLimitLines", 3);
-           my $j = &getChanConfDefault("sendPublicLimitBytes", 1000);
-
-           if ( ($pubcount % $i) == 0 and $pubcount) {
-               sleep 1;
-           } elsif ($pubsize > $j) {
-               sleep 1;
-               $pubsize -= $j;
-           }
 
-       } else {
-           $pubcount   = 0;
-           $pubtime    = $t;
-           $pubsize    = length $msg;
+    return unless (&whatInterface() =~ /IRC/);
+
+    $msg = "zero" if ($msg =~ /^0+$/);
+
+    my $t = time();
+
+    if ($t == $pubtime) {
+       $pubcount++;
+       $pubsize += length $msg;
+
+       my $i = &getChanConfDefault("sendPublicLimitLines", 3, $chan);
+       my $j = &getChanConfDefault("sendPublicLimitBytes", 1000, $chan);
+
+       if ( ($pubcount % $i) == 0 and $pubcount) {
+           sleep 1;
+       } elsif ($pubsize > $j) {
+           sleep 1;
+           $pubsize -= $j;
        }
 
-       $conn->privmsg($talkchannel, $msg);
+    } else {
+       $pubcount       = 0;
+       $pubtime        = $t;
+       $pubsize        = length $msg;
     }
+
+    $conn->privmsg($talkchannel, $msg);
 }
 
 sub msg {
@@ -253,8 +274,8 @@ sub msg {
        $msgcount++;
        $msgsize += length $msg;
 
-       my $i = &getChanConfDefault("sendPrivateLimitLines", 3);
-       my $j = &getChanConfDefault("sendPrivateLimitBytes", 1000);
+       my $i = &getChanConfDefault("sendPrivateLimitLines", 3, $chan);
+       my $j = &getChanConfDefault("sendPrivateLimitBytes", 1000, $chan);
        if ( ($msgcount % $i) == 0 and $msgcount) {
            sleep 1;
        } elsif ($msgsize > $j) {
@@ -305,8 +326,8 @@ sub notice {
        $notcount++;
        $notsize += length $txt;
 
-       my $i = &getChanConfDefault("sendNoticeLimitLines", 3);
-       my $j = &getChanConfDefault("sendNoticeLimitBytes", 1000);
+       my $i = &getChanConfDefault("sendNoticeLimitLines", 3, $chan);
+       my $j = &getChanConfDefault("sendNoticeLimitBytes", 1000, $chan);
 
        if ( ($notcount % $i) == 0 and $notcount) {
            sleep 1;
@@ -388,10 +409,6 @@ sub performAddressedReply {
     &performReply(@_);
 }
 
-sub pSReply {
-    &performStrictReply(@_);
-}
-
 # Usage: &performStrictReply($reply);
 sub performStrictReply {
     my ($reply) = @_;
@@ -445,8 +462,9 @@ sub dcc_close {
 }
 
 sub joinchan {
-    my ($chan) = @_;
-    my $key    = &getChanConf("chankey", $chan) || "";
+    my ($chan, $key) = @_;
+    $key ||= &getChanConf("chankey", $chan);
+    $key ||= "";
 
     # forgot for about 2 years to implement channel keys when moving
     # over to Net::IRC...
@@ -456,10 +474,10 @@ sub joinchan {
        &status("join: already on $chan?");
     }
     #} else {
-       &status("joining $b_blue$chan$ob");
+       &status("joining $b_blue$chan $key$ob");
 
        return if ($conn->join($chan, $key));
-       return if (&validChan($chan));
+       return if (&validChan($chan));
 
        &DEBUG("joinchan: join failed. trying connect!");
        &clearIRCVars();
@@ -822,10 +840,10 @@ sub getJoinChans {
            $skip++ if ($val eq "0");
            if ($val eq "1") {
                # convert old +autojoin to autojoin <nick>
-               $val = $nick;
+               $val = lc $nick;
                $chanconf{$_}{autojoin} = $val;
            }
-           $skip++ if ($val ne $nick);
+           $skip++ if (lc $val ne lc $nick);
        } else {
            $skip++;
        }
@@ -842,8 +860,8 @@ sub getJoinChans {
     }
 
     my $str;
-    $str .= ' in:' . join(',', sort @in) if scalar @in;
-    $str .= ' skip:' . join(',', sort @skip) if scalar @skip;
+    #$str .= ' in:' . join(',', sort @in) if scalar @in;
+    #$str .= ' skip:' . join(',', sort @skip) if scalar @skip;
     $str .= ' join:' . join(',', sort @join) if scalar @join;
 
     &status("Chans: ($nick)$str") if ($show);