2 ### Question.pl: Kevin Lenzo (c) 1997
6 ## if ($query == query) {
14 if (&IsParam("useStrict")) { use strict; }
16 use vars qw($query $reply $finalQMark $nuh $result $talkok $who $nuh);
17 use vars qw(%bots %forked);
20 # my doesn't allow variables to be inherinted, local does.
21 # following is used in math()...
24 local $finalQMark = $query =~ s/\?+\s*$//;
25 $finalQMark += $query =~ s/\?\s*$//;
26 $query =~ s/^\s+|\s+$//g;
28 if (!defined $query or $query =~ /^\s*$/) {
32 my $questionWord = "";
35 return '' unless ($finalQMark);
36 return '' if (&IsParam("minVolunteerLength") == 0);
37 return '' if (length $query < $param{'minVolunteerLength'});
39 ### TODO: this should be caught in Process.pl?
40 return '' unless ($talkok);
43 # dangerous; common preambles should be stripped before here
44 if ($query =~ /^forget /i or $query =~ /^no, /) {
45 return if (exists $bots{$nuh});
48 if ($query =~ s/^literal\s+//i) {
49 &status("literal ask of '$query'.");
53 # convert to canonical reference form
57 push(@query, $query); # 1: push original.
60 if ($query =~ s/[!.]$//) {
64 $x = &normquery($query);
65 push(@query, $x) if ($x ne $query);
68 $x = &switchPerson($query);
69 push(@query, $x) if ($x ne $query);
72 $query =~ s/\s+at\s*(\?*)$/$1/; # where is x at?
73 $query =~ s/^explain\s*(\?*)/$1/i; # explain x
74 $query = " $query "; # side whitespaces.
76 my $qregex = join '|', keys %{ $lang{'qWord'} };
78 # what's whats => what is; who'?s => who is, etc
79 $query =~ s/ ($qregex)\'?s / $1 is /i;
80 if ($query =~ s/\s+($qregex)\s+//i) { # check for question word
81 $questionWord = lc($1);
84 if ($questionWord eq "" and $finalQMark and $addressed) {
85 $questionWord = "where";
88 if (&IsChanConf("factoidArguments")) {
89 $result = &factoidArgs($query[0]);
90 return $result if (defined $result);
94 for (my$i=0; $i<scalar @query; $i++) {
96 $result = &getReply($query);
97 next if (!defined $result or $result eq "");
99 # 'see also' factoid redirection support.
101 while ($result =~ /^see( also)? (.*?)\.?$/) {
104 if (grep /^$link$/i, @link) {
105 &status("recursive link found; bailing out.");
109 if (scalar @link >= 5) {
110 &status("recursive link limit reached.");
115 my $newr = &getReply($link);
116 last if (!defined $newr or $newr eq "");
121 &status("'$query' linked to: ".join(" => ", @link) );
125 &VERB("Question.pl: '$query[0]' did not exist; '$query[$i]' ($i) did",2);
131 ### TODO: Use &Forker(); move function to Freshmeat.pl.
132 if (&IsChanConf("freshmeatForFactoid")) {
133 &loadMyModule($myModules{'freshmeat'});
134 $result = &Freshmeat::showPackage($query);
135 return $result if (defined $result);
138 ### TODO: Use &Forker(); move function to Debian.pl
139 if (&IsChanConf("debianForFactoid")) {
140 &loadMyModule($myModules{'debian'});
141 $result = &Debian::DebianFind($query); # ???
142 ### TODO: debian module should tell, through shm, that it went
144 ### return $result if (defined $result);
147 if ($questionWord ne "" or $finalQMark) {
148 # if it has not been explicitly marked as a question
149 if ($addressed and $reply eq "") {
150 &status("notfound: <$who> ".join(' :: ', @query))
153 return '' unless (&IsParam("friendlyBots"));
155 foreach (split /\s+/, $param{'friendlyBots'}) {
156 &msg($_, ":INFOBOT:QUERY <$who> $query");
168 # to make it eleeter, split each arg and use "blah OR blah or BLAH"
169 # which will make it less than linear => quicker!
170 # todo: cache this, update cache when altered.
171 my @list = &searchTable("factoids", "factoid_key", "factoid_key", "CMD: ");
173 # from a design perspective, it's better to have the regex in
174 # the factoid key to reduce repetitive processing.
177 next if (/#DEL#/); # deleted.
180 # &DEBUG("factarg: ''$str' =~ /^$_\$/'");
184 # todo: make eval work with $$i's :(
186 if ($str =~ /^$arg$/i) {
187 for ($i=1; $i<=5; $i++) {
189 last unless (defined $val);
196 if ($@) { # it failed!!!
197 &WARN("factargs: regex failed! '$str' =~ /^$_\$/");
203 # &DEBUG("vals => @vals");
205 &status("Question: factoid Arguments for '$str'");
206 # todo: use getReply() - need to modify it :(
208 $result = &getFactoid("CMD: $_");
209 $result =~ s/^\((.*?)\): //;
211 foreach ( split(',', $1) ) {
213 # &DEBUG("val => $val");
216 &status("factArgs: vals[$i] == undef; not SARing '$_' for '$str'");
223 # &DEBUG("Q: result => $result (1)");
224 $result = &substVars($result);
225 # &DEBUG("Q: result => $result (1)");
227 last if ($old eq $result);
233 $vals[$i] =~ s/^me$/$who/gi;
236 &status("factArgs: SARing '$_' to '$vals[$i]'.");
237 $result =~ s/\Q$_\E/$vals[$i]/;
242 # nasty hack to get partial &getReply() functionality.
243 $result =~ s/^\s*<action>\s*(.*)/\cAACTION $1\cA/i;
244 $result =~ s/^\s*<reply>\s*//i;
245 $result = &SARit($result);
246 # $result = &substVars($result);