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]);
91 return $result if (defined $result);
95 for (my$i=0; $i<scalar @query; $i++) {
97 $result = &getReply($query);
98 next if (!defined $result or $result eq "");
100 # 'see also' factoid redirection support.
102 while ($result =~ /^see( also)? (.*?)\.?$/) {
105 if (grep /^$link$/i, @link) {
106 &status("recursive link found; bailing out.");
110 if (scalar @link >= 5) {
111 &status("recursive link limit reached.");
116 my $newr = &getReply($link);
117 last if (!defined $newr or $newr eq "");
122 &status("'$query' linked to: ".join(" => ", @link) );
126 &VERB("Question.pl: '$query[0]' did not exist; '$query[$i]' ($i) did",2);
132 ### TODO: Use &Forker(); move function to Freshmeat.pl.
133 if (&IsChanConf("freshmeatForFactoid")) {
134 &loadMyModule($myModules{'freshmeat'});
135 $result = &Freshmeat::showPackage($query);
136 return $result if (defined $result);
139 ### TODO: Use &Forker(); move function to Debian.pl
140 if (&IsChanConf("debianForFactoid")) {
141 &loadMyModule($myModules{'debian'});
142 $result = &Debian::DebianFind($query); # ???
143 ### TODO: debian module should tell, through shm, that it went
145 ### return $result if (defined $result);
148 if ($questionWord ne "" or $finalQMark) {
149 # if it has not been explicitly marked as a question
150 if ($addressed and $reply eq "") {
151 &status("notfound: <$who> ".join(' :: ', @query))
154 return '' unless (&IsParam("friendlyBots"));
156 foreach (split /\s+/, $param{'friendlyBots'}) {
157 &msg($_, ":INFOBOT:QUERY <$who> $query");
169 # to make it eleeter, split each arg and use "blah OR blah or BLAH"
170 # which will make it less than linear => quicker!
171 # todo: cache this, update cache when altered. !!! !!! !!!
172 # my $t = &timeget();
173 my @list = &searchTable("factoids", "factoid_key", "factoid_key", "CMD: ");
174 # my $delta_time = &timedelta($t);
175 # &DEBUG("factArgs: delta_time = $delta_time s");
176 # &DEBUG("factArgs: list => ".scalar(@list) );
178 # from a design perspective, it's better to have the regex in
179 # the factoid key to reduce repetitive processing.
181 # it does not matter if it's not alphabetically sorted.
182 foreach (sort { length($b) <=> length($a) } @list) {
183 next if (/#DEL#/); # deleted.
186 # &DEBUG("factarg: ''$str' =~ /^$_\$/'");
189 # todo: <greycat> ~punish apt for (Eating) (Parentheses)
190 # how the hell do I fix the above? -dms.
192 # eval (evil!) code. cleaned up courtesy of lear.
195 @vals = ($str =~ /^$arg$/i);
199 &WARN("factargs: regex failed! '$str' =~ /^$_\$/");
205 if (defined $result) {
206 &WARN("factargs: '$_' matches aswell.");
210 # &DEBUG("vals => @vals");
212 &status("Question: factoid Arguments for '$str'");
213 # todo: use getReply() - need to modify it :(
216 my $r = &getFactoid($q);
218 &DEBUG("question: !result... should this happen?");
223 my $count = &getFactInfo($q, "requested_count") || 0;
225 &setFactInfo($q, "requested_by", $nuh);
226 &setFactInfo($q, "requested_time", time());
227 &setFactInfo($q, "requested_count", $count);
228 # end of update stats.
231 $result =~ s/^\((.*?)\): //;
233 foreach ( split(',', $1) ) {
235 # &DEBUG("val => $val");
238 &status("factArgs: vals[$i] == undef; not SARing '$_' for '$str'");
245 # &DEBUG("Q: result => $result (1before)");
246 $result = &substVars($result);
247 # &DEBUG("Q: result => $result (1after)");
249 last if ($old eq $result);
255 $vals[$i] =~ s/^me$/$who/gi;
258 &status("factArgs: SARing '$_' to '$vals[$i]'.");
259 $result =~ s/\Q$_\E/$vals[$i]/g;
264 # nasty hack to get partial &getReply() functionality.
265 $result =~ s/^\s*<action>\s*(.*)/\cAACTION $1\cA/i;
266 $result =~ s/^\s*<reply>\s*//i;
267 $result = &SARit($result);
269 # well... lets go through all of them. not advisable if we have like
270 # 1000 commands, heh.
272 $cmdstats{'Factoid Commands'}++;