]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Factoids/Core.pl
- make ignoreAdd a little more verbose.
[infobot.git] / src / Factoids / Core.pl
index ec0addb8f1b97d10b3891caa19c9bb9e3b2406af..067e49428e3c8d399f71737093c265c6c6d99d78 100644 (file)
@@ -148,11 +148,11 @@ sub FactoidStuff {
        if (defined $result) {
            my $author  = &getFactInfo($faqtoid, "created_by");
            my $count   = &getFactInfo($faqtoid, "requested_count") || 0;
-           my $limit   = &getChanConfDefault("factoidPreventForgetLimit", 
-                               0, $chan);
-
-           &DEBUG("forget: limit = $limit");
-           &DEBUG("forget: count = $count");
+           my $limit   = &getChanConfDefault(
+                               "factoidPreventForgetLimit", 100, $chan);
+           my $limitage = &getChanConfDefault(
+                               "factoidPreventForgetLimitTime", 180, $chan);
+           my $age     = time() - &getFactInfo($faqtoid, "created_time");
 
            if (IsFlag("r") ne "r") {
                &msg($who, "you don't have access to remove factoids");
@@ -160,20 +160,77 @@ sub FactoidStuff {
            }
 
            return 'locked factoid' if (&IsLocked($faqtoid) == 1);
+           my $isop = (&IsFlag("o") eq "o") ? 1 : 0;
+
+           ### lets go do some checking.
+
+           # factoidPreventForgetLimitTime:
+           if (!$isop and $age/(60*60*24) > $limitage) {
+               &msg($who, "cannot remove factoid since it is protected by Time.");
+               return;
+           }
 
            # factoidPreventForgetLimit:
-           if ($limit and $count > $limit and (&IsFlag("o") ne "o")) {
+           if (!$isop and $limit and $count > $limit) {
                &msg($who, "will not delete '$faqtoid', count > limit ($count > $limit)");
                return;
            }
 
+           # this may eat some memory.
+           # prevent deletion if other factoids redirect to it.
+           # todo: use hash instead of array.
+           my @list;
+           if (&getChanConf("factoidPreventForgetRedirect")) {
+               &status("Factoids/Core: forget: checking for redirect factoids");
+               @list = &searchTable("factoids", "factoid_key",
+                               "factoid_value", "^<REPLY> see ");
+           }
+
+           my $match = 0;
+           for (@list) {
+               my $f = $_;
+               my $v = &getFactInfo($f, "factoid_value");
+               my $fsafe = quotemeta($faqtoid);
+               next unless ($v =~ /^<REPLY> ?see( also)? $fsafe\.?$/i);
+
+               &DEBUG("Factoids/Core: match! ($f || $faqtoid)");
+
+               $match++;
+           }
+           # todo: warn for op aswell, but allow force delete.
+           if (!$isop and $match) {
+               &msg($who, "uhm, other (redirection) factoids depend on this one.");
+               return;
+           }
+
+           # minimize abuse.
+           my $faqauth = &getFactInfo($faqtoid, "created_by");
+           if (!$isop and &IsHostMatch($faqauth) != 2) {
+               $cache{forget}{$h}++;
+
+               # warn.
+               if ($cache{forget}{$h} > 3) {
+                   &msg($who, "Stop abusing forget!");
+               }
+
+               # ignore.
+               # todo: make forget limit configurable.
+               # todo: make forget ignore time configurable.
+               if ($cache{forget}{$h} > 5) {
+                   &ignoreAdd(&makeHostMask($nuh), "*", 3*24*60*60, "abuse of forget");
+                   &msg($who, "forget: Suck it!");
+               }
+           }
+
+           # lets do it!
+
            if (&IsParam("factoidDeleteDelay") or &IsChanConf("factoidDeleteDelay")) {
-               if ($faqtoid =~ / #DEL#$/ and !&IsFlag("o")) {
+               if (!$isop and $faqtoid =~ / #DEL#$/) {
                    &msg($who, "cannot delete it ($faqtoid).");
                    return;
                }
 
-               &status("forgot (safe delete): <$who> '$faqtoid' =is=> '$result'");
+               &status("forgot (safe delete): '$faqtoid' - ". scalar(localtime));
                ### TODO: check if the "backup" exists and overwrite it
                my $check = &getFactoid("$faqtoid #DEL#");
 
@@ -181,8 +238,7 @@ sub FactoidStuff {
                    if ($faqtoid !~ / #DEL#$/) {
                        my $new = $faqtoid." #DEL#";
 
-                       my $backup = &getFactoid($faqtoid);
-                       # this looks weird but does it work?
+                       my $backup = &getFactoid($new);
                        if ($backup) {
                            &DEBUG("forget: not overwriting backup: $faqtoid");
                        } else {
@@ -199,15 +255,15 @@ sub FactoidStuff {
                } else {
                    &status("forget: not overwriting backup!");
                }
-
-           } else {
-               &status("forget: <$who> '$faqtoid' =is=> '$result'");
            }
+
+           &status("forget: <$who> '$faqtoid' =is=> '$result'");
            &delFactoid($faqtoid);
 
            &performReply("i forgot $faqtoid");
 
            $count{'Update'}++;
+
        } else {
            &performReply("i didn't have anything called '$faqtoid'");
        }
@@ -238,12 +294,12 @@ sub FactoidStuff {
        my $check  = &getFactoid($faqtoid);
 
        if (!defined $result) {
-           &performReply("i didn't have anything ('$faqtoid') to undelete.");
+           &performReply("that factoid was not backedup :/");
            return;
        }
 
        if (defined $check) {
-           &performReply("cannot undeleted '$faqtoid' because it already exists?");
+           &performReply("cannot undeleted '$faqtoid' because it already exists!");
            return;
        }
 
@@ -350,10 +406,20 @@ sub FactoidStuff {
            my $was = $result;
 
            if (($flags eq "g" && $result =~ s/\Q$op/$np/gi) || $result =~ s/\Q$op/$np/i) {
+               # excessive length.
                if (length $result > $param{'maxDataSize'}) {
                    &performReply("that's too long");
                    return;
                }
+               # min length.
+               my $faqauth = &getFactInfo($faqtoid, "created_by");
+               if ((length $result)*2 < length $was and
+                       &IsFlag("o") ne "o" and
+                       &IsHostMask($faqauth) != 2
+               ) {
+                   &performReply("too drastic change of factoid.");
+               }
+
                &setFactInfo($faqtoid, "factoid_value", $result);
                &status("update: '$faqtoid' =is=> '$result'; was '$was'");
                &performReply("OK");