]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Factoids/Core.pl
- nice patch from Phil Edwards <pme@devphil.com>. Thanks!
[infobot.git] / src / Factoids / Core.pl
index 41ed537399d9de603c3aabbf2b66a14621eec15c..fde06aa273292ebd14bad902ec70836b703646ff 100644 (file)
@@ -5,7 +5,11 @@
 #   Created: 20010906
 #
 
-if (&IsParam("useStrict")) { use strict; }
+# use strict;  # TODO
+
+use vars qw(%param %cache %lang %cmdstats %bots);
+use vars qw($message $who $addressed $chan $h $nuh $ident $msgType
+       $correction_plausable);
 
 # Usage: &validFactoid($lhs,$rhs);
 sub validFactoid {
@@ -153,10 +157,12 @@ sub FactoidStuff {
 
        my $author      = &getFactInfo($faqtoid, "created_by");
        my $count       = &getFactInfo($faqtoid, "requested_count") || 0;
+       # don't delete if requested $limit times
        my $limit       = &getChanConfDefault(
                                "factoidPreventForgetLimit", 100, $chan);
+       # don't delete if older than $limitage seconds (modified by requests below)
        my $limitage    = &getChanConfDefault(
-                               "factoidPreventForgetLimitTime", 180, $chan);
+                               "factoidPreventForgetLimitTime", 7 * 24 * 60 * 60, $chan);
        my $t           = &getFactInfo($faqtoid, "created_time") || 0;
        my $age         = time() - $t;
 
@@ -166,7 +172,7 @@ sub FactoidStuff {
        my $isau        = (defined $author and &IsHostMatch($author) == 2) ? 1 : 0;
        my $isop        = (&IsFlag("o") eq "o") ? 1 : 0;
 
-       if (IsFlag("r") ne "r") {
+       if (IsFlag("r") ne "r" && !$isop) {
            &msg($who, "you don't have access to remove factoids");
            return;
        }
@@ -179,13 +185,14 @@ sub FactoidStuff {
 
        # factoidPreventForgetLimitTime:
        if (!($isop or $isau) and $age/(60*60*24) > $limitage) {
-           &msg($who, "cannot remove factoid '$faqtoid' since it is protected by Time.");
+           &msg($who, "cannot remove factoid '$faqtoid', too old. (" .
+                   $age/(60*60*24) . ">$limitage) use 'no,' instead");
            return;
        }
 
        # factoidPreventForgetLimit:
        if (!($isop or $isau) and $limit and $count > $limit) {
-           &msg($who, "will not delete '$faqtoid', count > limit ($count > $limit)");
+           &msg($who, "will not delete '$faqtoid', count > limit ($count > $limit) use 'no, ' instead.");
            return;
        }
 
@@ -242,7 +249,7 @@ sub FactoidStuff {
                return;
            }
 
-           &status("forgot (safe delete): '$faqtoid' - ". scalar(localtime));
+           &status("forgot (safe delete): '$faqtoid' - ". scalar(gmtime));
            ### TODO: check if the "backup" exists and overwrite it
            my $check = &getFactoid("$faqtoid #DEL#");
 
@@ -293,7 +300,7 @@ sub FactoidStuff {
 
        my $faqtoid = $message;
        if ($faqtoid eq "") {
-           &help("undelete");
+           &help("unforget");
            return;
        }
 
@@ -370,29 +377,31 @@ sub FactoidStuff {
        }
 
        if ($message =~ /^'(.*)'\s+'(.*)'$/) {
-           my($from,$to) = (lc $1, lc $2);
+           my ($from,$to) = (lc $1, lc $2);
 
            my $result = &getFactoid($from);
            if (defined $result) {
-               my $author = &getFactInfo($from, "created_by");
-
-               if (0 and !&IsFlag("m") or $author !~ /^\Q$who\E\!/i) {
-                   &msg($who, "It's not yours to modify.");
-                   return;
-               }
+               &performReply("i didn't have anything called '$from'");
+               return;
+           }
 
-               if ($_ = &getFactoid($to)) {
-                   &performReply("destination factoid already exists.");
-                   return;
-               }
+           my $author = &getFactInfo($from, "created_by");
 
-               &setFactInfo($from,"factoid_key",$to);
+           # who == nick!user@host.
+           if (&IsFlag("m") ne "m" and $author !~ /^\Q$who\E\!/i) {
+               &msg($who, "factoid '$form' is not yours to modify.");
+               return;
+           }
 
-               &status("rename: <$who> '$from' is now '$to'");
-               &performReply("i renamed '$from' to '$to'");
-           } else {
-               &performReply("i didn't have anything called '$from'");
+           if ($_ = &getFactoid($to)) {
+               &performReply("destination factoid already exists.");
+               return;
            }
+
+           &setFactInfo($from,"factoid_key",$to);
+
+           &status("rename: <$who> '$from' is now '$to'");
+           &performReply("i renamed '$from' to '$to'");
        } else {
            &msg($who,"error: wrong format. ask me about 'help rename'.");
        }
@@ -513,7 +522,7 @@ sub FactoidStuff {
        return;
     }
 
-    return unless ($addressed);
+    return unless ($addressed and !$addrchar);
 
     if (length $message > 64) {
        &status("unparseable-moron: $message");