$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;
&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(),
### $ SUBSTITUTION.
###
- $reply = &substVars($reply);
-
+# &DEBUG("Reply: reply => $reply");
+ $reply = &substVars($reply,1);
+# &DEBUG("Reply: reply => $reply");
+
$reply;
}
}
sub substVars {
- my($reply) = @_;
+ my($reply,$flag) = @_;
# $date, $time.
my $date = scalar(localtime());
$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.
- $reply =~ s/\$nick/$who/g;
- $reply =~ s/\$who/$who/g; # backward compat.
+ if ($flag) {
+ $reply =~ s/\$nick/$who/g;
+ $reply =~ s/\$who/$who/g; # backward compat.
+ }
+
if ($reply =~ /\$(user(name)?|host)/) {
my ($username, $hostname) = split /\@/, $uh;
$reply =~ s/\$user(name)?/$username/g;
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/) {