summaryrefslogtreecommitdiffstats
path: root/lib/Crawl/Bot/Plugin/Puppet.pm
blob: 52c3019663bf1ddeeed16b87267d2b76614e7814 (plain) (blame)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package Crawl::Bot::Plugin::Puppet;
use Moose;
use autodie;
extends 'Crawl::Bot::Plugin';

has admin => (
    is      => 'ro',
    isa     => 'ArrayRef[Str]',
    # Make sure these nicks are registered!  Even if they are, there is a
    # time window during which someone could abuse the feature (before
    # being disconnected by nickserv), so we are only using the nick that
    # is usually connected, and not the backups.
    default => sub { [
        '|amethyst', # '\amethyst', 'lamethyst'
    ] }
);

sub said {
    my $self = shift;
    my ($args) = @_;

    my $doit = 0;
    $doit ||= ($_ eq $args->{who}) for @{$self->admin};
    return undef unless $doit;

    if ($args->{body} =~ /^%pup(?:pet)?(a?)(e?)\s+(#\S+\s+)?(\S.*)$/) {
        my ($all, $emote, $namedchan, $msg) = ($1, $2, $3, $4);
        my @chans = $self->bot->channels;

        for my $chan ($namedchan || @chans[0 .. ($all ? $#chans : 0)]) {
            my %keys = (channel => $chan, body => $msg);
            if ($emote) {
                $self->emote(%keys)
            } else {
                $self->say(%keys);
            }
        }
    }
}

__PACKAGE__->meta->make_immutable;
no Moose;

1;