#!/usr/bin/perl -w

use Net::Chat::Daemon;
use Getopt::Long qw(:config no_ignore_case);

my $jid;
my $password = 'secret';
my $prompt_password = 0;
my $help;
GetOptions('password|P=s' => \$password,
           'prompt|p!' => \$prompt_password,
           'help|h!' => \$help,
           );

if ($help || @ARGV != 1) {
    print "usage: $0 [--password=PASS] [--prompt] jabber-id\n";
    exit($help ? 0 : 1);
}

$jid = shift(@ARGV);

if ($prompt_password) {
    print "Enter password: ";
    flush(STDOUT);
    chomp($password = <STDIN>);
}

my $server =
    Net::Chat::Daemon->run($jid,
                           password => $password,
                           commands => { 'exit' => sub { exit 7 },
                                         'hello' => sub { "hello back" }},
                           );

print "Done??? ($server)\n";
