]> git.donarmstrong.com Git - infobot.git/blob - src/Factoids/Statement.pl
* New maxVolunteerLength to govern max size of non addressed replies
[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 db
10 ##              - return feedback statement
11 ##
12 ##      otherwise return
13 ##              - null for confused.
14 ##
15
16 # use strict;   # TODO
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         }
47         elsif ( $param{'acceptUrl'} eq 'REJECT' ) {
48             &status("REJECTED URL entry") if ( &IsParam('VERBOSITY') );
49             return unless ( $urlType eq '' );
50         }
51         else {
52
53             # OPTIONAL
54         }
55     }
56
57     # learn statement. '$lhs is|are $rhs'
58     if ( $in =~ /(^|\s)(is|are)(\s|$)/i ) {
59         my ( $lhs, $mhs, $rhs ) = ( $`, $&, $' );
60
61         # Quit if they are over the limits. Check done here since Core.pl calls
62         # this mid sub and Question.pl needs its own check as well. NOTE: $in is
63         # used in this place since lhs and rhs are really undefined for unwanted
64         # teaching. Mainly, the "is" could be anywhere within a 510 byte or so
65         # block of text, so the total size was choosen since the sole purpose of
66         # this logic is to not hammer the db with pointless factoids that were
67         # only meant to be general conversation.
68         return ''
69           if (
70             length $in <
71             &::getChanConfDefault( 'minVolunteerLength', 2, $chan ) or
72             $param{'addressing'} =~ m/require/i ) and not $addressed;
73         return ''
74           if (
75             length $in >
76             &::getChanConfDefault( 'maxVolunteerLength', 512, $chan ) or
77             $param{'addressing'} =~ m/require/i ) and not $addressed;
78
79         # allows factoid arguments to be updated. -lear.
80         $lhs =~ s/^(cmd: )?(.*)/$1||'' . lc $2/e;
81
82         # discard article.
83         $lhs =~ s/^(the|da|an?)\s+//i;
84
85         # remove excessive initial and final whitespaces.
86         $lhs =~ s/^\s+|\s+$//g;
87         $mhs =~ s/^\s+|\s+$//g;
88         $rhs =~ s/^\s+|\s+$//g;
89
90         # break if either lhs or rhs is NULL.
91         if ( $lhs eq '' or $rhs eq '' ) {
92             return "NOT-A-STATEMENT";
93         }
94
95         # lets check if it failed.
96         if ( &validFactoid( $lhs, $rhs ) == 0 ) {
97             if ($addressed) {
98                 &status("IGNORE statement: <$who> $message");
99                 &performReply( &getRandom( keys %{ $lang{'confused'} } ) );
100             }
101             return;
102         }
103
104         # uncomment to prevent HUNGRY learning of rhs with whitespace
105         #return if (!$addressed and $lhs =~ /\s+/);
106         &::DEBUG("doStatement: $in:$lhs:$mhs:$rhs");
107
108         &status("statement: <$who> $message");
109
110         # change "#*#" back to '*' because of '\' sar to '#blah#'.
111         $lhs =~ s/\#(\S+)\#/$1/g;
112         $rhs =~ s/\#(\S+)\#/$1/g;
113
114         $lhs =~ s/\?+\s*$//;    # strip off '?'.
115
116         # verify the update statement whether there are any weird
117         # characters.
118         ### this can be simplified.
119         foreach ( split //, $lhs . $rhs ) {
120             my $ord = ord $_;
121             if ( $ord > 170 and $ord < 220 ) {
122                 &status("statement: illegal character '$_' $ord.");
123                 &performAddressedReply(
124                     "i'm not going to learn illegal characters");
125                 return;
126             }
127         }
128
129         # success.
130         return if ( &update( $lhs, $mhs, $rhs ) );
131     }
132
133     return 'CONTINUE';
134 }
135
136 1;
137
138 # vim:ts=4:sw=4:expandtab:tw=80