forked from vern/scripts
29 lines
1.0 KiB
Bash
Executable File
29 lines
1.0 KiB
Bash
Executable File
#!/usr/bin/env -S bash -e
|
|
[[ -z "$1" ]] && {
|
|
printf "Usage: %s message [description]\n" "$0"
|
|
exit 1
|
|
}
|
|
TxnId() { # Random chars. Needed for sending messages. I am not using tr on /dev/urandom for speed reasons
|
|
CharRange='1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
|
for ((i = 0; i <= 32; i++)); do
|
|
printf '%s' "${CharRange:$((RANDOM % ${#CharRange})):1}"
|
|
done
|
|
}
|
|
instance='https://mtrx.vern.cc'
|
|
RoomId='!TvCDlIfMEHfcpCrSow:vern.cc'
|
|
if [[ -z ${2} ]]; then
|
|
curl -s \
|
|
-X PUT \
|
|
-H 'Content-Type: application/json' \
|
|
-H 'Authorization: Bearer '"$(</root/priv/root-access-token)" \
|
|
-d '{"msgtype":"m.text", "body":"'"${1}"'"}' \
|
|
"$instance"'/_matrix/client/r0/rooms/'"$RoomId"'/send/m.room.message/'"$(TxnId)"
|
|
else
|
|
curl -s \
|
|
-X PUT \
|
|
-H 'Content-Type: application/json' \
|
|
-H 'Authorization: Bearer '"$(</root/priv/root-access-token)" \
|
|
-d '{"msgtype":"m.text", "body":"'"${1}\n\n${2}"'"}' \
|
|
"$instance"'/_matrix/client/r0/rooms/'"$RoomId"'/send/m.room.message/'"$(TxnId)"
|
|
fi
|