Add get-room-list action

tags/patrix-0.1.4-1
Daniel Berteaud 7 years ago
parent 7b8e607f64
commit 612af1e89a
  1. 27
      scripts/patrix

@ -154,10 +154,37 @@ sub send_msg(){
my $resp = $lwp->request( $req );
}
sub list_room(){
my $uri = $opt->{server} . '/_matrix/client/r0/publicRooms?access_token=' . $opt->{access_token};
my $req = HTTP::Request->new( 'POST', $uri );
my $json = {};
$req->header( 'Content-Type' => 'application/json' );
$req->content( to_json($json) );
my $resp = $lwp->request( $req );
unless ( $resp->is_success ){
die "Error joining room $opt->{room}\n";
}
if ($opt->{debug}){
print "List rooms response is\n" .
to_json(from_json($resp->decoded_content), { pretty => 1 }) .
"\n\n";
}
print "Existing Rooms:\n";
foreach (@{from_json($resp->decoded_content)->{chunk}}){
print " * " . $_->{room_id};
print ' (' . $_->{canonical_alias} . ')' if (defined $_->{canonical_alias});
print "\n";
}
}
if ($opt->{action} eq 'get-access-token'){
login();
print $opt->{access_token} . "\n";
}
elsif ($opt->{action} eq 'get-room-list'){
login();
list_room();
}
elsif ($opt->{action} eq 'send-msg'){
if (defined $opt->{access_token}){
join_room();

Loading…
Cancel
Save