From 7c615772f0b39762219c4df8bf4b61f52f8c62c7 Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 4 Apr 2024 13:27:58 +0200 Subject: [PATCH] add mx-set-status --- .config/zsh/functions/mx-set-status | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 .config/zsh/functions/mx-set-status diff --git a/.config/zsh/functions/mx-set-status b/.config/zsh/functions/mx-set-status new file mode 100755 index 0000000..632fd99 --- /dev/null +++ b/.config/zsh/functions/mx-set-status @@ -0,0 +1,26 @@ +#!/usr/bin/env zsh +# set matrix status message to ${1} +# cfg file: server\nuser ID\token + +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" +[[ -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}) + +curl --silent -X PUT \ + --header "Authorization: Bearer ${token}" \ + --json '{"presence": "'${presence}'", "status_msg": "'${mxstatus}'"}' \ + "https://${host}/_matrix/client/v3/presence/${user}/status" > /dev/null