summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Moore <neil@s-z.org>2012-08-01 23:15:35 -0500
committerNeil Moore <neil@s-z.org>2012-08-01 23:15:35 -0500
commit2d4a4d4a213ba467c2b8bc576f41a0b5bc32ec20 (patch)
treeaf5991d6502ada7c3fefc3538877b84498c1792e
parentc256ddc4dd6c4150fe6e80c0dc2e9e13a66866f8 (diff)
downloadcrawlbot-2d4a4d4a213ba467c2b8bc576f41a0b5bc32ec20.tar.gz
crawlbot-2d4a4d4a213ba467c2b8bc576f41a0b5bc32ec20.zip
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
-rw-r--r--lib/Crawl/Bot/Plugin.pm2
-rw-r--r--lib/Crawl/Bot/Plugin/Puppet.pm44
2 files changed, 45 insertions, 1 deletions
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;