]> git.donarmstrong.com Git - infobot.git/commitdiff
global SAR. only avail to +n and DCC.
authordms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Wed, 6 Sep 2000 14:57:40 +0000 (14:57 +0000)
committerdms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Wed, 6 Sep 2000 14:57:40 +0000 (14:57 +0000)
git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@73 c11ca15a-4712-0410-83d8-924469b57eb5

src/Modules/UserDCC.pl

index 8478822fd93f99175d54dfe6a3aced67e556edea..8337c952d09f12377dfb3f7ecfa757a1a902008d 100644 (file)
@@ -339,6 +339,59 @@ sub userDCC {
        exit 0;
     }
 
+    # global factoid substitution.
+    if ($message =~ m|^s([/,#])(.+?)\2(.*?)\2;?\s*$|) {
+       &DEBUG("global factoid subst called!");
+       my ($delim,$op,$np) = ($1, $2, $3);
+       return $noreply unless (&hasFlag("n"));
+
+       # incorrect format.
+       if ($np =~ /$delim/) {
+           &msg($who,"looks like you used the delimiter too many times. You may want to use a different delimiter, like ':' or '#'.");
+           return $noreply;
+       }
+
+       ### TODO: fix up $op to support mysql/pgsql/dbm(perl)
+       ### TODO: => add db/sql specific function to fix this.
+       my @list = &searchTable("factoids", "factoid_key",
+                       "factoid_value", $op);
+
+       if (!scalar @list) {
+           &performStrictReply("Expression didn't match anything.");
+           return $noreply;
+       }
+
+       my $error = 0;
+       foreach (@list) {
+           my $faqtoid = $_;
+
+           next if (&IsLocked($faqtoid) == 1);
+           my $result = &getFactoid($faqtoid);
+           my $was = $result;
+           &DEBUG("was($faqtoid) => '$was'.");
+
+           # global global
+           # we could support global local (once off).
+           if ($result =~ s/\Q$op/$np/gi) {
+               if (length $result > $param{'maxDataSize'}) {
+                   &performReply("that's too long (or was long)");
+                   return $noreply;
+               }
+###            &setFactInfo($faqtoid, "factoid_value", $result);
+               &status("update: '$faqtoid' =is=> '$result'; was '$was'");
+           } else {
+               &WARN("subst: that's weird... thought we found the string ($op) in '$faqtoid'.");
+               $error++;
+           }
+       }
+
+       if ($error) {
+           &ERROR("Something happened...");
+       }
+
+       return $noreply;
+    }
+
     # jump.
     if ($message =~ /^jump(\s+(\S+))?$/i) {
        return $noreply unless (&hasFlag("n"));