From 35e1e95a3ee798283336cb75f79a3d37483dd6c6 Mon Sep 17 00:00:00 2001 From: tea Date: Mon, 14 Oct 2024 13:05:33 +0200 Subject: [PATCH] mx-set-status: preserve non-default status message --- .config/zsh/functions/mx-set-status | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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}" \