]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Factoids/Reply.pl
- make ignoreAdd a little more verbose.
[infobot.git] / src / Factoids / Reply.pl
index c920b32ce26c995baf95257529dff314b8fd0612..5c472fc5b87f257090670bcfb9888aee7da6042a 100644 (file)
@@ -67,7 +67,7 @@ sub getReply {
            &setFactInfo($lhs,"requested_time", time());
            &setFactInfo($lhs,"requested_count", $count);
        } else {
-           &dbReplace("factoids", (
+           &dbReplace("factoids", "factoid_key", (
                factoid_key     => $lhs,
                requested_by    => $nuh,
                requested_time  => time(),
@@ -136,9 +136,12 @@ sub getReply {
     ### $ SUBSTITUTION.
     ###
 
-#    &DEBUG("Reply: reply => $reply");
-    $reply = &substVars($reply,1);
-#    &DEBUG("Reply: reply => $reply");
+    # don't evaluate if it has factoid arguments.
+    if ($message =~ /^CMD:/i) {
+       &status("Reply: not doing substVars (eval dollar vars)");
+    } else {
+       $reply = &substVars($reply,1);
+    }
 
     $reply;
 }
@@ -252,6 +255,7 @@ sub substVars {
     $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.
@@ -274,20 +278,30 @@ sub substVars {
 
     if ($reply =~ /\$rand/) {
        my $rand  = rand();
-       my $randp = int($rand*100);
-       $reply =~ s/\$randpercentage/$randp/g;  # ???
-       # randnick.
+
+       # $randnick.
        if ($reply =~ /\$randnick/) {
            my @nicks = keys %{ $channels{$chan}{''} };
            my $randnick = $nicks[ int($rand*$#nicks) ];
-           s/\$randnick/$randnick/;
+           $reply =~ s/\$randnick/$randnick/g;
        }
 
+       # eg: $rand100.3
        ### TODO: number of digits. 'x.y'
-       if ($reply =~ /\$rand(\d+)/) {
-           # will this work as it does in C?
-           $rand = sprintf("%*f", $1, $rand);
+       # 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 = $&;
+
+           &status("swapping $orig to $rand");
+           &status("reply => $reply");
+           $reply =~ s/$orig/$rand/eg;
+           &status("reply => $reply");
        }
+
        $reply =~ s/\$rand/$rand/g;
     }