]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Factoids/Statement.pl
* Add vim formatting comments ( # vim:ts=4:sw=4:expandtab:tw=80 )
[infobot.git] / src / Factoids / Statement.pl
index fe83ab3081972fdf8d53e3cbdbf725a538a22a20..0df491860dd34fd62e73f832000e19af853c138a 100644 (file)
@@ -6,15 +6,14 @@
 ##  doStatement --
 ##
 ##     decide if $in is a statement, and if so,
-##             - update the dbm
+##             - update the db
 ##             - return feedback statement
 ##
 ##     otherwise return
 ##             - null for confused.
-##             - NOREPLY not to respond.
 ##
 
-if (&IsParam("useStrict")) { use strict; }
+# use strict;  # TODO
 
 sub doStatement {
     my($in) = @_;
@@ -23,15 +22,15 @@ sub doStatement {
     $in =~ s/^no([, ]+)//i;    # 'no, '.
 
     # check if we need to be addressed and if we are
-    return $noreply unless ($learnok);
+    return unless ($learnok);
 
-    my($urlType) = "";
+    my($urlType) = '';
 
     # prefix www with http:// and ftp with ftp://
     $in =~ s/ www\./ http:\/\/www\./ig;
     $in =~ s/ ftp\./ ftp:\/\/ftp\./ig;
 
-    $urlType = "about"   if ($in =~ /\babout:/i);
+    $urlType = 'about'   if ($in =~ /\babout:/i);
     $urlType = 'afp'     if ($in =~ /\bafp:/);
     $urlType = 'file'    if ($in =~ /\bfile:/);
     $urlType = 'palace'  if ($in =~ /\bpalace:/);
@@ -41,12 +40,12 @@ sub doStatement {
     }
 
     # acceptUrl.
-    if (&IsParam("acceptUrl")) {
+    if (&IsParam('acceptUrl')) {
        if ($param{'acceptUrl'} eq 'REQUIRE') {         # require url type.
-           return $noreply if ($urlType eq "");
+           return if ($urlType eq '');
        } elsif ($param{'acceptUrl'} eq 'REJECT') {
-           &status("REJECTED URL entry") if (&IsParam("VERBOSITY"));
-           return $noreply unless ($urlType eq "");
+           &status("REJECTED URL entry") if (&IsParam('VERBOSITY'));
+           return unless ($urlType eq '');
        } else {
            # OPTIONAL
        }
@@ -56,8 +55,11 @@ sub doStatement {
     if ($in =~ /(^|\s)(is|are)(\s|$)/i) {
        my($lhs, $mhs, $rhs) = ($`, $&, $');
 
-       $lhs =~ tr/A-Z/a-z/;
-       $lhs =~ s/^(the|da|an?)\s+//i; # discard article
+       # allows factoid arguments to be updated. -lear.
+       $lhs =~ s/^(cmd: )?(.*)/$1||'' . lc $2/e;
+
+       # discard article.
+       $lhs =~ s/^(the|da|an?)\s+//i;
 
        # remove excessive initial and final whitespaces.
        $lhs =~ s/^\s+|\s+$//g;
@@ -65,24 +67,26 @@ sub doStatement {
        $rhs =~ s/^\s+|\s+$//g;
 
        # break if either lhs or rhs is NULL.
-       if ($lhs eq "" or $rhs eq "") {
-           return $noreply;
+       if ($lhs eq '' or $rhs eq '') {
+           return "NOT-A-STATEMENT";
        }
 
        # lets check if it failed.
        if (&validFactoid($lhs,$rhs) == 0) {
            if ($addressed) {
                &status("IGNORE statement: <$who> $message");
-               &performReply( &getRandom(keys %{$lang{'confused'}}) );
+               &performReply( &getRandom(keys %{ $lang{'confused'} }) );
            }
-           return $noreply;
+           return;
        }
 
-       return $noreply if (!$addressed and $lhs =~ /\s+/);
+       # uncomment to prevent HUNGRY learning of rhs with whitespace
+       #return if (!$addressed and $lhs =~ /\s+/);
+       &::DEBUG("doStatement: $in:$lhs:$mhs:$rhs");
 
        &status("statement: <$who> $message");
 
-       # change "#*#" back to "*" because of '\' sar to '#blah#'.
+       # change "#*#" back to '*' because of '\' sar to '#blah#'.
        $lhs =~ s/\#(\S+)\#/$1/g;
        $rhs =~ s/\#(\S+)\#/$1/g;
 
@@ -90,20 +94,23 @@ sub doStatement {
 
        # verify the update statement whether there are any weird
        # characters.
-       ### this chan be simplified.
+       ### this can be simplified.
        foreach (split //, $lhs.$rhs) {
            my $ord = ord $_;
            if ($ord > 170 and $ord < 220) {
                &status("statement: illegal character '$_' $ord.");
                &performAddressedReply("i'm not going to learn illegal characters");
-               return $noreply;
+               return;
            }
        }
 
-       return &update($lhs, $mhs, $rhs);
+       # success.
+       return if (&update($lhs, $mhs, $rhs));
     }
 
-    return '';
+    return 'CONTINUE';
 }
 
 1;
+
+# vim:ts=4:sw=4:expandtab:tw=80