Added getopts and -s option to curl

This commit is contained in:
Jeremy Baxter 2022-07-29 06:54:54 +12:00
parent c74497105b
commit b98624bc78

19
matrix-send Normal file → Executable file
View file

@ -101,7 +101,7 @@ GetAccessToken () {
[ -z "$manualAuth" ] && printf "Getting access token...\n"
if [ "$manualAuth" = "true" ];
then printf ""; # printf "" basically means do nothing
else token=$(curl -XPOST -d "{"'"'"type"'"'":"'"'"m.login.password"'"'", "'"'"user"'"'":"'"'"$username"'"'", "'"'"password"'"'":"'"'"$password"'"'"}" "https://$server/_matrix/client/r0/login" | grep -oE 'syt_.+_...................._......');
else token=$(curl -s -XPOST -d "{"'"'"type"'"'":"'"'"m.login.password"'"'", "'"'"user"'"'":"'"'"$username"'"'", "'"'"password"'"'":"'"'"$password"'"'"}" "https://$server/_matrix/client/r0/login" | grep -oE 'syt_.+_...................._......');
fi
}
@ -121,7 +121,7 @@ ClearCache () {
}
Send () {
curl -XPOST -d "{"'"'"msgtype"'"'":"'"'"m.text"'"'", "'"'"body"'"'":"'"'"$message"'"'"}" "https://$server/_matrix/client/r0/rooms/%21$roomid/send/m.room.message?access_token=$token"
curl -s -XPOST -d "{"'"'"msgtype"'"'":"'"'"m.text"'"'", "'"'"body"'"'":"'"'"$message"'"'"}" "https://$server/_matrix/client/r0/rooms/%21$roomid/send/m.room.message?access_token=$token"
}
########################
@ -131,9 +131,18 @@ Send () {
[ -e /usr/local/bin/curl ] || [ -e /usr/bin/curl ] || error "curl not found"
[ -z "$1" ] && usage
[ "$1" = "-c" ] && ClearCache
[ "$1" = "-h" ] && help
[ "$1" = "-V" ] && version
#[ "$1" = "-c" ] && ClearCache
#[ "$1" = "-h" ] && help
#[ "$1" = "-V" ] && version
while getopts :chV opt
do
case $opt in
c) ClearCache ;;
h) help ;;
V) version ;;
esac
done
###############################
#### Configuration loading ####