mirror of
https://github.com/dani/patrix.git
synced 2024-06-25 19:13:27 +02:00
Add get-room-list action
This commit is contained in:
parent
7b8e607f64
commit
612af1e89a
|
@ -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…
Reference in New Issue
Block a user