Add --federation (and --no-federation) option when creating a room

tags/patrix-0.1.4-1
Daniel Berteaud 7 years ago
parent d07b2e1956
commit fb73e16732
  1. 3
      README.md
  2. 9
      scripts/patrix

@ -1,4 +1,4 @@
patrix is a simple command line client for [Matrix](https://matrix.org) written in perl. It can send text messages or files to rooms. I use it to send [Zabbix](https://www.zabbix.com) alerts to a Matrix room, a bit like [sendxmpp](https://github.com/lhost/sendxmpp) can do with XMPP. patrix is a simple command line client for [Matrix](https://matrix.org) written in perl. It can create rooms, send text messages or files to rooms. I use it to send [Zabbix](https://www.zabbix.com) alerts to a Matrix room, a bit like [sendxmpp](https://github.com/lhost/sendxmpp) can do with XMPP.
It requires the following perl modules It requires the following perl modules
* LWP::UserAgent * LWP::UserAgent
@ -27,6 +27,7 @@ For now it's very limited, and can only send text messages and files to a room.
* --name: set the name of a room * --name: set the name of a room
* --topic: set the topic of a room * --topic: set the topic of a room
* --alias: set an alias for a room * --alias: set an alias for a room
* --federation: Enable the federation when creating a room. Default is enabled. Can be turned of with --no-federation
* --action: what to do. Valid actions are * --action: what to do. Valid actions are
* send-msg (default): send the text message * send-msg (default): send the text message
* send-message: an alias for send-msg * send-message: an alias for send-msg

@ -31,7 +31,8 @@ GetOptions(
"alias=s" => \$opt->{alias}, "alias=s" => \$opt->{alias},
"topic=s" => \$opt->{topic}, "topic=s" => \$opt->{topic},
"preset=s" => \$opt->{preset}, "preset=s" => \$opt->{preset},
"visibility=s" => \$opt->{visibility} "visibility=s" => \$opt->{visibility},
"federation!" => \$opt->{federation}
); );
if (-e File::HomeDir->my_home . "/.patrixrc" && !$opt->{conf}){ if (-e File::HomeDir->my_home . "/.patrixrc" && !$opt->{conf}){
@ -53,8 +54,9 @@ if (!-t STDIN){
} }
# Set defaults # Set defaults
$opt->{server} //= 'matrix.org'; $opt->{server} //= 'matrix.org';
$opt->{action} //= 'send-msg'; $opt->{action} //= 'send-msg';
$opt->{federation} //= 1;
# Check we have all the options we need # Check we have all the options we need
if ($opt->{action} eq 'get-access-token' && (!$opt->{user} || !$opt->{password})){ if ($opt->{action} eq 'get-access-token' && (!$opt->{user} || !$opt->{password})){
@ -288,6 +290,7 @@ sub create_room {
$json->{invite} = $opt->{invite} if $opt->{invite}; $json->{invite} = $opt->{invite} if $opt->{invite};
$json->{preset} = $opt->{preset} if $opt->{preset}; $json->{preset} = $opt->{preset} if $opt->{preset};
$json->{visibility} = $opt->{visibility} if $opt->{visbility}; $json->{visibility} = $opt->{visibility} if $opt->{visbility};
$json->{creation_content}->{'m.federate'} = $opt->{federation};
$req->header( 'Content-Type' => 'application/json' ); $req->header( 'Content-Type' => 'application/json' );
$req->content( to_json($json) ); $req->content( to_json($json) );
my $resp = $lwp->request( $req ); my $resp = $lwp->request( $req );

Loading…
Cancel
Save