#!/usr/bin/env perl
use strict;
use warnings;
use LWP;
my $api_url = 'http://c...content-available-to-author-only...l.cx/api/' ;
my $name = shift @ ARGV or usage
( ) ; my $room = shift @ ARGV || 'lounge' ;
my $ua = LWP:: UserAgent -> new ;
main( ) ;
sub usage {
Usage: perl $0 name [room]
name your handle name.
room chat room to enter. if omitted, 'lounge' is used.
END
}
sub main {
my $quit = 0 ;
post( "${api_url}enter" , { room => $room , name => $name } ) ;
while ( ! $quit ) {
show_logs( ) ;
print "\n (r: read, q: quit)\n " ; my $cmd = <STDIN> ;
if ( $cmd eq 'q' ) {
$quit = 1 ;
} elsif ( $cmd eq 'r' ) {
} else {
post( "${api_url}write" , { room => $room , name => $name , body => $cmd } ) ;
}
}
post( "${api_url}leave" , { room => $room , name => $name } ) ;
}
sub show_logs {
my $res = post( "${api_url}read.tab" , { room => $room , name => $name } ) ;
my ( $time , $name , $color , $body ) = split /\t/ ; print "$name\t $body ($time)\n " ; }
}
sub post {
my ( $url , $args ) = @_ ;
return $ua -> post ( $url , $args ) -> content ; }
IyEvdXNyL2Jpbi9lbnYgcGVybAoKdXNlIHN0cmljdDsKdXNlIHdhcm5pbmdzOwp1c2UgTFdQOwoKbXkgJGFwaV91cmwgPSAnaHR0cDovL2MuLi5jb250ZW50LWF2YWlsYWJsZS10by1hdXRob3Itb25seS4uLmwuY3gvYXBpLyc7CgpteSAkbmFtZSA9IHNoaWZ0IEBBUkdWIG9yIHVzYWdlKCk7Cm15ICRyb29tID0gc2hpZnQgQEFSR1YgfHwgJ2xvdW5nZSc7CgpteSAkdWEgPSBMV1A6OlVzZXJBZ2VudC0+bmV3OwoKbWFpbigpOwoKc3ViIHVzYWdlIHsKCXByaW50ICJcbiIsIDw8RU5EOyBleGl0OwpVc2FnZTogcGVybCAkMCBuYW1lIFtyb29tXQoKICAgIG5hbWUJeW91ciBoYW5kbGUgbmFtZS4KICAgIHJvb20JY2hhdCByb29tIHRvIGVudGVyLiBpZiBvbWl0dGVkLCAnbG91bmd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