Fix joining room by alias

And replace --notice with --action=send-notice
tags/patrix-0.1.4-1
Daniel Berteaud 7 years ago
parent 517771707b
commit 03a854f576
  1. 5
      README.md
  2. 10
      scripts/patrix

@ -17,14 +17,15 @@ For now it's very limited, and can only send text messages and files to a room.
* --password: the password to auth against the HS
* --server: the HS you want to connect to. Default is https://matrix.org
* --access_token: can be used instead of --user and --password
* --room: the room to which the message must be sent
* --room: the room to which the message must be sent. Can be a room ID or a room alias
* --message: the text message you want to send. If you send something on stdin, it's assumed to be the text to send and this option is ignored
* --debug: if present, will be verbose
* --notice: send a notice instead of a message (more or less the same but the client can display it differently. Riot for example will not notify you for notices)
* --conf: path to a conf file. Default conf file is ~/.patrixrc
* --file: if action is send-file, specify the path of the file to send
* --action: what to do. Valid actions are
* send-msg (default): send the text message
* send-message: an alias for send-msg
* send-notice: send a notice. Very similar to send-msg but the client may display it differently. Eg Riot will not notify you for notices
* send-file: send a binary file. --file must be set
* get-access-token: just login and print the access token
* get-room-list: prints the list of public rooms of this server

@ -10,6 +10,7 @@ use Config::Simple;
use File::HomeDir;
use File::MimeInfo;
use File::Basename;
use URI::Escape;
use Path::Tiny;
our $opt;
@ -21,7 +22,6 @@ GetOptions(
"server=s" => \$opt->{server},
"room=s" => \$opt->{room},
"message=s" => \$opt->{message},
"notice" => \$opt->{notice},
"files=s" => \$opt->{file},
"debug" => \$opt->{debug},
"action=s" => \$opt->{action},
@ -134,7 +134,7 @@ sub join_room(){
if ($opt->{debug}){
print "Trying to join room $opt->{room}\n";
}
my $uri = $opt->{server} . '/_matrix/client/r0/rooms/' . $opt->{room} . '/join?access_token=' . $opt->{access_token};
my $uri = $opt->{server} . '/_matrix/client/r0/join/' . uri_escape( $opt->{room} ) . '?access_token=' . $opt->{access_token};
my $req = HTTP::Request->new( 'POST', $uri );
my $json = {};
$req->header( 'Content-Type' => 'application/json' );
@ -150,14 +150,14 @@ sub join_room(){
}
# Resolve room -> room_id if joined by alias
my $room_id = from_json($resp->decoded_content)->{room_id};
$opt->{roomt} = $room_id if $room_id;
$opt->{room} = $room_id if $room_id;
}
sub send_msg(){
my $uri = $opt->{server} . '/_matrix/client/r0/rooms/' . $opt->{room} . '/send/m.room.message?access_token=' . $opt->{access_token};
my $req = HTTP::Request->new( 'POST', $uri );
my $json = {
msgtype => ($opt->{notice}) ? 'm.notice' : 'm.text',
msgtype => ($opt->{action} eq 'send-notice') ? 'm.notice' : 'm.text',
body => $opt->{message}
};
$req->header( 'Content-Type' => 'application/json' );
@ -242,7 +242,7 @@ if ($opt->{action} eq 'get-access-token'){
elsif ($opt->{action} eq 'get-room-list'){
list_room();
}
elsif ($opt->{action} eq 'send-msg'){
elsif ($opt->{action} =~ m/send\-(msg|message|notice)/){
join_room();
send_msg();
}

Loading…
Cancel
Save