From: dms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Date: Wed, 3 Jan 2001 13:37:00 +0000 (+0000)
Subject: - Finally added proper recursive SARs
X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=4321cc1e0c1162a99e534c30003ce9f1cad9e54b;p=infobot.git

- Finally added proper recursive SARs


git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk@220 c11ca15a-4712-0410-83d8-924469b57eb5
---

diff --git a/blootbot/src/Factoids/Reply.pl b/blootbot/src/Factoids/Reply.pl
index d0607c1..0ad9ecc 100644
--- a/blootbot/src/Factoids/Reply.pl
+++ b/blootbot/src/Factoids/Reply.pl
@@ -86,9 +86,32 @@ sub getReply {
 	$done = 0;
 
 	# EG: (blah1|blah2|blah3|) => blah1
-	while ($result =~ /\((.*?\|.*?)\)/) {
+	while ($result =~ /\((.*\|.*?)\)/) {
 	    my $str = $1;
-	    my @rand = split /\|/, $str;
+	    my @rand;
+
+	    if ($done == 1) {
+		&status("Cool. recursive SAR factoids rock :-)");
+	    }
+
+	    my $x = "";
+	    foreach (split /\|/, $str) {
+		$x = $x.$_;
+
+		if (/^\(/ or ($x ne $_ and !/\)$/)) {   # start or mid.
+		    $x = $x."|";
+###		    print "start or mid. ($x)\n";
+		} elsif (/\)$/) {               # end.
+###		    print "end; pushing '$x$_', (was $x)\n";
+		    push(@rand,$x);
+		    $x = "";
+		} else {
+###		    print "nice append. '$_'\n";
+		    push(@rand,$_);
+		    $x = "";
+		}
+	    }
+
 	    my $rand = $rand[rand @rand];
 
 	    &status("Reply.pl: SARing '($str)' to '$rand'.");