]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Factoids/Reply.pl
- strictify
[infobot.git] / src / Factoids / Reply.pl
index 0d518658fccd6b62e8cf4c9a6921412f9db693ef..4ba2135ad4259879418dd9150b3c6d8810331cbf 100644 (file)
@@ -10,7 +10,7 @@
 #   rhs - factoid message.
 ##
 
-if (&IsParam("useStrict")) { use strict; }
+# use strict;  # TODO
 
 use vars qw($msgType $uh $lastWho $ident);
 use vars qw(%lang %lastWho);
@@ -18,7 +18,7 @@ use vars qw(%lang %lastWho);
 sub getReply {
     my($message) = @_;
     my($lhs,$mhs,$rhs);
-    my($result,$reply);
+    my($reply);
     $orig{message} = $message;
 
     if (!defined $message or $message =~ /^\s*$/) {
@@ -61,18 +61,11 @@ sub getReply {
        ### FIXME: old mysql doesn't support
        ### "requested_count=requested_count+1".
        $count++;
-       ### BROKEN!!! - Tim Riker <Tim@Rikers.org> says it's fixed now
-       if (0) {        # old code.
-           &setFactInfo($lhs,"requested_by", $nuh);
-           &setFactInfo($lhs,"requested_time", time());
-           &setFactInfo($lhs,"requested_count", $count);
-       } else {
-           &dbSet("factoids", {'factoid_key' => $lhs}, {
+       &dbSet("factoids", {'factoid_key' => $lhs}, {
                requested_by    => $nuh,
                requested_time  => time(),
                requested_count => $count
-           } );
-       }
+       } );
 
        # todo: rename $real to something else!
        my $real   = 0;
@@ -250,11 +243,11 @@ sub substVars {
     my($reply,$flag) = @_;
 
     # $date, $time.
-    my $date   =  scalar(localtime());
+    # todo: support localtime.
+    my $date   =  scalar(gmtime());
     $date      =~ s/\:\d+(\s+\w+)\s+\d+$/$1/;
     $reply     =~ s/\$date/$date/gi;
     $date      =~ s/\w+\s+\w+\s+\d+\s+//;
-    # todo: support UTC.
     $reply     =~ s/\$time/$date/gi;
 
     # dollar variables.
@@ -286,28 +279,24 @@ sub substVars {
        }
 
        # eg: $rand100.3
-       ### TODO: number of digits. 'x.y'
-       # too hard.
        if ($reply =~ /\$rand(\d+)(\.(\d+))?/) {
            my $max = $1;
            my $dot = $3 || 0;
-           &status("dot => $dot, max => $max, rand=>$rand");
-           $rand = sprintf("%.*f", $dot, $rand*$max);
            my $orig = $&;
+           #&DEBUG("dot => $dot, max => $max, rand=>$rand");
+           $rand = sprintf("%.*f", $dot, $rand*$max);
 
-           &status("swapping $orig to $rand");
-           &status("reply => $reply");
-           $reply =~ s/$orig/$rand/eg;
-           &status("reply => $reply");
+           &DEBUG("swapping $orig to $rand");
+           $reply =~ s/\Q$orig\E/$rand/eg;
+       } else {
+           $reply =~ s/\$rand/$rand/g;
        }
-
-       $reply =~ s/\$rand/$rand/g;
     }
 
     $reply     =~ s/\$ident/$ident/g;
 
     if ($reply =~ /\$startTime/) {
-       my $time = scalar(localtime $^T);
+       my $time = scalar(gmtime $^T);
        $reply =~ s/\$startTime/$time/;
     }
 
@@ -317,7 +306,7 @@ sub substVars {
     }
 
     if ($reply =~ /\$factoids/) {
-       my $count = &countKeys("factoids");
+       my $factoids = &countKeys("factoids");
        $reply =~ s/\$factoids/$factoids/;
     }