1
0
mirror of https://github.com/dani/patrix.git synced 2024-06-17 20:29:13 +02:00

Add support for --send-code

This commit is contained in:
Daniel Berteaud 2017-11-24 12:30:29 +01:00
parent 0e867c76c9
commit 5207d794b5
2 changed files with 9 additions and 1 deletions

View File

@ -41,6 +41,7 @@ Here're the vailable options:
* 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
* 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-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-code: same as send-msg, but text will be presented like code (<pre><code>text</code></pre>)
* send-file: send a binary file. --file must be set * send-file: send a binary file. --file must be set
* create-room: create a new room * create-room: create a new room
* modify-room: change an existing room (add an alias, set name, topic, join_rules, invite) * modify-room: change an existing room (add an alias, set name, topic, join_rules, invite)

View File

@ -30,6 +30,7 @@ GetOptions(
"action=s" => \$opt->{action}, "action=s" => \$opt->{action},
"send-msg|send-message" => \$opt->{'send-msg'}, "send-msg|send-message" => \$opt->{'send-msg'},
"send-notice" => \$opt->{'send-notice'}, "send-notice" => \$opt->{'send-notice'},
"send-code" => \$opt->{'send-code'},
"send-file" => \$opt->{'send-file'}, "send-file" => \$opt->{'send-file'},
"create-room" => \$opt->{'create-room'}, "create-room" => \$opt->{'create-room'},
"modify-room" => \$opt->{'modify-room'}, "modify-room" => \$opt->{'modify-room'},
@ -62,6 +63,7 @@ if ($opt->{conf} && -e $opt->{conf}){
my @actions = qw( my @actions = qw(
send-msg send-msg
send-notice send-notice
send-code
send-file send-file
create-room create-room
modify-room modify-room
@ -228,6 +230,11 @@ sub send_msg {
msgtype => ($opt->{action} eq 'send-notice') ? 'm.notice' : 'm.text', msgtype => ($opt->{action} eq 'send-notice') ? 'm.notice' : 'm.text',
body => $opt->{message} body => $opt->{message}
}; };
# If we send code, we have to format it correctly
if ($opt->{action} eq 'send-code'){
$json->{formatted_body} = '<pre><code>' . $opt->{message} . '</code></pre>';
$json->{format} = 'org.matrix.custom.html';
}
my $resp = send_request({ my $resp = send_request({
uri => $uri, uri => $uri,
content => to_json($json) content => to_json($json)
@ -549,7 +556,7 @@ elsif ($opt->{action} eq 'get-room-list'){
elsif ($opt->{action} eq 'get-room-id'){ elsif ($opt->{action} eq 'get-room-id'){
print $opt->{room} . "\n"; print $opt->{room} . "\n";
} }
elsif ($opt->{action} =~ m/^send\-(msg|message|notice)$/){ elsif ($opt->{action} =~ m/^send\-(msg|message|notice|code)$/){
join_room(); join_room();
send_msg(); send_msg();
} }