| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# You may distribute under the terms of either the GNU General Public License |
|
2
|
|
|
|
|
|
|
# or the Artistic License (the same terms as Perl itself) |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# (C) Paul Evans, 2016 -- leonerd@leonerd.org.uk |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package App::MatrixTool::Command::directory; |
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
790
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
27
|
|
|
9
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
25
|
|
|
10
|
1
|
|
|
1
|
|
4
|
use base qw( App::MatrixTool ); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
75
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
5
|
use URI::Escape qw( uri_escape ); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
64
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.08'; |
|
15
|
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
17
|
use constant DESCRIPTION => "Look up room alias to room ID entries"; |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
49
|
|
|
17
|
1
|
|
|
1
|
|
11
|
use constant ARGUMENTS => ( "alias" ); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
49
|
|
|
18
|
1
|
|
|
|
|
253
|
use constant OPTIONS => ( |
|
19
|
|
|
|
|
|
|
's|servers' => 'Include list of candidate servers', |
|
20
|
1
|
|
|
1
|
|
4
|
); |
|
|
1
|
|
|
|
|
1
|
|
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 NAME |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
matrixtool directory - Look up room alias to room ID entries |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$ matrixtool directory '#matrix:matrix.org' |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
This command queries the room directory service on a homeserver to map a room |
|
33
|
|
|
|
|
|
|
alias name into a room ID. As this is a fully public API that does not need an |
|
34
|
|
|
|
|
|
|
access token, this command is separate from C. |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 OPTIONS |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
The following additional options are recognised |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=over 4 |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=item C<--servers>, C<-s> |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Include a list of candidate servers in the output. |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=back |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub run |
|
51
|
|
|
|
|
|
|
{ |
|
52
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
53
|
0
|
|
|
|
|
|
my ( $opts, $alias ) = @_; |
|
54
|
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
my ( $server ) = $alias =~ m/^\#[^:]*:(.*)$/ or |
|
56
|
|
|
|
|
|
|
return Future->fail( "Cannot parse room alias" ); |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$self->http_client->request_json( |
|
59
|
|
|
|
|
|
|
method => "GET", |
|
60
|
|
|
|
|
|
|
server => $server, |
|
61
|
|
|
|
|
|
|
path => "/_matrix/client/r0/directory/room/" . uri_escape( $alias ), |
|
62
|
|
|
|
|
|
|
)->then( sub { |
|
63
|
0
|
|
|
0
|
|
|
my ( $body ) = @_; |
|
64
|
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
my $room_id = $body->{room_id}; |
|
66
|
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
$self->output( "room_id: " . $room_id ); |
|
68
|
|
|
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
|
if( $opts->{servers} ) { |
|
70
|
0
|
|
|
|
|
|
my $servers = $body->{servers}; |
|
71
|
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
$self->output( "candidate servers:" ); |
|
73
|
0
|
|
|
|
|
|
$self->output( " $_" ) for @$servers; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
Future->done; |
|
77
|
0
|
|
|
|
|
|
}); |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 EXAMPLES |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
For example, resolving a room alias into a room ID: |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
$ matrixtool directory '#matrix:matrix.org' |
|
85
|
|
|
|
|
|
|
room_id: !cURbafjkfsMDVwdRDQ:matrix.org |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Additionally a list of join candidate servers can also be printed: |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
room_id: !cURbafjkfsMDVwdRDQ:matrix.org |
|
90
|
|
|
|
|
|
|
candidate servers: |
|
91
|
|
|
|
|
|
|
matrix.org |
|
92
|
|
|
|
|
|
|
... |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 AUTHOR |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Paul Evans |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
0x55AA; |