Skip to content

Instantly share code, notes, and snippets.

@smiler
Created March 26, 2013 13:34
Show Gist options
  • Save smiler/5245396 to your computer and use it in GitHub Desktop.
Save smiler/5245396 to your computer and use it in GitHub Desktop.
#!/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