Added getopts and -s option to curl

This commit is contained in:
Jeremy 2022-07-29 06:54:54 +12:00
parent 90fb158618
commit 14a7466c1c

19
matrix-send Normal file → Executable file
View file

@ -101,7 +101,7 @@ GetAccessToken () {
[ -z "$manualAuth" ] && printf "Getting access token...\n" [ -z "$manualAuth" ] && printf "Getting access token...\n"
if [ "$manualAuth" = "true" ]; if [ "$manualAuth" = "true" ];
then printf ""; # printf "" basically means do nothing 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 fi
} }
@ -121,7 +121,7 @@ ClearCache () {
} }
Send () { 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" [ -e /usr/local/bin/curl ] || [ -e /usr/bin/curl ] || error "curl not found"
[ -z "$1" ] && usage [ -z "$1" ] && usage
[ "$1" = "-c" ] && ClearCache #[ "$1" = "-c" ] && ClearCache
[ "$1" = "-h" ] && help #[ "$1" = "-h" ] && help
[ "$1" = "-V" ] && version #[ "$1" = "-V" ] && version
while getopts :chV opt
do
case $opt in
c) ClearCache ;;
h) help ;;
V) version ;;
esac
done
############################### ###############################
#### Configuration loading #### #### Configuration loading ####