| 1 | package Amethyst::Brain::CNN; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use vars qw(@ISA); | ||
| 5 | use URI; | ||
| 6 | use Amethyst::Brain; | ||
| 7 | use Amethyst::Message; | ||
| 8 | |||
| 9 | @ISA = qw(Amethyst::Brain); | ||
| 10 | |||
| 11 | sub init { | ||
| 12 | my $self = shift; | ||
| 13 | $self->{Content} = ''; | ||
| 14 | } | ||
| 15 | |||
| 16 | sub think { | ||
| 17 | my $self = shift; | ||
| 18 | my $message = shift; | ||
| 19 | |||
| 20 | my $content = $message->content; | ||
| 21 | |||
| 22 | if ($content !~ /[\.?!]\s*$/) { | ||
| 23 | $self->{Content} .= ' ' . $content; | ||
| 24 | return; | ||
| 25 | } | ||
| 26 | |||
| 27 | $content = lc $self->{Content} . ' ' . $content; | ||
| 28 | $self->{Content} = ''; | ||
| 29 | |||
| 30 | # $content =~ s/\b(\w)\b/\u$1/g; | ||
| 31 | $content =~ s/\s+/ /g; | ||
| 32 | $content =~ s/^ //; | ||
| 33 | $content =~ s/ $//; | ||
| 34 | |||
| 35 | local *::connections = $self->{Output}; | ||
| 36 | |||
| 37 | foreach my $connection (keys %::connections) { | ||
| 38 | my $reply = new Amethyst::Message( | ||
| 39 | Connection => $connection, | ||
| 40 | Channel => $::connections{$connection}, | ||
| 41 | User => 'Amethyst', | ||
| 42 | Action => ACT_SAY, | ||
| 43 | Content => ucfirst $content, | ||
| 44 | ); | ||
| 45 | $reply->send; | ||
| 46 | } | ||
| 47 | |||
| 48 | return undef; | ||
| 49 | } | ||
| 50 | |||
| 51 | 1; |