From 2d4a4d4a213ba467c2b8bc576f41a0b5bc32ec20 Mon Sep 17 00:00:00 2001 From: Neil Moore Date: Wed, 1 Aug 2012 23:15:35 -0500 Subject: Add a new %puppet command. Usable only by someone on the list of admin nicks (currently, me). Usage is: %pup I will say this in the primary channel (##crawl-dev) %pupe will emote this in the primary channel %pupa I will say this in all channels %pupae will emote this in all channels %pup ##crawl I will say this in the single named channel %pupe ##crawl will emote this in the single named channel --- lib/Crawl/Bot/Plugin.pm | 2 +- lib/Crawl/Bot/Plugin/Puppet.pm | 44 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 lib/Crawl/Bot/Plugin/Puppet.pm diff --git a/lib/Crawl/Bot/Plugin.pm b/lib/Crawl/Bot/Plugin.pm index 6ef7c80..0661f24 100644 --- a/lib/Crawl/Bot/Plugin.pm +++ b/lib/Crawl/Bot/Plugin.pm @@ -6,7 +6,7 @@ has bot => ( isa => 'Crawl::Bot', required => 1, weak_ref => 1, - handles => [qw(say say_all data_dir)], + handles => [qw(emote say say_all data_dir)], ); # not all plugins require implementations here 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; -- cgit v1.2.3