2 ### Question.pl: Kevin Lenzo (c) 1997
6 ## if ($query == query) {
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);
42 # there is no flag to disable/enable asking factoids...
43 # so it was added... thanks zyxep! :)
44 if (&IsFlag("a") ne "a" && &IsFlag("o") ne "o") {
45 &status("$who tried to ask us when not allowed.");
50 # dangerous; common preambles should be stripped before here
51 if ($query =~ /^forget /i or $query =~ /^no, /) {
52 return if (exists $bots{$nuh});
55 if ($query =~ s/^literal\s+//i) {
56 &status("literal ask of '$query'.");
60 # convert to canonical reference form
64 push(@query, $query); # 1: push original.
67 if ($query =~ s/[!.]$//) {
71 $x = &normquery($query);
72 push(@query, $x) if ($x ne $query);
75 $x = &switchPerson($query);
76 push(@query, $x) if ($x ne $query);
79 $query =~ s/\s+at\s*(\?*)$/$1/; # where is x at?
80 $query =~ s/^explain\s*(\?*)/$1/i; # explain x
81 $query = " $query "; # side whitespaces.
83 my $qregex = join '|', keys %{ $lang{'qWord'} };
85 # what's whats => what is; who'?s => who is, etc
86 $query =~ s/ ($qregex)\'?s / $1 is /i;
87 if ($query =~ s/\s+($qregex)\s+//i) { # check for question word
88 $questionWord = lc($1);
91 if ($questionWord eq "" and $finalQMark and $addressed) {
92 $questionWord = "where";
95 if (&IsChanConf("factoidArguments")) {
96 $result = &factoidArgs($query[0]);
98 return $result if (defined $result);
102 for (my$i=0; $i<scalar @query; $i++) {
104 $result = &getReply($query);
105 next if (!defined $result or $result eq "");
107 # 'see also' factoid redirection support.
109 while ($result =~ /^see( also)? (.*?)\.?$/) {
112 # #debian@OPN was having problems with libstdc++ factoid
113 # redirection :) 20021116. -xk.
114 # hrm... allow recursive loops... next if statement handles
116 if (grep /^\Q$link\E$/i, @link) {
117 &status("recursive link found; bailing out.");
121 if (scalar @link >= 5) {
122 &status("recursive link limit (5) reached.");
127 my $newr = &getReply($link);
128 last if (!defined $newr or $newr eq "");
133 &status("'$query' linked to: ".join(" => ", @link) );
137 &VERB("Question.pl: '$query[0]' did not exist; '$query[$i]' ($i) did",2);
143 ### TODO: Use &Forker(); move function to Freshmeat.pl.
144 if (&IsChanConf("freshmeatForFactoid")) {
145 &loadMyModule($myModules{'freshmeat'});
146 $result = &Freshmeat::showPackage($query);
147 return $result if (defined $result);
150 ### TODO: Use &Forker(); move function to Debian.pl
151 if (&IsChanConf("debianForFactoid")) {
152 &loadMyModule($myModules{'debian'});
153 $result = &Debian::DebianFind($query); # ???
154 ### TODO: debian module should tell, through shm, that it went
156 ### return $result if (defined $result);
159 if ($questionWord ne "" or $finalQMark) {
160 # if it has not been explicitly marked as a question
161 if ($addressed and $reply eq "") {
162 &status("notfound: <$who> ".join(' :: ', @query))
165 return '' unless (&IsParam("friendlyBots"));
167 foreach (split /\s+/, $param{'friendlyBots'}) {
168 &msg($_, ":INFOBOT:QUERY <$who> $query");
180 # to make it eleeter, split each arg and use "blah OR blah or BLAH"
181 # which will make it less than linear => quicker!
182 # todo: cache this, update cache when altered. !!! !!! !!!
183 # my $t = &timeget();
184 my @list = &searchTable("factoids", "factoid_key", "factoid_key", "^CMD: ");
185 # my $delta_time = &timedelta($t);
186 # &DEBUG("factArgs: delta_time = $delta_time s");
187 # &DEBUG("factArgs: list => ".scalar(@list) );
189 # from a design perspective, it's better to have the regex in
190 # the factoid key to reduce repetitive processing.
192 # it does not matter if it's not alphabetically sorted.
193 foreach (sort { length($b) <=> length($a) } @list) {
194 next if (/#DEL#/); # deleted.
197 &DEBUG("factarg: ''$str' =~ /^$_\$/'");
200 # todo: <greycat> ~punish apt for (Eating) (Parentheses)
201 # how the hell do I fix the above? -dms.
203 # eval (evil!) code. cleaned up courtesy of lear.
206 @vals = ($str =~ /^$arg$/i);
210 &WARN("factargs: regex failed! '$str' =~ /^$_\$/");
216 if (defined $result) {
217 &WARN("factargs: '$_' matches aswell.");
221 # &DEBUG("vals => @vals");
223 &status("Question: factoid Arguments for '$str'");
224 # todo: use getReply() - need to modify it :(
227 my $r = &getFactoid($q);
229 &DEBUG("question: !result... should this happen?");
234 my $count = &getFactInfo($q, "requested_count") || 0;
236 &setFactInfo($q, "requested_by", $nuh);
237 &setFactInfo($q, "requested_time", time());
238 &setFactInfo($q, "requested_count", $count);
239 # end of update stats.
242 $result =~ s/^\((.*?)\): //;
244 foreach ( split(',', $1) ) {
246 # &DEBUG("val => $val");
249 &status("factArgs: vals[$i] == undef; not SARing '$_' for '$str'");
256 # &DEBUG("Q: result => $result (1before)");
257 $result = &substVars($result);
258 # &DEBUG("Q: result => $result (1after)");
260 last if ($old eq $result);
266 $vals[$i] =~ s/^me$/$who/gi;
269 &status("factArgs: SARing '$_' to '$vals[$i]'.");
270 $result =~ s/\Q$_\E/$vals[$i]/g;
275 # nasty hack to get partial &getReply() functionality.
276 $result =~ s/^\s*<action>\s*(.*)/\cAACTION $1\cA/i;
277 $result =~ s/^\s*<reply>\s*//i;
278 $result = &SARit($result);
280 # well... lets go through all of them. not advisable if we have like
281 # 1000 commands, heh.
283 $cmdstats{'Factoid Commands'}++;