Wakaba/Kareha patches (107)

49 Name: Anonymous : 2011-03-07 19:01 ID:CeUyu93S [Del]

A dice roller. Type "dice (X)d(Y)[Z]" in the email field and it will prepend a little message to your post.

use List::Utils qw( sum );

#put this after "$comment=format_comment($comment,$markup,$thread);" in kareha.pl
if ($link =~ /dice \s*/( #$1
(\d+) #$2
\s* d \s* #letter d
(\d+) #$3
\s* #space
([+-]\d+)? #$4
)/xi) {
my $derp = ", "; #array element separator
my @results = map { int( rand($3) ) +1} (1 .. $2); #generate dice results
my $sum = sum(@results) + $4; #adds the results together, plus the modifier
my $roll = join($derp, @results); #adds commas to the array elements
my $modifier = ", $4" if defined $4; #http://en.wikipedia.org/wiki/Oxford_comma
my $rolled = "<strong>Rolled: $roll$modifier = $sum</strong>"; #e.g. "Rolled: 2, 3, +1 = 6", in bold
$comment = $rolled . $comment;
}
Name: Link:
Leave these fields empty (spam trap):
More options...
Verification: