From fb73e1673214c88920af9a554bfe55d759c3cbf6 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Sat, 9 Sep 2017 11:16:44 +0200 Subject: [PATCH] Add --federation (and --no-federation) option when creating a room --- README.md | 3 ++- scripts/patrix | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6c78c1e..b7fb049 100644 --- a/README.md +++ b/README.md @@ -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 * 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 * --topic: set the topic of 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 * send-msg (default): send the text message * send-message: an alias for send-msg diff --git a/scripts/patrix b/scripts/patrix index a1651dd..a61df82 100644 --- a/scripts/patrix +++ b/scripts/patrix @@ -31,7 +31,8 @@ GetOptions( "alias=s" => \$opt->{alias}, "topic=s" => \$opt->{topic}, "preset=s" => \$opt->{preset}, - "visibility=s" => \$opt->{visibility} + "visibility=s" => \$opt->{visibility}, + "federation!" => \$opt->{federation} ); if (-e File::HomeDir->my_home . "/.patrixrc" && !$opt->{conf}){ @@ -53,8 +54,9 @@ if (!-t STDIN){ } # Set defaults -$opt->{server} //= 'matrix.org'; -$opt->{action} //= 'send-msg'; +$opt->{server} //= 'matrix.org'; +$opt->{action} //= 'send-msg'; +$opt->{federation} //= 1; # Check we have all the options we need 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->{preset} = $opt->{preset} if $opt->{preset}; $json->{visibility} = $opt->{visibility} if $opt->{visbility}; + $json->{creation_content}->{'m.federate'} = $opt->{federation}; $req->header( 'Content-Type' => 'application/json' ); $req->content( to_json($json) ); my $resp = $lwp->request( $req );