]> git.donarmstrong.com Git - infobot.git/blobdiff - blootbot/src/Factoids/Reply.pl
- second round of changes from lear@OPN. thanks!
[infobot.git] / blootbot / src / Factoids / Reply.pl
index 745b7dc72b85cd805d6ae437659de938e59f5b81..e73a73e254b6e4eb3079652dcdcb970d75168d25 100644 (file)
@@ -48,7 +48,7 @@ sub getReply {
        $result =~ s/^\s*//;
     }
 
-    my $fauthor = &dbGet("factoids", "created_by", "factoid_key='$message'");
+    my $fauthor = &dbGet("factoids", "created_by", "factoid_key=".&dbQuote($message) );
     $result    = &SARit($result);
 
     $reply     = $result;
@@ -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(),
@@ -252,6 +252,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,24 +275,33 @@ 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;
     }
 
-    $reply     =~ s/\$factoid/$lhs/g;
     $reply     =~ s/\$ident/$ident/g;
 
     if ($reply =~ /\$startTime/) {