diff --git a/.config/zsh/functions/mx-set-status b/.config/zsh/functions/mx-set-status index e10db8d..6aa4507 100755 --- a/.config/zsh/functions/mx-set-status +++ b/.config/zsh/functions/mx-set-status @@ -13,12 +13,21 @@ local host=${cfg[1]} local user=${cfg[2]} local token=${cfg[3]} local mxstatus="be gay, do crime! :3" -[[ -v 1 ]] && mxstatus=${1} local response=$(curl --silent \ --header "Authorization: Bearer ${token}" \ "https://${host}/_matrix/client/v3/presence/${user}/status") 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 \ --header "Authorization: Bearer ${token}" \