DiceBot.pm untested

filter: Statementstmt 0.0% 0 / 23 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod n/a totaltotal 0.0% 0 / 28 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package DiceBot;
2 use strict;
3 use warnings;
4  
5 use Bot::BasicBot::CommandBot qw/command/;
6 use List::Util qw/sum/;
7  
8 use base 'Bot::BasicBot::CommandBot';
9  
10 command '1d6' => sub {
11 return int(rand 6) + 1;
12 };
13  
14 command qr/\d+d\d+/i => sub {
15 my ($self, $cmd, $message) = @_;
16  
17 my ($num, $faces) = $cmd =~ /(\d+)d(\d+)/;
18  
19 my @rolls = map { int(rand $faces) + 1 } 1 .. $num;
20  
21 return join(", ", @rolls) . " = " . sum(0, @rolls);
22 };
23  
24 1;