#!/usr/bin/env perl
use strict;
use warnings;
use 5.008001;
use File::Spec;
use File::Basename;
use lib File::Spec->catdir(dirname(__FILE__), '..', 'lib');
use App::Tacochan;
use Getopt::Long ();
use LWP::UserAgent;
my $parser = Getopt::Long::Parser->new(
config => [ "no_ignore_case", "pass_through" ],
);
my $tacochan_server = 'http://127.0.0.1:4969/';
$parser->getoptions(
's|server=s' => \$tacochan_server,
);
sub usage {
print "tacochan_client
$0 [-s tacochan_server] leave #chat
$0 [-s tacochan_server] send #chat|user[, user, ...] message
";
}
my $command = shift @ARGV;
my $chat = shift @ARGV;
unless ($chat) {
usage();
exit;
}
my @params;
if ($command eq 'join') {
@params = (
"${tacochan_server}join",
+{
chat => $chat,
},
);
} elsif ($command eq 'leave') {
@params = (
"${tacochan_server}leave",
+{
chat => $chat,
},
);
} elsif ($command eq 'send' || $command eq 'notice' || $command eq 'privmsg') {
my $message = shift @ARGV;
unless ($message) {
usage();
exit;
}
@params = (
"${tacochan_server}send",
+{
chat => $chat,
message => $message,
},
);
} else {
usage();
exit;
}
my $ua = LWP::UserAgent->new(
agent => "TacochanClient/$App::Tacochan::VERSION",
);
my $res = $ua->post(@params);
print $res->content . "\n";
__END__
=head1 NAME
tacochan - Skype message delivery by HTTP
=head1 SYNOPSIS
# leave chat
tacochan -s http://127.0.0.1:4969/ leave \#chat
# sent message
tacochan -s http://127.0.0.1:4969/ send \#chat|user[, user, ...] message
=head1 OPTIONS
=over 4
=item -s, --server
tacochan server url.
=cut