Amethyst
view release on metacpan or search on metacpan
Amethyst/Brain/Infobot/Module/Excuse.pm view on Meta::CPAN
package Amethyst::Brain::Infobot::Module::Excuse;
use strict;
use vars qw(@ISA);
use Socket qw(AF_INET SOCK_STREAM);
use POE qw(Wheel::SocketFactory Wheel::ReadWrite
Filter::Line Driver::SysRW);
use Amethyst::Brain::Infobot::Module;
@ISA = qw(Amethyst::Brain::Infobot::Module);
sub new {
my $class = shift;
my $self = $class->SUPER::new(
Name => 'Excuse',
Regex => qr/^(give me an? )?excuse$/i,
Usage => '((?:give me an)? excuse)',
Description => "Get an excuse from the excuse " .
"server.",
@_
);
return bless $self, $class;
}
sub action {
my ($self, $message) = @_;
my $reply = $self->reply_to($message, $self->excuse());
$reply->send;
return 1;
}
sub excuse {
my $self = shift;
unless ($self->{excuses}) {
while (<DATA>) {
chomp;
push @{$self->{excuses}}, $_;
}
}
my $e = $self->{excuses}->[rand(@{$self->{excuses}})];
return $e;
}
#sub action {
# my ($self, $message) = @_;
#
# my %states = map { $_ => "handler_$_" } qw(
# _start connect failure read
# );
#
# print STDERR "Creating child session for excuse\n";
#
# POE::Session->create(
# package_states => [ ref($self) => \%states ],
# args => [ $self, $message ],
# );
#
# return 1;
#}
#
#sub handler_read {
# my ($kernel, $heap, $session, $data) =
# @_[KERNEL, HEAP, SESSION, ARG0];
# $data =~ s/Your excuse is: // or return undef;
# chomp($data);
#
# my $reply = $heap->{Module}->reply_to($heap->{Message}, $data);
# $reply->send;
#
# delete $heap->{ReadWrite};
#}
#
#sub handler_connect {
( run in 0.756 second using v1.01-cache-2.11-cpan-39bf76dae61 )