]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Factoids/Update.pl
- strictify
[infobot.git] / src / Factoids / Update.pl
index 79abd84c1d9a3e2c0b70f0050dac60338d6e3951..885538280735b9268d4fbc4f890cd21d37bfe8da 100644 (file)
@@ -6,7 +6,7 @@
 #   Created: 1997
 #
 
-if (&IsParam("useStrict")) { use strict; }
+# use strict;  # TODO
 
 sub update {
     my($lhs, $mhs, $rhs) = @_;
@@ -27,7 +27,7 @@ sub update {
     }
 
     # teaching.
-    if (&IsFlag("t") ne "t") {
+    if (&IsFlag("t") ne "t" && &IsFlag("o") ne "o") {
        &msg($who, "permission denied.");
        &status("alert: $who wanted to teach me.");
        return 1;
@@ -54,13 +54,43 @@ sub update {
 
     # freshmeat
     if (&IsChanConf("freshmeatForFactoid")) {
-       if (&dbGet("freshmeat", "name", $lhs, "name")) {
+       # todo: "name" is invalid for fm ][
+       if ( &dbGet("freshmeat", "name", "name=".&dbQuote($lhs)) ) {
            &msg($who, "permission denied. (freshmeat)");
            &status("alert: $who wanted to teach me something that freshmeat already has info on.");
            return 1;
        }
     }
 
+    # factoid arguments handler.
+    if (&IsChanConf("factoidArguments") and $lhs =~ /\$/) {
+       &status("Update: Factoid Arguments found.");
+       &status("Update: orig lhs => '$lhs'.");
+       &status("Update: orig rhs => '$rhs'.");
+
+       my @list;
+       my $count = 0;
+       $lhs =~ s/^/CMD: /;
+       while ($lhs =~ s/\$(\S+)/(.*?)/) {
+           push(@list, "\$$1");
+           $count++;
+           last if ($count >= 10);
+       }
+
+       if ($count >= 10) {
+           &msg($who, "error: could not SAR properly.");
+           &DEBUG("error: lhs => '$lhs'.");
+           &DEBUG("error: rhs => '$rhs'.");
+           return;
+       }
+
+       my $z = join(',',@list);
+       $rhs =~ s/^/($z): /;
+
+       &status("Update: new  lhs => '$lhs'.");
+       &status("Update: new  rhs => '$rhs'.");
+    }
+
     # the fun begins.
     my $exists = &getFactoid($lhs);
 
@@ -77,9 +107,12 @@ sub update {
 
        &performAddressedReply("okay");
 
-       &setFactInfo($lhs,"created_by", $nuh);
-       &setFactInfo($lhs,"created_time", time());
-       &setFactInfo($lhs,"factoid_value", $rhs);
+       &dbReplace("factoids", "factoid_key", (
+               created_by      => $nuh,
+               created_time    => time(),      # modified time.
+               factoid_key     => $lhs,
+               factoid_value   => $rhs,
+       ) );
 
        if (!defined $rhs or $rhs eq "") {
            &ERROR("Update: rhs1 == NULL.");
@@ -90,13 +123,16 @@ sub update {
 
     # factoid exists.
     if ($exists eq $rhs) {
+       # this catches the following situation: (right or wrong?)
+       #    "test is test"
+       #    "test is also test"
        &performAddressedReply("i already had it that way");
        return 1;
     }
 
     if ($also) {                       # 'is also'.
        if ($exists =~ /^<REPLY> see /i) {
-           &DEBUG("todo: append to linked factoid.");
+           &DEBUG("Update.pl: todo: append to linked factoid.");
        }
 
        if ($also_or) {                 # 'is also ||'.
@@ -166,12 +202,14 @@ sub update {
                &performStrictReply("...but \002$lhs\002 is already something else...");
                &status("FAILED update: <$who> \'$lhs\' =$mhs=> \'$rhs\'");
            }
-           return;
+           return 1;
        }
 
        my $author = &getFactInfo($lhs, "created_by") || "";
 
-       if (IsFlag("m") ne "m" and $author !~ /^\Q$who\E\!/i) {
+       if (IsFlag("m") ne "m" && IsFlag("o") ne "o" &&
+           $author !~ /^\Q$who\E\!/i
+       ) {
            &msg($who, "you can't change that factoid.");
            return 1;
        }
@@ -181,9 +219,10 @@ sub update {
        $count{'Update'}++;
        &status("update: <$who> \'$lhs\' =$mhs=> \'$rhs\'; was \'$exists\'");
 
-       &delFactoid($lhs);
-       &setFactInfo($lhs,"created_by", $nuh);
-       &setFactInfo($lhs,"created_time", time());
+       # should dbReplace be used here?
+       #&delFactoid($lhs); # breaks dbm. leave it and use modified_* - Tim Riker <Tim@Rikers.org>
+       &setFactInfo($lhs,"modified_by", $nuh);
+       &setFactInfo($lhs,"modified_time", time());
        &setFactInfo($lhs,"factoid_value", $rhs);
 
        if (!defined $rhs or $rhs eq "") {