| 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; |