aboutsummaryrefslogtreecommitdiff
path: root/Plugin/Random.pm
blob: c6ed304fe7a6aeebc9308bbbe9e8485f24d9c635 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package Plugin::Random;

use strict;
use warnings;

use List::Util;

sub configure {
	my $self = shift;
	my $cmdref = shift;

	$cmdref->($self, "shuffle", sub { $self->shuffle(@_); } );
	$cmdref->($self, "choose", sub { $self->choose(@_); } );

	return $self;
}

sub shuffle {
	my ($self, $irc, $logger, $who, $where, $ided, $rest, @arguments) = @_;

	return join " ", List::Util::shuffle(@arguments);
}

sub choose {
	my ($self, $irc, $logger, $who, $where, $ided, $rest, @arguments) = @_;
	return (List::Util::shuffle(@arguments))[0];
}
1;