mx-set-status: preserve non-default status message

This commit is contained in:
tea 2024-10-14 13:05:33 +02:00
parent 5334da6ce1
commit 35e1e95a3e
No known key found for this signature in database

View File

@ -13,12 +13,21 @@ local host=${cfg[1]}
local user=${cfg[2]} local user=${cfg[2]}
local token=${cfg[3]} local token=${cfg[3]}
local mxstatus="be gay, do crime! :3" local mxstatus="be gay, do crime! :3"
[[ -v 1 ]] && mxstatus=${1}
local response=$(curl --silent \ local response=$(curl --silent \
--header "Authorization: Bearer ${token}" \ --header "Authorization: Bearer ${token}" \
"https://${host}/_matrix/client/v3/presence/${user}/status") "https://${host}/_matrix/client/v3/presence/${user}/status")
local presence=$(jq --raw-output .presence <<<${response}) local presence=$(jq --raw-output .presence <<<${response})
local status_msg=$(jq --raw-output .status_msg <<<${response})
if [[ -v 1 ]]; then
mxstatus=${1}
else
# preserve status message that is not empty or beginning with “np: ”
if [[ ${#status_msg} != 0 ]] && [[ ${status_msg[1,4]} != "np: " ]]; then
mxstatus=${status_msg}
fi
fi
curl --silent -X PUT \ curl --silent -X PUT \
--header "Authorization: Bearer ${token}" \ --header "Authorization: Bearer ${token}" \