summaryrefslogtreecommitdiffstats
path: root/lib/Crawl/Bot/Plugin/Puppet.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Crawl/Bot/Plugin/Puppet.pm')
-rw-r--r--lib/Crawl/Bot/Plugin/Puppet.pm44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/Crawl/Bot/Plugin/Puppet.pm b/lib/Crawl/Bot/Plugin/Puppet.pm
new file mode 100644
index 0000000..52c3019
--- /dev/null
+++ b/lib/Crawl/Bot/Plugin/Puppet.pm
@@ -0,0 +1,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;