]> git.donarmstrong.com Git - infobot.git/blob - src/Factoids/Statement.pl
Changed $infobot_ to $bot_
[infobot.git] / src / Factoids / Statement.pl
1 ###
2 ### Statement.pl: Kevin Lenzo  (c) 1997
3 ###
4
5 ##
6 ##  doStatement --
7 ##
8 ##      decide if $in is a statement, and if so,
9 ##              - update the dbm
10 ##              - return feedback statement
11 ##
12 ##      otherwise return
13 ##              - null for confused.
14 ##              - NOREPLY not to respond.
15 ##
16
17 if (&IsParam("useStrict")) { use strict; }
18
19 sub doStatement {
20     my($in) = @_;
21
22     $in =~ s/\\(\S+)/\#$1\#/g;  # fix the backslash.
23     $in =~ s/^no([, ]+)//i;     # 'no, '.
24
25     # check if we need to be addressed and if we are
26     return $noreply unless ($learnok);
27
28     my($urlType) = "";
29
30     # prefix www with http:// and ftp with ftp://
31     $in =~ s/ www\./ http:\/\/www\./ig;
32     $in =~ s/ ftp\./ ftp:\/\/ftp\./ig;
33
34     # look for a "type nugget". this should be externalized.
35     $urlType = "mailto" if ($in =~ /\bmailto:.+\@.+\..{2,}/i);
36     $urlType = "mailto" if ($in =~ s/\b(\S+\@\S+\.\S{2,})/mailto:$1/gi);
37     $in =~ s/(mailto:)+/mailto:/g;
38
39     $urlType = "about"   if ($in =~ /\babout:/i);
40     $urlType = 'afp'     if ($in =~ /\bafp:/);
41     $urlType = 'file'    if ($in =~ /\bfile:/);
42     $urlType = 'palace'  if ($in =~ /\bpalace:/);
43     $urlType = 'phoneto' if ($in =~ /\bphone(to)?:/);
44     if ($in =~ /\b(news|http|ftp|gopher|telnet):\s*\/\/[\-\w]+(\.[\-\w]+)+/) {
45         $urlType = $1;
46     }
47
48     # acceptUrl.
49     if (&IsParam("acceptUrl")) {
50         if ($param{'acceptUrl'} eq 'REQUIRE') {         # require url type.
51             return $noreply if ($urlType eq "");
52         } elsif ($param{'acceptUrl'} eq 'REJECT') {
53             &status("REJECTED URL entry") if (&IsParam("VERBOSITY"));
54             return $noreply unless ($urlType eq "");
55         } else {
56             # OPTIONAL
57         }
58     }
59
60     # learn statement. '$lhs is|are $rhs'
61     if ($in =~ /(^|\s)(is|are)(\s|$)/i) {
62         my($lhs, $mhs, $rhs) = ($`, $&, $');
63
64         $lhs =~ tr/A-Z/a-z/;
65         $lhs =~ s/^(the|da|an?)\s+//i; # discard article
66
67         # remove excessive initial and final whitespaces.
68         $lhs =~ s/^\s+|\s+$//g;
69         $mhs =~ s/^\s+|\s+$//g;
70         $rhs =~ s/^\s+|\s+$//g;
71
72         # break if either lhs or rhs is NULL.
73         if ($lhs eq "" or $rhs eq "") {
74             return $noreply;
75         }
76
77         # lets check if it failed.
78         if (&validFactoid($lhs,$rhs) == 0) {
79             if ($addressed) {
80                 &status("IGNORE statement: <$who> $message");
81                 &performReply( &getRandom(keys %{$lang{'confused'}}) );
82             }
83             return $noreply;
84         }
85
86         return $noreply if (!$addressed and $lhs =~ /\s+/);
87
88         &status("statement: <$who> $message");
89
90         # change "#*#" back to "*" because of '\' sar to '#blah#'.
91         $lhs =~ s/\#(\S+)\#/$1/g;
92         $rhs =~ s/\#(\S+)\#/$1/g;
93
94         $lhs =~ s/\?+\s*$//;    # strip off '?'.
95
96         # verify the update statement whether there are any weird
97         # characters.
98         ### this chan be simplified.
99         foreach (split //, $lhs.$rhs) {
100             my $ord = ord $_;
101             if ($ord > 170 and $ord < 220) {
102                 &status("statement: illegal character '$_' $ord.");
103                 &performAddressedReply("i'm not going to learn illegal characters");
104                 return $noreply;
105             }
106         }
107
108         return &update($lhs, $mhs, $rhs);
109     }
110
111     return '';
112 }
113
114 1;