]> git.donarmstrong.com Git - infobot.git/blob - src/Factoids/Statement.pl
- ok, now it works. kill me, lear!
[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         # allows factoid arguments to be updated. -lear.
59         $lhs =~ s/^(CMD: )?(.*)/$1||"" . lc $2/e;
60
61         # discard article.
62         $lhs =~ s/^(the|da|an?)\s+//i;
63
64         # remove excessive initial and final whitespaces.
65         $lhs =~ s/^\s+|\s+$//g;
66         $mhs =~ s/^\s+|\s+$//g;
67         $rhs =~ s/^\s+|\s+$//g;
68
69         # break if either lhs or rhs is NULL.
70         if ($lhs eq "" or $rhs eq "") {
71             return "NOT-A-STATEMENT";
72         }
73
74         # lets check if it failed.
75         if (&validFactoid($lhs,$rhs) == 0) {
76             if ($addressed) {
77                 &status("IGNORE statement: <$who> $message");
78                 &performReply( &getRandom(keys %{ $lang{'confused'} }) );
79             }
80             return;
81         }
82
83         return if (!$addressed and $lhs =~ /\s+/);
84
85         &status("statement: <$who> $message");
86
87         # change "#*#" back to "*" because of '\' sar to '#blah#'.
88         $lhs =~ s/\#(\S+)\#/$1/g;
89         $rhs =~ s/\#(\S+)\#/$1/g;
90
91         $lhs =~ s/\?+\s*$//;    # strip off '?'.
92
93         # verify the update statement whether there are any weird
94         # characters.
95         ### this chan be simplified.
96         foreach (split //, $lhs.$rhs) {
97             my $ord = ord $_;
98             if ($ord > 170 and $ord < 220) {
99                 &status("statement: illegal character '$_' $ord.");
100                 &performAddressedReply("i'm not going to learn illegal characters");
101                 return;
102             }
103         }
104
105         # success.
106         return if (&update($lhs, $mhs, $rhs));
107     }
108
109     return "CONTINUE";
110 }
111
112 1;