]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Factoids/Core.pl
more babelfish cleanup
[infobot.git] / src / Factoids / Core.pl
index 41ed537399d9de603c3aabbf2b66a14621eec15c..6c647309e06e49f8cc5e3d80a2b0a6ed2d1c124c 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 {
@@ -33,7 +37,6 @@ sub validFactoid {
        /^learn / and last;             # teach. damn morons.
        /^tell (\S+) about / and last;  # tell.
        /\=\~/ and last;                # substituition.
-       /^\S+ to \S+ \S+/ and last;     # babelfish.
 
        /^\=/ and last;                 # botnick = heh is.
        /wants you to know/ and last;
@@ -143,20 +146,24 @@ sub FactoidStuff {
        }
 
        $faqtoid =~ tr/A-Z/a-z/;
+       $faqtoid =~ s/^cmd:/CMD:/; # basic command forgetting
        my $result = &getFactoid($faqtoid);
 
        # if it doesn't exist, well... it doesn't!
        if (!defined $result) {
-           &performReply("i didn't have anything called '$faqtoid'");
+           &performReply("i didn't have anything called '$faqtoid' to forget");
            return;
        }
 
+       # TODO: squeeze 3 getFactInfo calls into one?
        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 +173,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,19 +186,20 @@ 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;
        }
 
        # this may eat some memory.
        # prevent deletion if other factoids redirect to it.
-       # todo: use hash instead of array.
+       # TODO: use hash instead of array.
        my @list;
        if (&getChanConf("factoidPreventForgetRedirect")) {
            &status("Factoids/Core: forget: checking for redirect factoids");
@@ -210,7 +218,7 @@ sub FactoidStuff {
 
            $match++;
        }
-       # todo: warn for op aswell, but allow force delete.
+       # TODO: warn for op aswell, but allow force delete.
        if (!$isop and $match) {
            &msg($who, "uhm, other (redirection) factoids depend on this one.");
            return;
@@ -226,11 +234,11 @@ sub FactoidStuff {
            }
 
            # ignore.
-           # todo: make forget limit configurable.
-           # todo: make forget ignore time configurable.
+           # 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!");
+               &ignoreAdd(&makeHostMask($nuh), "*", 3*24*60, "abuse of forget");
+               &msg($who, "forget: Ignoring you for abuse!");
            }
        }
 
@@ -242,7 +250,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,11 +301,12 @@ sub FactoidStuff {
 
        my $faqtoid = $message;
        if ($faqtoid eq "") {
-           &help("undelete");
+           &help("unforget");
            return;
        }
 
        $faqtoid =~ tr/A-Z/a-z/;
+       $faqtoid =~ s/^cmd:/CMD:/; # basic command undeleteing
        my $result = &getFactoid($faqtoid." #DEL#");
        my $check  = &getFactoid($faqtoid);
 
@@ -316,7 +325,7 @@ sub FactoidStuff {
 #      &setFactInfo($faqtoid, "modified_time", 0);
 
        $check  = &getFactoid($faqtoid);
-       # todo: check if $faqtoid." #DEL#" exists?
+       # TODO: check if $faqtoid." #DEL#" exists?
        if (defined $check) {
            &performReply("Successfully recovered '$faqtoid'.  Have fun now.");
            $count{'Undelete'}++;
@@ -370,29 +379,29 @@ 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 (!defined $result) {
+               &performReply("i didn't have anything called '$from' to rename");
+               return;
+           }
 
-               if (0 and !&IsFlag("m") or $author !~ /^\Q$who\E\!/i) {
-                   &msg($who, "It's not yours to modify.");
-                   return;
-               }
+           # who == nick!user@host.
+           if (&IsFlag("m") ne "m" and $author !~ /^\Q$who\E\!/i) {
+               &msg($who, "factoid '$from' is not yours to modify.");
+               return;
+           }
 
-               if ($_ = &getFactoid($to)) {
-                   &performReply("destination factoid already exists.");
-                   return;
-               }
+           if ($_ = &getFactoid($to)) {
+               &performReply("destination factoid already exists.");
+               return;
+           }
 
-               &setFactInfo($from,"factoid_key",$to);
+           &setFactInfo($from,"factoid_key",$to);
 
-               &status("rename: <$who> '$from' is now '$to'");
-               &performReply("i renamed '$from' to '$to'");
-           } else {
-               &performReply("i didn't have anything called '$from'");
-           }
+           &status("rename: <$who> '$from' is now '$to'");
+           &performReply("i renamed '$from' to '$to'");
        } else {
            &msg($who,"error: wrong format. ask me about 'help rename'.");
        }
@@ -438,7 +447,7 @@ sub FactoidStuff {
                &performReply("that doesn't contain '$op'");
            }
        } else {
-           &performReply("i didn't have anything called '$faqtoid'");
+           &performReply("i didn't have anything called '$faqtoid' to modify");
        }
 
        return;
@@ -513,7 +522,7 @@ sub FactoidStuff {
        return;
     }
 
-    return unless ($addressed);
+    return unless ($addressed and !$addrchar);
 
     if (length $message > 64) {
        &status("unparseable-moron: $message");