diff options
author | Neil Moore <neil@s-z.org> | 2012-01-02 22:51:24 -0500 |
---|---|---|
committer | Neil Moore <neil@s-z.org> | 2012-01-02 22:51:24 -0500 |
commit | 49b8fd93afa1a4981cbba011ed0f09e5403ccd93 (patch) | |
tree | 16023319c922f99a4810e52b717f3389a062b3ba | |
parent | 2ccf5107e0d93c9bcf92a1232e5a83329b90f1b4 (diff) | |
download | crawlbot-49b8fd93afa1a4981cbba011ed0f09e5403ccd93.tar.gz crawlbot-49b8fd93afa1a4981cbba011ed0f09e5403ccd93.zip |
Plugin for %?? command, like gretell's @??.
-rw-r--r-- | lib/Crawl/Bot/Plugin/Monster.pm | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/Crawl/Bot/Plugin/Monster.pm b/lib/Crawl/Bot/Plugin/Monster.pm new file mode 100644 index 0000000..8b917fe --- /dev/null +++ b/lib/Crawl/Bot/Plugin/Monster.pm @@ -0,0 +1,40 @@ +package Crawl::Bot::Plugin::Monster; +use Moose; + +extends 'Crawl::Bot::Plugin'; + +use autodie; + +warn "Loading Plugin::Monster\n"; + +sub said { + my $self = shift; + my ($args) = @_; + my @keys = (who => $args->{who}, channel => $args->{channel}, "body"); + + if ($args->{body} =~ /^%\?\? *(.*)/) { + my $resp = $self->get_monster_info($1); + if ($resp) { + $self->say(@keys, $resp); + } else { + $self->say(@keys, "Error calling monster-trunk: $!") + } + } +} + +sub get_monster_info { + my $self = shift; + my $monster = shift; + + CORE::open(F, "-|", "bin/monster-trunk", $monster) or return undef; + local $/ = undef; + my $resp = <F>; + CORE::close(F) or return undef; + + return $resp; +} + +__PACKAGE__->meta->make_immutable; +no Moose; + +1; |