From 13aeccd78f3e891d5e3b99747e115f3b4d43b810 Mon Sep 17 00:00:00 2001 From: stormdragon2976 Date: Mon, 30 Jan 2023 00:23:54 -0500 Subject: [PATCH] I think we have our first fully complete flag, -M should now post music and let you know if it was successful or if there were errors. --- ratatoskr.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ratatoskr.sh b/ratatoskr.sh index 9399fe8..8d4087c 100755 --- a/ratatoskr.sh +++ b/ratatoskr.sh @@ -76,9 +76,21 @@ post_music() { local text="[$(playerctl metadata -f 'Now playing "{{title}}" by "{{artist}}" from "{{album}}"')]" local link="(https://www.youtube.com/results?search_query=$(playerctl metadata -f '{{artist}} {{title}}' | urlencode -b))" 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}') - curl -sS --oauth2-bearer "${oauth_token}" -H "Content-Type: application/json" \ + local result + result="$(curl -sS --oauth2-bearer "${oauth_token}" -H "Content-Type: application/json" \ -d "$json" \ - "${instanceURL}/api/v1/statuses" + "${instanceURL}/api/v1/statuses")" + # Check for errors + if [[ $? -ne 0 ]]; then + echo "there was a problem contacting the server" + exit 1 + fi + local error="$(echo "$result" | jq -r '.error')" + if [[ "$error" != "null" ]]; then + echo "Error: $error" + exit 1 + fi + echo "Music posted!" exit 0 }