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