aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOxbian <got.dacs@slmail.me>2024-07-06 22:48:22 +0200
committerOxbian <got.dacs@slmail.me>2024-07-06 22:48:22 +0200
commit6ff18be6f163f39fbb6320d3d7b5f8a8a7f082fb (patch)
tree09d85d6226e6f0dff3c461d09960626a5afe76fb
parent7145d1818350af8d793bea68a354707248666fa3 (diff)
downloadmatrix-sender-6ff18be6f163f39fbb6320d3d7b5f8a8a7f082fb.tar.gz
matrix-sender-6ff18be6f163f39fbb6320d3d7b5f8a8a7f082fb.zip
ADD: user can now specify ROOM-ID for messageHEADmaster
-rw-r--r--README.md14
-rwxr-xr-xmatrix-sender31
-rw-r--r--matrix-sender.112
3 files changed, 38 insertions, 19 deletions
diff --git a/README.md b/README.md
index add85d0..c20074a 100644
--- a/README.md
+++ b/README.md
@@ -24,36 +24,36 @@ First you need to edit the script with your homeserver url & the roomID
After this you need to get your token
```sh
-./matrix-sender -t <username> <password>
+matrix-sender -t <username> <password>
```
Once all is setup, you can send messages:
- Simple message
```sh
-./matrix-sender -s <message>
+matrix-sender -s {<room-id>} <message>
```
- or an HTML formatted message
```sh
-./matrix-sender -html <message>
+matrix-sender -html {<room-id>} <message>
```
For help you can use:
```sh
-./matrix-sender -h
+matrix-sender -h
```
or
```sh
-./matrix-sender --help
+matrix-sender --help
```
**Example**
```bash
-./matrix-sender -s 'Hello world!'
+matrix-sender -s 'Hello world!'
```
```bash
-./matrix-sender -html '<h1 class="test"> t e s t </h1>'
+matrix-sender -html '<h1 class="test"> t e s t </h1>'
```
## Contributing
diff --git a/matrix-sender b/matrix-sender
index dca13b1..78ce634 100755
--- a/matrix-sender
+++ b/matrix-sender
@@ -59,9 +59,9 @@ get_token() {
}
# Send a message
-# usage: ./matrix.sh -s <message>
-# usage: ./matrix.sh -html <message>
-# send_message <message>
+# usage: ./matrix.sh -s {<room-id>} <message>
+# usage: ./matrix.sh -html {<room-id>} <message>
+# send_message {<room-id>} <message>
send_message() {
check_var
check_token
@@ -85,8 +85,8 @@ help() {
printf "Actions:\n"
printf " -h, --help show this menu\n"
printf " -t <username> <password> get the token of the account and save it\n"
- printf " -s <message> send a message\n"
- printf " -html <html> send an html message\n"
+ printf " -s {<room-id>} <message> send a message, if room id is set, the message will be send to the selected room\n"
+ printf " -html {<room-id>} <html> send an html message, if room id is set, the message will be send to the selected room\n"
}
# Main
@@ -116,7 +116,25 @@ case $1 in
;;
esac
-MESSAGE=$*
+# Vérification du room-id et du message
+if [ $# -eq 2 ]; then
+ ROOM_ID="$1"
+ MESSAGE="$2"
+
+ # Validation du format du room-id
+ if ! echo "$ROOM_ID" | grep -Eq '^.?![A-Za-z0-9+/]+:[^:]+.?$'; then
+ error "Invalid room-id format."
+ fi
+
+ MATRIX_ROOM_ID=$ROOM_ID
+
+elif [ $# -eq 1 ]; then
+ MESSAGE="$1"
+
+else
+ error "Message not set, usage:\n$0 -s {<room-id>} <message>\n$0 -html {<room-id>} <html>"
+fi
+
case $action in
send)
send_message "$MESSAGE"
@@ -126,3 +144,4 @@ html)
send_message "$MESSAGE"
;;
esac
+
diff --git a/matrix-sender.1 b/matrix-sender.1
index 9a0b5ab..11e28a2 100644
--- a/matrix-sender.1
+++ b/matrix-sender.1
@@ -1,10 +1,10 @@
.\" Manpage for matrix-sender.
.\" Contact oxbian.noch@simplelogin.com to correct errors or typos.
-.TH man 8 "08 October 2023" "1.0" "matrix-sender man page"
+.TH man 8 "06 July 2024" "1.1" "matrix-sender man page"
.SH NAME
.B matrix-sender
-- send an unencrypted message to a matrix room
+- send an unencrypted message to a matrix room via CLI
.SH SYNOPSIS
.B matrix-sender [OPTIONS]
@@ -21,11 +21,11 @@ Prints help
.IP "-t <username> <password>"
Get token account token, needed for sending messages
-.IP "-s <message>"
-Send a message to a matrix room
+.IP "-s {<room-id>} <message>"
+Send a message to a matrix room, room can be specified
-.IP "-html <html formatted message>"
-Send a HTML formatted message to a matrix room
+.IP "-html {<room-id>} <html formatted message>"
+Send a HTML formatted message to a matrix room, room can be specified
.SH EXAMPLES
.IP "matrix-sender -s 'Hello World!'
ArKa projects. All rights to me, and your next child right arm.