]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Factoids/Question.pl
fix for endless loop. asuffield.
[infobot.git] / src / Factoids / Question.pl
index 1001c0b9ce8e32a99512becdfdb8fd1adc0652ba..a356f82a402fe07f3f066223b48a1f75c9940f66 100644 (file)
@@ -35,7 +35,7 @@ sub doQuestion {
     if (!$addressed) {
        return '' unless ($finalQMark);
        return '' if (&IsParam("minVolunteerLength") == 0);
-       return '' if (length($query) < $param{'minVolunteerLength'});
+       return '' if (length $query < $param{'minVolunteerLength'});
     } else {
        ### TODO: this should be caught in Process.pl?
        return '' unless ($talkok);
@@ -52,6 +52,11 @@ sub doQuestion {
 
     push(@query, $query);      # 1: push original.
 
+    # valid factoid.
+    if ($query =~ s/[!.]$//) {
+       push(@query,$query);
+    }
+
     $x = &normquery($query);
     push(@query, $x) if ($x ne $query);
     $query = $x;
@@ -76,24 +81,39 @@ sub doQuestion {
        $questionWord = "where";
     }
 
-    # valid factoid.
-    if ($query =~ s/[\!\.]$//) {
-       push(@query,$query);
-    }
-
-    for (my$i=0; $i<scalar(@query); $i++) {
+    my @link;
+    for (my$i=0; $i<scalar @query; $i++) {
        $query  = $query[$i];
        $result = &getReply($query);
        next if (!defined $result or $result eq "");
 
        # 'see also' factoid redirection support.
-       if ($result =~ /^see( also)? (.*?)\.?$/) {
-           my $newr = &getReply($2);
-           $result  = $newr    if ($newr ne "");
+
+       while ($result =~ /^see( also)? (.*?)\.?$/) {
+           my $link    = $2;
+
+           if (grep /^$link$/i, @link) {
+               &status("recursive link found; bailing out.");
+               last;
+           }
+
+           if (scalar @link >= 5) {
+               &status("recursive link limit reached.");
+               last;
+           }
+
+           push(@link, $link);
+           my $newr = &getReply($link);
+           last if (!defined $newr or $newr eq "");
+           $result  = $newr;
+       }
+
+       if (@link) {
+           &status("'$query' linked to: ".join(" => ", @link) );
        }
 
        if ($i != 0) {
-           &DEBUG("Question: guessed factoid correctly ($i) => '$query'.");
+           &DEBUG("Question: '$query[0]' did not exist; '$query[$i]' ($i) did");
        }
 
        return $result;