Created
March 26, 2013 13:34
-
-
Save smiler/5245396 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# Hailo requires Perl 5.10 | |
use v5.10; | |
use strict; | |
use feature "switch"; | |
use Any::Moose; | |
use Hailo; | |
# Setup brain from first argument | |
my $hailo = Hailo->new(brain => $ARGV[0]); | |
$| = 1; # Autoflushing is needed | |
# Loop forever, chewing stuff from stdin and spitting the out on stdout | |
while(1) { | |
my $line = <STDIN>; | |
last if !$line; | |
chomp $line; | |
# The first word on input decides wether to learn, reply or do both. | |
my @message = split(/ /, $line); | |
my $command = shift(@message); | |
my $msg = join(' ', @message); | |
given($command) { | |
when ("learn") { $hailo->learn($msg); } | |
when ("learn_reply") { say $hailo->learn_reply($msg); } | |
when ("reply") { say $hailo->reply($msg); } | |
default { say $hailo->reply($line); } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment