2024-04-04 13:27:58 +02:00
|
|
|
#!/usr/bin/env zsh
|
|
|
|
# set matrix status message to ${1}
|
2024-06-06 21:38:48 +02:00
|
|
|
# cfg file: server\nuser ID\ntoken
|
2024-04-04 13:27:58 +02:00
|
|
|
|
|
|
|
setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL
|
|
|
|
|
|
|
|
local -a cfg
|
|
|
|
while IFS=\n read -r line; do
|
|
|
|
cfg+=${line}
|
|
|
|
done < ${XDG_CONFIG_HOME:-~/.config}/mx-set-status.cfg
|
|
|
|
|
|
|
|
local host=${cfg[1]}
|
|
|
|
local user=${cfg[2]}
|
|
|
|
local token=${cfg[3]}
|
|
|
|
local mxstatus="be gay, do crime! :3"
|
|
|
|
|
|
|
|
local response=$(curl --silent \
|
|
|
|
--header "Authorization: Bearer ${token}" \
|
|
|
|
"https://${host}/_matrix/client/v3/presence/${user}/status")
|
|
|
|
local presence=$(jq --raw-output .presence <<<${response})
|
2024-10-14 13:05:33 +02:00
|
|
|
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
|
2024-04-04 13:27:58 +02:00
|
|
|
|
|
|
|
curl --silent -X PUT \
|
|
|
|
--header "Authorization: Bearer ${token}" \
|
|
|
|
--json '{"presence": "'${presence}'", "status_msg": "'${mxstatus}'"}' \
|
|
|
|
"https://${host}/_matrix/client/v3/presence/${user}/status" > /dev/null
|