]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Factoids/Reply.pl
* Remove merge detrius from Reply.pl; stop breaking on 'you are'
[infobot.git] / src / Factoids / Reply.pl
index 7dc720fc8f5f55b5401e4a20dd4cc2b22dd632e1..38f65a083db6d8c534d9716887cdc629c953a236 100644 (file)
@@ -11,6 +11,7 @@
 ##
 
 # use strict;  # TODO
+use POSIX qw(strftime);
 
 use vars qw($msgType $uh $lastWho $ident);
 use vars qw(%lang %lastWho);
@@ -27,14 +28,9 @@ sub getReply {
     }
 
     $message =~ tr/A-Z/a-z/;
-    $message =~ s/^cmd:/CMD:/;
-
-    if (&IsChanConf("factoidSearch")) {
-       @searches = split(/\s+/, &getChanConf("factoidSearch"));
-    } else {
-       @searches = ('_default');
-    }
 
+    @searches = split(/\s+/, &getChanConfDefault('factoidSearch', '_default', $chan));
+    &::DEBUG("factoidSearch: $chan is: " . join(':', @searches));
     # requesting the _default one, ignore factoidSearch
     if ($message =~ /^_default\s+/) {
        @searches = ('_default');
@@ -85,7 +81,7 @@ sub getReply {
        ### FLOOD REPETION AND PROTECTION. -20000124
 
        # stats code.
-       ### FIXME: old mysql doesn't support
+       ### FIXME: old mysql/sqlite doesn't support
        ### "requested_count=requested_count+1".
        $count++;
        &sqlSet("factoids", {'factoid_key' => $factoid}, {
@@ -129,13 +125,7 @@ sub getReply {
                $reply = "$lhs $mhs $result";
            }
 
-           if ($reply =~ s/^\Q$who\E is/you are/i) {
-               # fix the person.
-           } else {
-               if ($reply =~ /^you are / or $reply =~ / you are /) {
-                   return if ($addressed);
-               }
-           }
+           $reply =~ s/^\Q$who\E is/you are/i) {
        }
     }
 
@@ -154,11 +144,11 @@ sub getReply {
     ###
 
     # don't evaluate if it has factoid arguments.
-    if ($message =~ /^CMD:/i) {
-       &status("Reply: not doing substVars (eval dollar vars)");
-    } else {
+#    if ($message =~ /^cmd:/i) {
+#      &status("Reply: not doing substVars (eval dollar vars)");
+#    } else {
        $reply = &substVars($reply,1);
-    }
+#    }
 
     $reply;
 }
@@ -254,19 +244,36 @@ sub SARit {
     }
     &status("Reply.pl: $done SARs done.") if ($done);
 
+    # <URL></URL> type
+    #
+    while ($txt =~ /<URL>(.*)<\/URL>/){
+       &status("we have to norm this <URL></URL> stuff, SARing");
+       my $foobar = $1;
+       if ($foobar =~ m/(http:\/\/[^?]+)\?(.*)/){
+           my ($pig1,$pig2) = ($1,$2);
+           &status("SARing using URLencode");
+           $pig2=~s/([^\w])/sprintf("%%%02x",ord($1))/gie;
+           $foobar=$pig1."?".$pig2;
+       }
+       $txt =~ s/<URL>(.*)<\/URL>/$foobar/;
+    }
     return $txt;
 }
 
 sub substVars {
     my($reply,$flag) = @_;
 
-    # $date, $time.
+    # $date, $time, $day.
     # TODO: support localtime.
-    my $date   =  scalar(gmtime());
-    $date      =~ s/\:\d+(\s+\w+)\s+\d+$/$1/;
+    my $date   =  strftime("%Y.%m.%d", gmtime());
     $reply     =~ s/\$date/$date/gi;
-    $date      =~ s/\w+\s+\w+\s+\d+\s+//;
-    $reply     =~ s/\$time/$date/gi;
+    my $time   =  strftime("%k:%M:%S", gmtime());
+    $reply     =~ s/\$time/$time/gi;
+    my $day    =  strftime("%A", gmtime());
+    $reply     =~ s/\$day/$day/gi;
+
+    # support $ident when I have multiple nicks
+    my $mynick = $conn->nick() if $conn;
 
     # dollar variables.
     if ($flag) {
@@ -311,7 +318,7 @@ sub substVars {
        }
     }
 
-    $reply     =~ s/\$ident/$ident/g;
+    $reply     =~ s/\$ident/$mynick/g;
 
     if ($reply =~ /\$startTime/) {
        my $time = scalar(gmtime $^T);