| 1 | package Amethyst::Brain::Infobot::Module::Fortune; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use vars qw(@ISA); | ||
| 5 | use Socket qw(AF_INET SOCK_STREAM); | ||
| 6 | use POE qw(Wheel::SocketFactory Wheel::ReadWrite | ||
| 7 | Filter::Line Driver::SysRW); | ||
| 8 | use Amethyst::Brain::Infobot::Module; | ||
| 9 | |||
| 10 | @ISA = qw(Amethyst::Brain::Infobot::Module); | ||
| 11 | |||
| 12 | sub new { | ||
| 13 | my $class = shift; | ||
| 14 | |||
| 15 | my $self = $class->SUPER::new( | ||
| 16 | Name => 'Fortune', | ||
| 17 | Regex => qr/^(give me a? )?fortune$/i, | ||
| 18 | Usage => '((?:give me a)? fortune)', | ||
| 19 | Description => "Get a fortune from the fortune " . | ||
| 20 | "server.", | ||
| 21 | @_ | ||
| 22 | ); | ||
| 23 | |||
| 24 | return bless $self, $class; | ||
| 25 | } | ||
| 26 | |||
| 27 | sub action { | ||
| 28 | my ($self, $message) = @_; | ||
| 29 | |||
| 30 | my $reply = $self->reply_to($message, $self->fortune()); | ||
| 31 | $reply->send; | ||
| 32 | |||
| 33 | return 1; | ||
| 34 | } | ||
| 35 | |||
| 36 | sub fortune { | ||
| 37 | my $self = shift; | ||
| 38 | |||
| 39 | my $f = qx{/usr/games/fortune -s}; | ||
| 40 | |||
| 41 | $f =~ s/\n/ /g; | ||
| 42 | |||
| 43 | return $f; | ||
| 44 | } | ||
| 45 | |||
| 46 | 1; |