]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Factoids/Question.pl
woot! %myModules is dead
[infobot.git] / src / Factoids / Question.pl
index 0fb25fb0f586c9665d5e4eca7200a5801e2e7b36..4451aaa30d6e3f2224a312bf8e3b33ff4c4f85fd 100644 (file)
@@ -65,7 +65,7 @@ sub doQuestion {
 
     # valid factoid.
     if ($query =~ s/[!.]$//) {
-       push(@query,$query);
+       push(@query, $query);
     }
 
     $x = &normquery($query);
@@ -82,15 +82,16 @@ sub doQuestion {
 
     my $qregex = join '|', keys %{ $lang{'qWord'} };
 
-    # what's whats => what is; who'?s => who is, etc
-    $query =~ s/ ($qregex)\'?s / $1 is /i;
-    if ($query =~ s/\s+($qregex)\s+//i) { # check for question word
+    # purge prefix question string.
+    if ($query =~ s/^ ($qregex)//i) {
        $questionWord = lc($1);
     }
 
     if ($questionWord eq "" and $finalQMark and $addressed) {
        $questionWord = "where";
     }
+    $query =~ s/^\s+|\s+$//g; # bleh. hacked.
+    push(@query, $query) if ($query ne $x);
 
     if (&IsChanConf("factoidArguments")) {
        $result = &factoidArgs($query[0]);
@@ -125,6 +126,19 @@ sub doQuestion {
 
            push(@link, $link);
            my $newr = &getReply($link);
+
+           # no such factoid. try commands
+           if (!defined $newr || $newr =~ /^0?$/) {
+               # support command redirection.
+               # recursive cmdHooks aswell :)
+               my $done = 0;
+               $done++ if &parseCmdHook("main", $link);
+               $done++ if &parseCmdHook("extra", $link);
+               $message        = $link;
+               $done++ unless (&Modules());
+
+               return;
+           }
            last if (!defined $newr or $newr eq "");
            $result  = $newr;
        }
@@ -140,16 +154,9 @@ sub doQuestion {
        return $result;
     }
 
-    ### TODO: Use &Forker(); move function to Freshmeat.pl.
-    if (&IsChanConf("freshmeatForFactoid")) {
-       &loadMyModule($myModules{'freshmeat'});
-       $result = &Freshmeat::showPackage($query);
-       return $result if (defined $result);
-    }
-
     ### TODO: Use &Forker(); move function to Debian.pl
-    if (&IsChanConf("debianForFactoid")) {
-       &loadMyModule($myModules{'debian'});
+    if (&IsChanConf('debianForFactoid')) {
+       &loadMyModule('Debian');
        $result = &Debian::DebianFind($query);  # ???
        ### TODO: debian module should tell, through shm, that it went
        ###       ok or not.
@@ -179,9 +186,10 @@ sub factoidArgs {
 
     # to make it eleeter, split each arg and use "blah OR blah or BLAH"
     # which will make it less than linear => quicker!
-    # todo: cache this, update cache when altered. !!! !!! !!!
+    # TODO: cache this, update cache when altered. !!! !!! !!!
 #    my $t = &timeget();
-    my @list = &searchTable("factoids", "factoid_key", "factoid_key", "^CMD: ");
+    my ($first) = split(/\s+/, $str);
+    my @list = &searchTable("factoids", "factoid_key", "factoid_key", "^CMD: $first ");
 #    my $delta_time = &timedelta($t);
 #    &DEBUG("factArgs: delta_time = $delta_time s");
 #    &DEBUG("factArgs: list => ".scalar(@list) );
@@ -194,10 +202,10 @@ sub factoidArgs {
        next if (/#DEL#/);      # deleted.
 
        s/^CMD: //i;
-       &DEBUG("factarg: ''$str' =~ /^$_\$/'");
+#      &DEBUG("factarg: '$str' =~ /^$_\$/");
        my $arg = $_;
 
-       # todo: <greycat> ~punish apt for (Eating) (Parentheses)
+       # TODO: <greycat> ~punish apt for (Eating) (Parentheses)
        # how the hell do I fix the above? -dms.
 
        # eval (evil!) code. cleaned up courtesy of lear.
@@ -221,7 +229,7 @@ sub factoidArgs {
 #      &DEBUG("vals => @vals");
 
        &status("Question: factoid Arguments for '$str'");
-       # todo: use getReply() - need to modify it :(
+       # TODO: use getReply() - need to modify it :(
        my $i   = 0;
        my $q   = "CMD: $_";
        my $r   = &getFactoid($q);
@@ -231,11 +239,12 @@ sub factoidArgs {
        }
 
        # 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);
+       &sqlUpdate("factoids", { factoid_key => $q }, {
+           requested_by        => $nuh,
+           requested_time      => time(),
+           -requested_count    => "requested_count+1",
+       } );
+
        # end of update stats.
 
        $result = $r;