]> git.donarmstrong.com Git - infobot.git/blobdiff - src/IRC/IrcHelpers.pl
Fixed bug in "+sed" by enforcing limit on output when using s///g
[infobot.git] / src / IRC / IrcHelpers.pl
index e620b2202bfa8e85d1e152abd5b2c56d3bd47e1d..cc53742069fc4fe2ec826c6f7a0c30f46a971a1a 100644 (file)
@@ -91,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;
            }
@@ -134,7 +141,7 @@ sub hookMsg {
     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) {
@@ -176,7 +183,7 @@ sub hookMsg {
        }
 
        $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.
@@ -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,7 +252,7 @@ sub hookMsg {
        $seencache{$who}{'msg'}  = $orig{message};
        $seencache{$who}{'msgcount'}++;
     }
-    if (&IsChanConf("minVolunteerLength")) {
+    if (&IsChanConf("minVolunteerLength") > 0) {
        # FIXME hack to treat unaddressed as if using addrchar
        $addrchar = 1;
     }
@@ -287,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.");
@@ -342,7 +360,7 @@ sub chanServCheck {
        &DEBUG("chanServCheck: lowercased chan ($chan)");
     }
 
-    if (! &IsChanConf("chanServ_ops") ) {
+    if (! &IsChanConf("chanServ_ops") > 0) {
        return 0;
     }