]> git.donarmstrong.com Git - infobot.git/blobdiff - src/IRC/IrcHelpers.pl
take a few more things literally
[infobot.git] / src / IRC / IrcHelpers.pl
index 7c8b7725aefc452f4464332b31f5cc63e5293565..e45b4b7b1d4638a4918940685868eb02f519d727 100644 (file)
@@ -34,11 +34,11 @@ sub hookMode {
            my $target = shift @targets;
 
            if ($parity) {
-               $chanstats{$chan}{'Op'}++    if ($mode eq "o");
-               $chanstats{$chan}{'Ban'}++   if ($mode eq "b");
+               $chanstats{$chan}{'Op'}++    if ($mode eq 'o');
+               $chanstats{$chan}{'Ban'}++   if ($mode eq 'b');
            } else {
-               $chanstats{$chan}{'Deop'}++  if ($mode eq "o");
-               $chanstats{$chan}{'Unban'}++ if ($mode eq "b");
+               $chanstats{$chan}{'Deop'}++  if ($mode eq 'o');
+               $chanstats{$chan}{'Unban'}++ if ($mode eq 'b');
            }
 
            # modes w/ target affecting nick => cache it.
@@ -47,8 +47,8 @@ sub hookMode {
                delete $channels{$chan}{$mode}{$target} if !$parity;
 
                # lets do some custom stuff.
-               if ($mode eq "o" and $parity) {
-                   if ($nick eq "ChanServ" and $target =~ /^\Q$ident\E$/i) {
+               if ($mode eq 'o' and $parity) {
+                   if ($nick eq 'ChanServ' and $target =~ /^\Q$ident\E$/i) {
                        &VERB("hookmode: chanserv deopped us! asking",2);
                        &chanServCheck($chan);
                    }
@@ -83,6 +83,7 @@ sub hookMsg {
     $message   =~ s/[\cA-\c_]//ig;     # strip control characters
     $message   =~ s/^\s+//;            # initial whitespaces.
     $who       =~ tr/A-Z/a-z/;         # lowercase.
+    my $mynick = $conn->nick();
 
     &showProc();
 
@@ -90,12 +91,19 @@ sub hookMsg {
     if ($msgType =~ /private/) {
        # private messages.
        $addressed = 1;
+       if (&IsChanConf('addressCharacter') > 0) {
+           $addressCharacter = getChanConf('addressCharacter');
+           if ($message =~ s/^\Q$addressCharacter\E//) {
+               &msg($who, "The addressCharacter \"$addressCharacter\" is to get my attention in a normal channel. Please leave it off when messaging me directly.");
+           }
+       }
     } else {
        # public messages.
        # addressing revamped by the xk.
        ### below needs to be fixed...
-       if (&IsParam("addressCharacter")) {
-           if ($message =~ s/^\Q$param{'addressCharacter'}\E//) {
+       if (&IsChanConf('addressCharacter') > 0) {
+           $addressCharacter = getChanConf('addressCharacter');
+           if ($message =~ s/^\Q$addressCharacter\E//) {
                $addrchar  = 1;
                $addressed = 1;
            }
@@ -103,19 +111,18 @@ sub hookMsg {
 
        if ($message =~ /^($mask{nick})([\;\:\>\, ]+) */) {
            my $newmessage = $';
-           my $mynick = $conn->nick();
            if ($1 =~ /^\Q$mynick\E$/i) {
                $message   = $newmessage;
                $addressed = 1;
            } else {
                # ignore messages addressed to other people or unaddressed.
-               $skipmessage++ if ($2 ne "" and $2 !~ /^ /);
+               $skipmessage++ if ($2 ne '' and $2 !~ /^ /);
            }
        }
     }
 
     # Determine floodwho.
-    my $c      = "_default";
+    my $c      = '_default';
     if ($msgType =~ /public/i) {
        # public.
        $floodwho = $c = lc $chan;
@@ -127,14 +134,14 @@ sub hookMsg {
        &FIXME("floodwho = ???");
     }
 
-    my $val = &getChanConfDefault("floodRepeat", "2:5", $c);
+    my $val = &getChanConfDefault('floodRepeat', "2:5", $c);
     my ($count, $interval) = split /:/, $val;
 
     # flood repeat protection.
     if ($addressed) {
        my $time = $flood{$floodwho}{$message} || 0;
 
-       if ($msgType eq "public" and (time() - $time < $interval)) {
+       if (!&IsFlag('o') and $msgType eq 'public' and (time() - $time < $interval)) {
            ### public != personal who so the below is kind of pointless.
            my @who;
            foreach (keys %flood) {
@@ -147,7 +154,7 @@ sub hookMsg {
            return if ($lobotomized);
 
            if (!scalar @who) {
-               push(@who,"Someone");
+               push(@who,'Someone');
            }
            &msg($who,join(' ', @who)." already said that ". (time - $time) ." seconds ago" );
 
@@ -168,15 +175,15 @@ sub hookMsg {
        }
 
        if ($addrchar) {
-           &status("$b_cyan$who$ob is short-addressing me");
-       } elsif ($msgType eq "private") {       # private.
-           &status("$b_cyan$who$ob is /msg'ing me");
+           &status("$b_cyan$who$ob is short-addressing $mynick");
+       } elsif ($msgType eq 'private') {       # private.
+           &status("$b_cyan$who$ob is /msg'ing $mynick");
        } else {                                # public?
-           &status("$b_cyan$who$ob is addressing me");
+           &status("$b_cyan$who$ob is addressing $mynick");
        }
 
        $flood{$floodwho}{$message} = time();
-    } elsif ($msgType eq "public" and &IsChanConf("kickOnRepeat")) {
+    } elsif ($msgType eq 'public' and &IsChanConf('kickOnRepeat') > 0) {
        # unaddressed, public only.
 
        ### TODO: use a separate "short-time" hash.
@@ -184,7 +191,7 @@ sub hookMsg {
        @data   = keys %{ $flood{$floodwho} } if (exists $flood{$floodwho});
     }
 
-    $val = &getChanConfDefault("floodMessages", "5:30", $c);
+    $val = &getChanConfDefault('floodMessages', "5:30", $c);
     ($count, $interval) = split /:/, $val;
 
     # flood overflow protection.
@@ -217,16 +224,27 @@ sub hookMsg {
     } elsif ($msgType =~ /private/i) {            # private.
        &status("[$orig{who}] $orig{message}");
        $talkchannel    = undef;
-       $chan           = "_default";
+       $chan           = '_default';
     } else {
        &DEBUG("unknown msgType => $msgType.");
     }
-    push(@ignore, keys %{ $ignore{"*"} }) if (exists $ignore{"*"});
-
-    if ((!$skipmessage or &IsChanConf("seenStoreAll") > 0) and
-       &IsChanConf("seen") > 0 and
-       $msgType =~ /public/
-    ) {
+    push(@ignore, keys %{ $ignore{'*'} }) if (exists $ignore{'*'});
+
+    if ((!$skipmessage or &IsChanConf('seenStoreAll') > 0) and
+           &IsChanConf('sed') > 0 and &IsChanConf('seen') > 0 and
+           $msgType =~ /public/ and
+            $orig{message} =~ /^s\/([^;\/]*)\/([^;\/]*)\/([g]*)$/) {
+       my $sedmsg = $seencache{$who}{'msg'};
+       eval "\$sedmsg =~ s/\Q$1\E/\Q$2\E/$3;";
+       $sedmsg =~ s/^(.{255}).*$/$1.../; # 255 char max to prevent flood
+
+       if ($sedmsg ne $seencache{$who}{'msg'}) {
+           &DEBUG("sed \"" . $orig{message} . "\" \"" .
+                   $seencache{$who}{'msg'} . "\" \"" . $sedmsg. "\"");
+           &msg($talkchannel, "$orig{who} meant: $sedmsg");
+       }
+    } elsif ((!$skipmessage or &IsChanConf('seenStoreAll') > 0) and
+           &IsChanConf('seen') > 0 and $msgType =~ /public/) {
        $seencache{$who}{'time'} = time();
        $seencache{$who}{'nick'} = $orig{who};
        $seencache{$who}{'host'} = $uh;
@@ -234,9 +252,12 @@ sub hookMsg {
        $seencache{$who}{'msg'}  = $orig{message};
        $seencache{$who}{'msgcount'}++;
     }
-
+    if (&IsChanConf('minVolunteerLength') > 0) {
+       # FIXME hack to treat unaddressed as if using addrchar
+       $addrchar = 1;
+    }
     return if ($skipmessage);
-    return unless (&IsParam("minVolunteerLength") or $addressed);
+    return unless ($addrchar or $addressed);
 
     foreach (@ignore) {
        s/\*/\\S*/g;
@@ -284,7 +305,7 @@ sub chanLimitVerify {
     $chan      = $c;
     my $l      = $channels{$chan}{'l'};
 
-    return unless (&IsChanConf("chanlimitcheck"));
+    return unless (&IsChanConf('chanlimitcheck') > 0);
 
     if (scalar keys %netsplit) {
        &WARN("clV: netsplit active (1, chan = $chan); skipping.");
@@ -298,9 +319,9 @@ sub chanLimitVerify {
     }
 
     # only change it if it's not set.
-    my $plus  = &getChanConfDefault("chanlimitcheckPlus", 5, $chan);
+    my $plus  = &getChanConfDefault('chanlimitcheckPlus', 5, $chan);
     my $count = scalar(keys %{ $channels{$chan}{''} });
-    my $int   = &getChanConfDefault("chanlimitcheckInterval", 10, $chan);
+    my $int   = &getChanConfDefault('chanlimitcheckInterval', 10, $chan);
 
     my $delta = $count + $plus - $l;
 #   $delta    =~ s/^\-//;
@@ -339,14 +360,14 @@ sub chanServCheck {
        &DEBUG("chanServCheck: lowercased chan ($chan)");
     }
 
-    if (! &IsChanConf("chanServ_ops") ) {
+    if (! &IsChanConf('chanServ_ops') > 0) {
        return 0;
     }
 
     &VERB("chanServCheck($chan) called.",2);
 
-    if ( &IsParam("nickServ_pass") and !$nickserv) {
-       $conn->who("NickServ");
+    if ( &IsParam('nickServ_pass') and !$nickserv) {
+       $conn->who('NickServ');
        return 0;
     }