]> git.donarmstrong.com Git - infobot.git/blob - src/Factoids/Question.pl
Changed $infobot_ to $bot_
[infobot.git] / src / Factoids / Question.pl
1 ###
2 ### Question.pl: Kevin Lenzo  (c) 1997
3 ###
4
5 ##  doQuestion --
6 ##      if ($query == query) {
7 ##              return $value;
8 ##      } else {
9 ##              return NULL;
10 ##      }
11 ##
12 ##
13
14 if (&IsParam("useStrict")) { use strict; }
15
16 use vars qw($query $reply $finalQMark $nuh $result $talkok $who $nuh);
17 use vars qw(%bots %forked);
18
19 sub doQuestion {
20     # my doesn't allow variables to be inherinted, local does.
21     # following is used in math()...
22     local($query) = @_;
23     local($reply) = "";
24     local $finalQMark = $query =~ s/\?+\s*$//;
25     $finalQMark += $query =~ s/\?\s*$//;
26
27     if (!defined $query or $query =~ /^\s*$/) {
28         &FIXME("doQ: query == NULL");
29         return '';
30     }
31
32     my $origQuery = $query;
33
34     my $questionWord    = "";
35
36     if (!$addressed) {
37         return '' unless ($finalQMark);
38
39         if (&IsParam("minVolunteerLength") == 0 or
40                 length($query) < $param{'minVolunteerLength'})
41         {
42             return '';
43         }
44     } else {
45         ### TODO: this should be caught in Process.pl?
46         return '' unless ($talkok);
47     }
48
49     # dangerous; common preambles should be stripped before here
50     if ($query =~ /^forget /i or $query =~ /^no, /) {
51         return $noreply if (exists $bots{$nuh});
52     }
53
54     # convert to canonical reference form
55     $query = &normquery($query);
56     $query = &switchPerson($query);
57
58     $query =~ s/\s+at\s*(\?*)$/$1/;     # where is x at?
59     $query =~ s/^explain\s*(\?*)/$1/i;  # explain x
60     $query = " $query ";                # side whitespaces.
61
62     my $qregex = join '|', keys %{$lang{'qWord'}};
63
64     # what's whats => what is; who'?s => who is, etc
65     $query =~ s/ ($qregex)\'?s / $1 is /i;
66     if ($query =~ s/\s+($qregex)\s+//i) { # check for question word
67         $questionWord = lc($1);
68     }
69
70     if ($questionWord eq "" and $finalQMark and $addressed) {
71         $questionWord = "where";
72     }
73
74     $query =~ s/^\s+|\s+$//g;
75
76     # valid factoid.
77     if (defined( $result = &getReply($query) )) {
78         # 'see also' factoid redirection support.
79         if ($result =~ /^see( also)? (.*?)\.?$/) {
80             my $newr = &getReply($2);
81             $result  = $newr    if ($newr ne "");
82         }
83
84         return $result if ($result ne "");
85
86         ### TODO: Use &Forker(); move function to Freshmeat.pl.
87         if (&IsParam("freshmeatForFactoid")) {
88             &loadMyModule($myModules{'freshmeat'});
89             $result = &Freshmeat::showPackage($query);
90             return $result unless ($result eq $noreply);
91         }
92
93         &DEBUG("Question: hrm... result => '$result'.");
94     }
95
96     if ($questionWord ne "" or $finalQMark) {
97         # if it has not been explicitly marked as a question
98         if ($addressed and $reply eq "") {
99             if ($origQuery eq $query) {
100                 &status("notfound: <$who> $origQuery");
101             } else {
102                 &status("notfound: <$who> $origQuery :: $query");
103             }
104
105             return '' unless (&IsParam("friendlyBots"));
106
107             foreach (split /\s+/, $param{'friendlyBots'}) {
108                 &msg($_, ":INFOBOT:QUERY <$who> $query");
109             }
110         }
111     }
112
113     $reply;
114 }
115
116 1;