Updates to the music function so that it now uses the post_status function to do the actual work of posting. Fixed problems of visibility not respecting the setting.

This commit is contained in:
Storm Dragon 2024-05-12 17:33:49 -04:00
parent 220d5c3d30
commit 5eff83b3ca

View File

@ -63,7 +63,7 @@ play_sound() {
declare -A sounds=(
[error]="|sox -n -p synth saw E2 fade 0 0.25 0.05 repeat norm -7"
[music]="|sox -np synth pl E2 pl B2 overdrive 100 remix - overdrive 100 fade h .25 1 .25 norm -11"
[post]='|sox -np synth .05 tri C2:C7'
[status]='|sox -np synth .05 tri C2:C7'
)
if [[ -n "${sounds[${soundName}]}" ]]; then
sox -qV0 "${sounds[${soundName}]}" -d gain -9 &> /dev/null &
@ -113,25 +113,9 @@ post_music() {
if [[ "${link}" =~ ^file:// ]]; then
link="https://www.youtube.com/results?search_query=$(playerctl metadata -f '{{artist}} {{title}}' | urlencode -b)"
fi
local json=$(jq -n --arg status "[${text}](${link})" --arg spoiler_text "Music" --arg content_type "text/markdown" '{status: $status, spoiler_text: $spoiler_text, content_type: $content_type}')
local result
result="$(curl -sS --oauth2-bearer "${oauth_token}" -H "Content-Type: application/json" \
-d "$json" \
"${instanceURL}/api/v1/statuses")"
# Check for errors
if [[ $? -ne 0 ]]; then
echo "there was a problem contacting the server"
play_sound error
exit 1
fi
local error="$(echo "$result" | jq -r '.error')"
if [[ "$error" != "null" ]]; then
echo "Error: $error"
play_sound error
exit 1
fi
echo "Music posted!"
play_sound music
statusSpoiler_text="Music"
postType="music"
post_status "[${text}](${link})"
}
@ -140,10 +124,10 @@ post_status() {
if [[ "${*}" == "" ]]; then
return
fi
postType="${postType:-status}"
local statusText="$*"
local statusVisibility="${statusVisibility:-public}"
local statusContent_type="${statusContent_type:-text/markdown}"
local statusSpoiler_text=""
statusVisibility="${statusVisibility:-public}"
statusContent_type="${statusContent_type:-text/markdown}"
local statusJson="$(jq -n --arg status "$statusText" \
--arg spoiler_text "$statusSpoiler_text" \
--arg visibility "$statusVisibility" \
@ -164,8 +148,8 @@ post_status() {
play_sound error
exit 1
fi
echo "Status posted!"
play_sound post
echo "${postType^} posted!"
play_sound "${postType}"
}
@ -224,9 +208,6 @@ eval set -- "$options"
while [[ $# -gt 0 ]]; do
case $1 in
--)
shift
break;;
-C)
get_oauth_token
shift;;
@ -244,7 +225,7 @@ while [[ $# -gt 0 ]]; do
post_status "$(cat)"
else
shift 3
#post_status "$@"
post_status "$@"
fi
exit 0;;
-S)