]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Factoids/Question.pl
- woops. forgot to check +o aswell.
[infobot.git] / src / Factoids / Question.pl
index e61b30fa8fc51d84aa9fa571bb5f3b9414e98baa..c51ec75b90c51019dbe1434c0e4261769089aaff 100644 (file)
@@ -38,6 +38,13 @@ sub doQuestion {
     } else {
        ### TODO: this should be caught in Process.pl?
        return '' unless ($talkok);
+
+       # there is no flag to disable/enable asking factoids...
+       # so it was added... thanks zyxep! :)
+       if (&IsFlag("a") ne "a" && &IsFlag("o") ne "o") {
+           &status("$who tried to ask us when not allowed.");
+           return;
+       }
     }
 
     # dangerous; common preambles should be stripped before here
@@ -87,6 +94,7 @@ sub doQuestion {
 
     if (&IsChanConf("factoidArguments")) {
        $result = &factoidArgs($query[0]);
+
        return $result if (defined $result);
     }
 
@@ -169,7 +177,7 @@ sub factoidArgs {
     # which will make it less than linear => quicker!
     # todo: cache this, update cache when altered. !!! !!! !!!
 #    my $t = &timeget();
-    my @list = &searchTable("factoids", "factoid_key", "factoid_key", "CMD: ");
+    my @list = &searchTable("factoids", "factoid_key", "factoid_key", "^CMD: ");
 #    my $delta_time = &timedelta($t);
 #    &DEBUG("factArgs: delta_time = $delta_time s");
 #    &DEBUG("factArgs: list => ".scalar(@list) );
@@ -183,23 +191,18 @@ sub factoidArgs {
 
        s/^CMD: //i;
 #      &DEBUG("factarg: ''$str' =~ /^$_\$/'");
-       my @vals;
        my $arg = $_;
 
-       # todo: make eval work with $$i's :(
-       # fuck this is an ugly hack. it works though.
-       eval {
-           if ($str =~ /^$arg$/i) {
-               for ($i=1; $i<=5; $i++) {
-                   $val = $$i;
-                   last unless (defined $val);
+       # todo: <greycat> ~punish apt for (Eating) (Parentheses)
+       # how the hell do I fix the above? -dms.
 
-                   push(@vals, $val);
-               }
-           }
+       # eval (evil!) code. cleaned up courtesy of lear.
+       my @vals;
+       eval {
+           @vals = ($str =~ /^$arg$/i);
        };
 
-       if ($@) {   # it failed!!!
+       if ($@) {
            &WARN("factargs: regex failed! '$str' =~ /^$_\$/");
            next;
        }
@@ -216,12 +219,21 @@ sub factoidArgs {
        &status("Question: factoid Arguments for '$str'");
        # todo: use getReply() - need to modify it :(
        my $i   = 0;
-       my $r   = &getFactoid("CMD: $_");
+       my $q   = "CMD: $_";
+       my $r   = &getFactoid($q);
        if (!defined $r) {
            &DEBUG("question: !result... should this happen?");
            return;
        }
 
+       # update stats.
+       my $count = &getFactInfo($q, "requested_count") || 0;
+       $count++;
+       &setFactInfo($q, "requested_by", $nuh);
+       &setFactInfo($q, "requested_time", time());
+       &setFactInfo($q, "requested_count", $count);
+       # end of update stats.
+
        $result = $r;
        $result =~ s/^\((.*?)\): //;
 
@@ -237,9 +249,9 @@ sub factoidArgs {
            my $done = 0;
            my $old = $result;
            while (1) {
-#              &DEBUG("Q: result => $result (1)");
+#              &DEBUG("Q: result => $result (1before)");
                $result = &substVars($result);
-#              &DEBUG("Q: result => $result (1)");
+#              &DEBUG("Q: result => $result (1after)");
 
                last if ($old eq $result);
                $old = $result;