diff options
Diffstat (limited to 'Plugin/Random.pm')
-rw-r--r-- | Plugin/Random.pm | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Plugin/Random.pm b/Plugin/Random.pm new file mode 100644 index 0000000..bd1c4d2 --- /dev/null +++ b/Plugin/Random.pm @@ -0,0 +1,32 @@ +package Plugin::Random; + +use strict; +use warnings; + +use List::Util; + +my %config; + +sub configure { + my $self = shift; + my $cmdref = shift; + my $cref = shift; + %config = %$cref; + + $cmdref->("shuffle", sub { $self->shuffle(@_); } ); + $cmdref->("choose", sub { $self->choose(@_); } ); + + return $self; +} + +sub shuffle { + my ($self, $irc, $logger, $who, $where, $rest, @arguments) = @_; + + return join " ", List::Util::shuffle(@arguments); +} + +sub choose { + my ($self, $irc, $logger, $who, $where, $rest, @arguments) = @_; + return (List::Util::shuffle(@arguments))[0]; +} +1; |